For example, if the the user was to click on a link to "member data" they wouldn't be able to view that page until they had logged in. Therefore, the user validations would send them to the login screen. From there though, I would like the user to be sent back to the page they wanted originally ("member data").
Currently, it forwards the user to the homepage; however, I would love for it to send them back to the page they originally requested.
To my knowledge the best way to do this would be to forward the URL of the original page to the login page. Then the login page could simply redirect the user to that page now that they have logged in.
This is my current code:
User Validation code at top of "Member Pages":
Code: Select all
<?php
session_start();
if ($_SESSION['memberLoggedIn'] != 1)
{
$URL="http://localhost/hr-bin/login.php";
header ("Location: $URL");
}
?>Login Page:
//Just a simple page with a password and username field and a submit button
//It send the data to the login script page below
Login Script:
Code: Select all
<?php
session_start();
// store session data
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_db", $con);
$result = mysql_query("SELECT * FROM members WHERE userName='$_POST[userName]' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc( $result );
$user_ID = $row['user_ID'];
$passvalidate = $row['password'];
if ($_POST[password] == $passvalidate)
{
$_SESSION['loggedin'] = 1;
$_SESSION['user_ID'] = $user_ID;
//PAGE REDIRECT TO INDEX
$URL="http://localhost/project13/index.php";
header ("Location: $URL");
}
else
{
echo "Incorrect password or username combination...please press back and login again<br>Please check to see if CAPS Lock is on.<br><br>
NOTE: If you continue to reach this page, please go back to the login page and click 'Forgot my Password'.";
}
mysql_close($con);
?>