Hi,
i am trying to forward a user after processing his login information. The header doesn`t seem to be changing from the processedlogin page.
Here the sequence to enter the member area:
login.php > processedlogin.php > mp1.php
the code for the page is as follows:
<?php
session_start();
// Starting the session
// including the database
include("dbconnect.php");
if($_POST['email'] != "" and $_POST['password'] != "")
{
// Initializing the variables over here
$email = $_POST['email'];
$email = trim($email);
$password = $_POST['password'];
$password = trim($password);
// Now begin the check to see if the username and password are in the database
$sql = mysql_query("SELECT * FROM timer WHERE email='$email' AND pass='$password'");
$login_check = mysql_num_rows($sql);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
if($login_check > 0)
{
// User id and password match, Now check to see if the user is still subscribed.
// Setting up the dates for comparison
$subscribedtill = mysql_result($sql, 0,'subscribedtill');
$today = time();
////////////////////////////////////////////////
// Print the dates to view the logic //
////////////////////////////////////////////////
//echo("<p>Time comparison:.</p>\n".
// "<p>Today: <b>$today</b>\n" .
// "<p>Subscribed till: <b>$subscribedtill</b></p>");
////////////////////////////////////////////////
// Comparing the dates
if($subscribedtill > $today)
{
// User is still subscribed, check to see if there is a session id in the database
$retrievedsid = mysql_result($sql, 0,'sid');
if(isset($_SESSION['$retrievedsid']))
{
//If there is a session id, we must destroy the session associated with that email address and build a new one
$oldsid = mysql_result($sql, 0,'sid');
$sid = $email . $today;
////////////////////////////////////////////////
// Print the session ids to view the logic //
////////////////////////////////////////////////
//echo("<p>Old Session: $oldsid</p>\n");
//echo("<p>New Session: $sid</p>\n");
////////////////////////////////////////////////
// the problem with this line is that server is trying to destroy the session but there is no session.
// check to see if there is a session for a particular account before destroying
// if there is no session for a particular acc then proceed to registration
// else destroy it.
// the session name is always the email address and date stamp
destroy_session($oldsid);
//We now need to update the database with the new session id and setup our friendly session
$updateacc1 = mysql_query("UPDATE timer SET sid='$sid' WHERE email='$email';");
// build the session at this point and forward him to the main page
//echo("<p>Reached this point 1</p>\n");
session_register('loggedin');
$_SESSION['loggedin'] = true;
session_register('email');
$_SESSION['email'] = $email;
session_register('session_id');
$_SESSION['session_id'] = $sid;
//echo("Welcome ". $_SESSION['email']);
header('Location: www.hijazionline.com/php/mp1.php');
exit();
/*}
else
{
echo("<p>Internal error.</p>\n<p>" . mysql_error() . ".</p>");
} */
}
else
{
//If there is no session id create a session and update the database and forward the user to the main page
$sid = $email . $today;
$updateacc1 = mysql_query("UPDATE timer SET sid='$sid' WHERE email='$email';");
// build the session at this point and forward him to the main page
//echo("<p>Reached this point 2</p>\n");
session_register('loggedin');
$_SESSION['loggedin'] = true;
session_register('email');
$_SESSION['email'] = $email;
session_register('session_id');
$_SESSION['session_id'] = $sid;
//echo("Welcome ". $_SESSION['email']);
header('Location: www.hijazionline.com/php/mp1.php');
exit();
/*}
else
{
echo("<p>Internal error.</p>\n<p>" . mysql_error() . ".</p>");
} */
}
}
else
{
// User is no longer subscribed and must be forwarded to the subscribption page
echo("<p>You are no longer subscribed. Please go to the subscription page and subscribe to continue using this service.</p>");
}
}
else
{
echo("<p>The username and password combination couldn`t be found.</p>");
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
}
else
{
echo("<p>You forgot to input your email address or password</p>");
}
?>
Please discard the comments made in the code. These were comments for me to help me along the way.
Any help will be appreciated. Regards.