Hello,
I am building a php / mysql website with the usual login / fancy php scripts etc. I have a little annoying issue and I think the answer may lie in my php sessions. When I use my login script, sometimes I am logged in and sometimes I am kicked back to my home page. Also, when i am logged in I am sometimes kicked back out when I click an internal link - very annoying indeed. I have posted an example script below detailing my use of sessions - any comments are greatly appreciated. 🙂
Regards,
Susan
<?php
header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
session_start();
if (!isset($_SESSION['SESSION'])) require ( "./include/session_init.php");
//echo $_SESSION['LOGGEDIN'];
if ($_SESSION['LOGGEDIN'] == true) {
header("Location: ./account.php");
exit;
}
$_SESSION['FORM_SUBMITTED'] = "";
$CRLF = chr(13).chr(10);
$userid = "";
if (isset($HTTP_GET_VARS["username"])) $username = $HTTP_GET_VARS["username"];
if ($username == '') { if (isset($_SESSION['username'])) $userid = $_SESSION['username']; }
// if the bFlg is true then some validation problems in the data.
// namely a blank field or a submission without the feedback page.
// just present a general error...
$flg = "";
$error = "";
if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"];
switch ($flg) {
case "yellow":
$error = "<font class=\"txt_main_str12_mar\"><BR>Your Account Has Not Been Verified.<BR>Check your email for Activation Instructions.<br>Click <a href=\"/courses/forgot_login.php\">here</a> to have the activation email resent.</font>";
break;
case "red":
$error = "<font class=\"txt_main_str12_mar\"><BR>That username/password combination is not in our database.<br>Please Try Again.</font>";
break;
case "blue":
$error = "<font class=\"txt_main_str12_mar\"><BR>Your Session has Expired.<br>Please Login Again.</font>";
break;
default:
$error = " <br>";
}
?>