Hi everyone, I have been working all day trying to figure out exactly how to get sessions to work out how I want to (in php of course.)<br><br>
Here is my code so far:<br><br>
<b>login.php</b><br>
<pre>
<?
session_start();
?>
<form method=post action="<?echo $PHP_SELF?>">
<table cellpadding=2 cellspacing=0 border=0>
<td>Username:</td><td><input type="text" name="name" size=10></td><tr>
<td>Password:</td><td><input type="password" name="password" size=10></td><tr>
<td> </td><td><input type="submit" name="submit" value="Log In"></td>
</table></form>
<?
if ($submit) {
$db = mysql_connect("localhost","root","mysql") or die ("cant connect");
mysql_select_db("e_users") or die ("Unable to select database!");
$query = "select * from e_users where name='$name'";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_object($result)) {
if ($row->password == $password) {
print session_id();
//$HTTP_SESSION_VARS["name"] = $name;
$HTTP_SESSION_VARS["name"] = "andy";
$HTTP_SESSION_VARS["test"] = "test";
echo "<br>Hello ".$HTTP_SESSION_VARS["name"]."<br>";
echo "Successfully Logged In!";
//echo "<a href='logged.php'>click here</a>";
?>
<a href='logged.php?<?=SID ?>'>logged.php</a>
<?
} else {
echo("Wrong password.");
}
}
mysql_close($db);
}
?>
</pre>
<br><br>
<b>logged.php</b><br>
<pre>
<?php
session_start();
//if (!$HTTP_SESSION_VARS["name"]) {
// print "I can't do anything for you. Sorry. Try again.";
// exit;
//} else {
//$HTTP_SESSION_VARS["name"] = $name;
print "your session id is: ".session_id();
print "<br>your name is: ".$HTTP_SESSION_VARS["name"];
print "<br>your test is: ".$HTTP_SESSION_VARS["test"];
//}
?>
</pre>
<br><br>
Essentially what I am trying to do is this: I want to have a login system where someone logs in and the name/pass are checked against a MySQL database query, and if the password/user matches the entry, it should enable the user to continue to the logged in area. For some reason (other than my incompetance,) I am not able to get the variables in the session to move from the login page to the logged.php page.<br><br>
Is there something I am missing in the code, or is there a better way to do what I am trying to do? Thanks!<br><br>
Andy Summers