$_SESSION[] not getting value
Posted: Sat Dec 05, 2009 12:17 pm
hi to all
i m using session in login and want to display database only members, i m using session id for this, but my database page cant get the session value.
i m giving code behind, please check and help
-------------------------------------------------------------------
this is check_login.php file
---------------------------------------------------
<?php
session_start();
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("oscobizz_os", $con);
$chk = mysql_query("select * from members where name='".$_POST['name']."' and pass='".$_POST['pass']."'");
if(mysql_num_rows($chk)>0)
{
$_SESSION['s_id']="1122";
header("Location: http://www.os-co.biz/data_final.php/");
}
else
echo "Wrong Username or Password:";
?>
----------------------------------------------------------------
this is database file named as data_final.php
-----------------------------------------------------------------
<?php
session_start();
echo $_SESSION['s_id'];
if($_SESSION['s_id']!=1122)
echo "Sorry: You are not logged in";
else
{
$con = mysql_connect("localhost","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());
else
{
mysql_select_db("oscobizz_os", $con);
$result = mysql_query("SELECT * FROM query");
while($row = mysql_fetch_array($result))
{
echo "<html>";
echo "<body>";
echo "<table>";
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['fax'] . "</td>";
echo "<td>" . $row['mob'] . "</td>";
echo "<td>" . $row['box'] . "</td>";
echo "<td>" . $row['query']."</td>";
echo "</tr>";
echo "</table>";
echo "</body>";
echo "</html>";
}//end of while
} //end of inner else
}//end of main else
?>
------------------------------------------------------------
when i provide the correct login info, and header calls the data_final.php file, it does not show the result, and display the msg "Sorry: You are not logged in" and also does not show the $_SESSION value by echo.
i m using session in login and want to display database only members, i m using session id for this, but my database page cant get the session value.
i m giving code behind, please check and help
-------------------------------------------------------------------
this is check_login.php file
---------------------------------------------------
<?php
session_start();
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("oscobizz_os", $con);
$chk = mysql_query("select * from members where name='".$_POST['name']."' and pass='".$_POST['pass']."'");
if(mysql_num_rows($chk)>0)
{
$_SESSION['s_id']="1122";
header("Location: http://www.os-co.biz/data_final.php/");
}
else
echo "Wrong Username or Password:";
?>
----------------------------------------------------------------
this is database file named as data_final.php
-----------------------------------------------------------------
<?php
session_start();
echo $_SESSION['s_id'];
if($_SESSION['s_id']!=1122)
echo "Sorry: You are not logged in";
else
{
$con = mysql_connect("localhost","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());
else
{
mysql_select_db("oscobizz_os", $con);
$result = mysql_query("SELECT * FROM query");
while($row = mysql_fetch_array($result))
{
echo "<html>";
echo "<body>";
echo "<table>";
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['tel'] . "</td>";
echo "<td>" . $row['fax'] . "</td>";
echo "<td>" . $row['mob'] . "</td>";
echo "<td>" . $row['box'] . "</td>";
echo "<td>" . $row['query']."</td>";
echo "</tr>";
echo "</table>";
echo "</body>";
echo "</html>";
}//end of while
} //end of inner else
}//end of main else
?>
------------------------------------------------------------
when i provide the correct login info, and header calls the data_final.php file, it does not show the result, and display the msg "Sorry: You are not logged in" and also does not show the $_SESSION value by echo.