imported_Amber
New member
On my index page, I have a login form. The info is sent to a php page that verifys the username and password and then either redirects the user back to the main page if login was successful or an error page if it wasn't.
I want the php page to set a cookie so that as people finish lessons, their information will be automatically updated.
I'm using a hello "user" code on my index page to verify the cookie is working.
that code is:
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>
The php page looks like this
<?php
include 'php/conn.php';
include 'php/config.php';
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM game
WHERE username='$username'") or die(mysql_error());
$row = mysql_fetch_array( $result );
if ($password==$row['password'])
{
SETCOOKIE ("user", "ryan", time()+3600, "/", ".mjweststudio.com");
header('Location: index.php');
}
else
header('Location: error.html');
?>
If I enter the correct information I am redirected to the index as hoped for. If I don't I am redirected to the error page as hoped for. But, the echoed welcome message stays welcome guest.
How do I fix it so that when redirected back to the main page it recognes the cookie and says welcome "user"?
I want the php page to set a cookie so that as people finish lessons, their information will be automatically updated.
I'm using a hello "user" code on my index page to verify the cookie is working.
that code is:
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>
The php page looks like this
<?php
include 'php/conn.php';
include 'php/config.php';
$username = $_POST['username'];
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM game
WHERE username='$username'") or die(mysql_error());
$row = mysql_fetch_array( $result );
if ($password==$row['password'])
{
SETCOOKIE ("user", "ryan", time()+3600, "/", ".mjweststudio.com");
header('Location: index.php');
}
else
header('Location: error.html');
?>
If I enter the correct information I am redirected to the index as hoped for. If I don't I am redirected to the error page as hoped for. But, the echoed welcome message stays welcome guest.
How do I fix it so that when redirected back to the main page it recognes the cookie and says welcome "user"?