I have some problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POST["username"])) || (!isset($_POST["passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POST["username"]=="") || ($_POST["passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POST[username]' and pass='$_POST[passwd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th e problem in session management in php. I have been trying to find the problem but couldn't fix.Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
fe problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
[color=darkge problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
feyd | fixede problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
feyd[/b:a7696ae problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
feyd | fixed php code to use [b:a7 in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
Thanks,
Banuprasad
[colort fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
</body>
</html>the problem I am facing is that when I login, its moves from login.php to account.php. I am creating two variables in the session: user_ID and first in login.php. In account.php, I am checking if $_SESSION['user_ID'] is set and printing echo $_SESSION[first].
I am getting the follwing error:
Code: Select all
Notice: Undefined index: first in F:\courses\CSCI5633\fall2004\Samudral\pages\fall04\php\account.php on line 61But sometimes, it works..I do not understand what is the problem..
please help me..
The problem in session management in php. I have been trying to find the problem but couldn't fix.
Code: Select all
<html>
<head>
<title></title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#BCBEC0">
<?php
include "../include/db.inc";
if((!isset($_POSTї"username"])) || (!isset($_POSTї"passwd"])))
{
include("../include/login.inc");
exit;
}
//no input in the form ; return to login.html
if(($_POSTї"username"]=="") || ($_POSTї"passwd"]==""))
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Must enter user ID and password fields</font></center>";
exit;
}
// connection string
$conn = mysql_connect($hostname,$username,$password) or die(mysql_error("Error: Could not connect to server"));
// select the DB
$db = mysql_select_db($db_name,$conn) or die(mysql_error("Error: Could not select the database"));
// sql query
$sql = "SELECT * FROM student WHERE stud_id ='$_POSTїusername]' and pass='$_POSTїpasswd]'";
// execute the sql query;
$result = mysql_query($sql,$conn) or die(mysql_error("Error: Could not execute SQL query"));
//retrieve the username and password from db
//if($result>0)
if(mysql_num_rows($result)==0)
{
//echo " Invalid user";
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
else
{
$user_ID = mysql_result($result,0,"stud_id") or die(mysql_error());
$pass = mysql_result($result,0,"pass") or die(mysql_error());
$fname = mysql_result($result,0,"fname") or die(mysql_error());
if($_POSTї'passwd']==$pass)
{
session_start();
//$first=$fname;
//session_register('user_ID');
//session_register('first');
//$user_ID= $_POSTї'username'];
//$first= $fname;
$_SESSIONї'user_ID'] = $_POSTї'username'];
$_SESSIONї'first'] = $fname;
header("Location: ./account.php");
}
else
{
include("../include/login.inc");
echo "<center><font color="#FF0000">Please enter correct user ID or password</font></center>";
exit;
}
}
?>
</body>
</html>Code: Select all
<?
session_start();
if (!isset($_SESSIONїuser_ID]))
{
//echo "No session".phpversion();
//header("Location: ./login.php");
//exit;
}
?>
<html>
<head>
<title>Account Information</title>
<style type="text/css">
<!--
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
color: #575C62;
text-decoration: none;
}
a:hover {
color: #FF6600;
text-decoration: none;
}
a:active {
color: #FF6600;
text-decoration: none;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
-->
</style>
<link href="../forAll.css" rel="stylesheet" type="text/css">
</head>
<body style="margin: 0 0 0 0">
<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1">
<tr valign="top">
<th width="180" align="left" class="leftMain" scope="col">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>
<th height="157" align="left" valign="top" scope="col">
<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr>
<th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./account.php">Home</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./viewgrades.php">Grades</a></th>
</tr><tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./changepwd.php">Change password</a></th></tr>
<tr><th height="25" align="left" valign="middle" class="forMenu" scope="col"><a href="./logout.php">Logout</a></th></tr>
</table> </th></tr></table> </th>
<th align="left" class="rightMain" scope="col"><table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1">
<tr><th align="left" valign="top" class="forContent" scope="row"><p>Hi, <?php echo "$_SESSIONїfirst]"; ?></p></th></tr>
</table></th></tr></table>
&a