Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions

Status
Not open for further replies.

draigGoch

Programmer
Feb 10, 2005
166
GB
HELP! I am not understanding sessions at all, and I can't find a decent tutorial anywhere on the web.

Here is the problem, I have a login screen with the code:

if ($user && $pass)
{
if (($user==$userdatabase) && ($pass==$passdatabase))
{
$_SESSION['user'] = $user;
}
else
{
echo ">Wrong Info!";
}
}

and I then redirect like so:

if (isset($_SESSION['user'])) {
?><meta http-equiv="REFRESH" content="0;url=http://chwilio.garcad.com/members.php"><?
}

which doesn't seem to work. Neither does the other file members.php, it as if I haven't logged in. Here's the code for that file:

<?
session_start();
$websiteTitle = "MY WEB";
//$user = &$_SESSION['user'];
?>

<html>
<head>
<?
echo "<title>$websiteTitle</title>";
?>
<LINK REL=StyleSheet HREF="css/chwilio.css" TYPE="text/css" MEDIA=screen>
</head>
<body>

<?
if (isset($_SESSION['user'])) {
echo '<p>Logged in | <a href="logout.php">logout</a></p>';
echo "<p>Helo $user! </p>";

}else{
?>
<p>You are not logged in, <a href="login2.php">click here</a> to log in</p>
<?
}
?>
</body>
</html>

Where am I going wrong?

A computer always does what you tell it to, but rarely does what you want it to.....
 
It sorted itself out - no idea what the problem was!

A computer always does what you tell it to, but rarely does what you want it to.....
 
A recommendation:

Instead of relying on the <meta> tag to refresh the page I would highly recommend to use the server side approach of PHP and user a header("Location: ...") directive.
When you use the meta tag you rely on the client side to do the work which in case of authentication is not the best idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top