Session Problem!!
Posted: Wed May 08, 2002 5:10 pm
For some reason when I log in, it goes to account.php, but If I go back to the index.php, It doesnt hold the session! Ive been trying everything on this, If anyone can see something wrong with this please let me know. I just cant see anything wrong with the session stuff.
p.s - I check the sessiondata and the set variables are always there!! And Im running PHP 4.10 on WIN32
INDEX.PHP
ACCOUNT.PHP
--------------------------------------------------------
--------------------------------------------------------
--------------------------------------------------------
Here it is without all the HTML crap
INDEX.PHP
ACCOUNT.PHP
Thx for any help,
pHlange
p.s - I check the sessiondata and the set variables are always there!! And Im running PHP 4.10 on WIN32
INDEX.PHP
Code: Select all
<?
session_start();
?>
<html>
<head>
<title></title>
<style type="text/css">
<!--
A:link { COLOR: 003399; TEXT-DECORATION: none; font-weight: bold }
A:visited { COLOR: 003399; TEXT-DECORATION: none; font-weight: bold }
A:active { COLOR: 003399; TEXT-DECORATION: none; font-weight: bold }
A:hover { COLOR: FFFFFF; TEXT-DECORATION: none; font-weight: bold }
-->
</style>
</head>
<body bgcolor="#FFCC00" topmargin="30" leftmargin="0" marginwidth="0" marginheight="0">
<table width="760" cellspacing="5" cellpadding="10" border="1" align="center" bordercolor="#EEEEEE">
<tr>
<td colspan="2" align="center" width="100%"><font color="#003399" face="verdana,arial,helvetica" size="2"><b></font></b></font></td>
</tr>
<tr>
<td width="150" valign="top">
<font color="#000000" face="verdana,arial,helvetica" size="2">
<!--<p align="left"><a href="index.php?action=home">Home</a></p>-->
</font>
</td>
<td width="610" valign="top">
<? if(!isset($_SESSIONї'username']) || !isset($_SESSIONї'password'])){ ?>
<form action="account.php" method="post">
<table cellspacing="5" cellpadding="5" align="center" border="0">
<tr>
<td colspan="2"><font face="verdana,arial,helvetica" size="2">Members only! Please login to access this document.</font></td>
</tr>
<tr>
<td><font face="verdana,arial,helvetica" size="2">Username</font></td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><font face="verdana,arial,helvetica" size="2">Password</font></td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="check" value="Log In"></td>
</tr>
</table>
</form>
<? }else{ ?>
<font face="verdana,arial,helvetica" size="2">YOU ARE STILL LOGGED IN!</font>
<? } ?>
</td>
</tr>
</table>
</body>
</html>Code: Select all
<?
session_start();
if(empty($_POSTї'username']) || empty($_POSTї'password'])){
echo "<font face="verdana,arial,helvetica" size="2">Error! - You did not supply the required details..You will now be redirected!</font>";
}else{
$_SESSIONї'username'] = $_POSTї'username'];
$_SESSIONї'passsword'] = $_POSTї'password'];
include("includes/connect.php");
$sql = mysql_query("SELECT member_pass FROM members WHERE member_mail='{$_SESSIONї'username']}'");
$result = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" && $_SESSIONї'passsword'] == $resultї"member_pass"]){
$valid_user = 1;
}else{
$valid_user = 0;
}
if (!($valid_user)){
session_unset();
session_destroy();
echo "<font face="verdana,arial,helvetica" size="2">Invalid Login! - you will now be redirected!</font>";
echo "<meta http-equiv="refresh" content="3;URL=index.php">";
}else{
echo $_SESSIONї'username'];
echo "<a href="index.php">HERE</a>";
}
}
?>--------------------------------------------------------
--------------------------------------------------------
--------------------------------------------------------
Here it is without all the HTML crap
INDEX.PHP
Code: Select all
<?
session_start();
?>
<? if(!isset($_SESSIONї'username']) || !isset($_SESSIONї'password'])){ ?>
<form action="account.php" method="post">
//form stuff
</form>
<? }else{ ?>
<font face="verdana,arial,helvetica" size="2">YOU ARE STILL LOGGED IN!</font>
<? } ?>Code: Select all
<?
session_start();
if(empty($_POSTї'username']) || empty($_POSTї'password'])){
echo "ERROR!";
}else{
$_SESSIONї'username'] = $_POSTї'username'];
$_SESSIONї'passsword'] = $_POSTї'password'];
include("includes/connect.php");
$sql = mysql_query("SELECT member_pass FROM members WHERE member_mail='{$_SESSIONї'username']}'");
$result = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" && $_SESSIONї'passsword'] == $resultї"member_pass"]){
$valid_user = 1;
}else{
$valid_user = 0;
}
if (!($valid_user)){
session_unset();
session_destroy();
echo "<font face="verdana,arial,helvetica" size="2">Invalid Login! - you will now be redirected!</font>";
echo "<meta http-equiv="refresh" content="3;URL=index.php">";
}else{
echo $_SESSIONї'username'];
echo "<a href="index.php">GO BACK</a>";
}
}
?>Thx for any help,
pHlange