URGENT - Remodified the code - still it's not working

Hi All

I have remodified the code and still I am not able to print the session value in the corressponding page…

I have used the below code in the main.php page to get the session value …BUT THE VALEU SI NOT GETTING PRINTED …

$username = $_SESSION[‘username’];
echo $username;

Login.php


<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?><HTML>
<HEAD>
<TITLE> Admin Login </TITLE>
<link href="css/tblbrd.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/text.css" rel="stylesheet" type="text/css">
<link href="css/heading.css" rel="stylesheet" type="text/css">
<style>
body{
background-color:#0473AE;
}
.txt{
font-family: Tahoma, Geneva, sans-serif;
font-size:12px;
font-weight:bold;
color: #000;
}
.adtxt{
font-family: Arial, Helvetica, sans-serif;
font-size:20px;
font-weight:bold;
color:#333333;
 
}
 
.adtxt1 { font-family: Tahoma, Geneva, sans-serif;
font-size:14px;
font-weight:bold;
color: #000;
}
.txt1 { font-family: Tahoma, Geneva, sans-serif;
font-size:12px;
font-weight:bold;
color:#FFF;
}
</style>
</HEAD>
<body>
 
 
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name="form" method="post" action="checklogin.php"><table width="617" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="617" height="501" bgcolor="#FFFFFF"><table width="607" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF" class="tblbrd">
<tr>
<td width="599" height="69" align="center" valign="top" bgcolor="#e5e3e4" class="adtxt"><p><img src="http://www.sitepoint.com/forums/images/banner.jpg" width="600" height="100"><br>
</p></td>
</tr>
<tr>
<td height="290" align="center" valign="top"bgcolor="#0473AE"><br>
<br>
<table width="411" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="403" height="222" colspan="0" valign="top" bgcolor="#0473AE"><p>&nbsp;</p>
<table width="321" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="319"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tblbrd">
<tr align="center">
<td height="33" colspan="4" bgcolor="#F2F2F2"><strong class="adtxt1">User Login</strong></td>
</tr>
<tr>
<td height="19" colspan="4" align="right" bgcolor="#E5E3E4" class="txt1">&nbsp;</td>
</tr>
<tr>
<td width="101" height="35" align="right" bgcolor="#E5E3E4" class="txt">Username</td>
<td width="11" height="35" align="center" bgcolor="#E5E3E4">&nbsp;</td>
<td width="207" height="35" colspan="2" bgcolor="#E5E3E4"><input name="username" type="text" id="username" ></td>
</tr>
<tr>
<td width="101" height="35" align="right" bgcolor="#E5E3E4" class="txt">Password</td>
<td height="35" align="center" bgcolor="#E5E3E4">&nbsp;</td>
<td height="35" colspan="2" bgcolor="#E5E3E4"><input name="password" type="password" id="password"></td>
</tr>
<tr align="center">
<td height="45" colspan="4" bgcolor="#E5E3E4"><input type="submit" name="Submit" value="Login"></td>
</tr>
<tr align="center">
<td height="27" colspan="4" bgcolor="#FFFFFF" >&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
<br>
<br></td>
</tr>
</table>
<br>
<br></td>
</tr>
<tr>
<td height="25" valign="top" bgcolor="#e5e3e4" background="http://www.sitepoint.com/forums/images/top_menu.jpg">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</form>
ss
</BODY>
</HTML>

Checklogin.php


<?php
ob_start();
include "config.php";
$username=$_POST['username'];
$password=$_POST['password'];
 
if ((!$username) || (!$password))
{
header('location:index.php?i=1');
exit;
}
$sql="SELECT * FROM $tbl_admin WHERE adminuser='$username' and adminpass='$password'";
echo $sql;
$result=mysql_query($sql);
//$count=mysql_fetch_array($result);
$count=mysql_num_rows($result);
 
if($count==1){
session_register("username",$username);
session_register("password",$password);
header("location:menu.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
 
?>

menu.php


session_start();
//if(!session_is_registered(username)){
$username = $_SESSION['username'];
echo $username;
//header("location:main_login.php");
 
?>
 
<HTML>
<HEAD>
<TITLE> Admin Login </TITLE>
<link href="css/tblbrd.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/text.css" rel="stylesheet" type="text/css">
<link href="css/heading.css" rel="stylesheet" type="text/css">
<style>
body{
background-color:#0473AE;
}
.border{
border:1px solid #ffffff;
}
.txt{
font-family: Tahoma, Geneva, sans-serif;
font-size:12px;
font-weight:bold;
color:#FFF;
}
.headtxt{
font-family: Arial, Helvetica, sans-serif;
font-size:16px;
font-weight:bold;
color:#4b5676;
text-decoration:none;
}
.headtxt a : hover{
font-family: Arial, Helvetica, sans-serif;
font-size:16px;
font-weight:bold;
color:#4b5676;
text-decoration:none;
}
.adtxt{
font-family: Tahoma, Geneva, sans-serif;
font-size:14px;
font-weight:bold;
color: #000;
 
}
.menutxt{
font-family: Arial, Helvetica, sans-serif;
font-size:18px;
font-weight:bold;
color: #ffffff;
}
 
</style>
</HEAD>
<body>
 
 
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="595" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
<tr>
<td width="593" height="375" bgcolor="#ffffff"><table width="571" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="571" height="61" align="center" bgcolor="#0473AE"><span style="font-family:Tahoma, Geneva, sans-serif; font-size:22px; font-style: italic font-weight:bold; color:#ffffff;">Weekly Work Report</span></td>
 
</tr>
<tr>
<td height="294" align="center" bgcolor="#0473AE"><table width="79%" border="0" cellpadding="0" cellspacing="0" bgcolor="#fffff" class="tblbrd">
<tr>
<td width="18%" height="125" align="center" bgcolor="#0473AE" class="menutxt"><img src="http://www.sitepoint.com/forums/images/add.png" width="68" height="68"></td>
<td width="35%" height="125" align="left" bgcolor="#0473AE" class="headtxt">
<a href="statusinput.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; text-decoration:none; color:#ffffff;">Insert Data</a></td>
<td width="18%" align="left" bgcolor="#0473AE" class="headtxt"><img src="http://www.sitepoint.com/forums/images/view.png" width="68" height="68"></td>
<td width="29%" height="125" align="left" bgcolor="#0473AE" class="headtxt"><a href="index1.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">View Data</a></td>
</tr>
<tr align="center">
<td height="89" align="center" bgcolor="#0473AE"><img src="http://www.sitepoint.com/forums/images/report.png" width="68" height="68"></td>
<td height="89" align="left" bgcolor="#0473AE"><span class="headtxt"><a href="reportview.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">Report View</a></span></td>
<td height="89" align="left" bgcolor="#0473AE"><span class="headtxt"><img src="http://www.sitepoint.com/forums/images/logout.png" width="73" height="66"></span></td>
<td height="89" align="left" bgcolor="#0473AE" class="headtxt"><a href="logout.php" style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; font-style: italic font-weight:bold; text-decoration:none; color:#ffffff;">Logout</a></td>
</tr>
<tr>
<td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
<td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
<td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
<td height="40" align="center" bgcolor="#0473AE" class="headtxt">&nbsp;</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
 
 
</BODY>
</HTML>

  1. [B]session_is_registered/B is a deprecated function in PHP 5.3 and shouldn’t be used anymore
  2. [B]session_register/B shouldn’t be used for setting sessions, you should use $_SESSION[‘key_name’] instead
  3. In your Checklogin.php file you haven’t declared [B]session_start/B which will result in no sessions been able to be set
  4. You are using plain text passwords which are very easy for a hacker to crack, you should start thinking about using [B]md5/B or [B]sha1/B encryption functions.

Welcome to the SP forums.

I have used the below code in the main.php page to get the session value …BUT THE VALEU SI NOT GETTING PRINTED …

$username = $_SESSION[‘username’];
echo $username;

Do you do session_start() in main.php?

And please, when you post code, put the appropriate tags around it to make it more readable.

I have used $_SESSION[‘key_name’] instead of session_register(“username”,$username);
I have also used the session_start() in the checklogin.php but still the username is not getting printed in the menu.php page.

You need to use the session_start() on each and every page to get acccess to the session variables. It’s not like a number of the other languages where the session variables are automatically available one you start the session. It’s one of a number of things I find annoying about php.