Hi Folks,
I am new to PHP and am trying to create a login page that interacts with a MYSQL database.
This example is taken from the SAMS Teach Yourself PHp book but I cannot get the code to work
The procedure is as follows:
login.php is the login form that collects the user data (This works OK)
the form is sent to verify.php that verifies the validity of the user entry with the database
This verify page signals the user as an authorised viewer and offers a link to a third page. (This works OK)
if the user's validity is confirmed the verify.php code, sets an "authorisation" cookie with a value to 1
The code for setting the cookie is
PHP Code:
if(!isset($HTTP_COOKIE_VARS[authorised])) {
// set cookie
$auth=1;
setcookie("authorised", $auth, time() + 14400, "/", "localhost", 0);
}
The strange thing is when I have the last 3 parametes for the setcookie() function included i.e."/", "yourdomain.com", 0 the cookie is not placed in the cookie folder.
(When I remove the last 3 parameters the cookie value is set and appended to a cookie file from previously worked examples. Is there a problem with "yourdomain.com")
The code in the third page should check for the presence of the "authorised" cookie with the value set to "1" before displaying the 3rd page. If the cookie is not found then user is redirected to the intial login.php page.
This is not working at all
PHP Code:
if (isset $HTTP_COOKIE_VARS[authorised]=="1") {
$msg = "<p>You are an authorized user.</p>";
} else {
//redirect back to login form if not authorized
header("Location: login.php");
exit;
}
On a previous post I had a problem where my code where my intial code was
if (isset $_cookie[authorised]=="1"){...
The solution suggested included changing the code to:
if (isset $HTTP_COOKIE_VARS[authorised]=="1") {
Could this be a problem??
I have now spent 4 hours trawling through the web for tutorials and all I have is more questions but fewer answers so any help would be gratefully appreciated,
Thanks in advance,
Orla