-
reply
below is my modified script. but it is not redirecting to the
page "products.php"
what went wrong here....
PHP Code:
<?php
session_start();
mysql_connect("localhost","root","") or die("mysql_error()");
mysql_select_db("shopping") or die("mysql_error()");
$result = mysql_query("SELECT * from login where username='" . $_POST['username'] . "' AND password='" . $_POST['password'] . "'");
$rows=mysql_num_rows($result);
if(isset($_SESSION['username']))
{
$messages = "UserId : ".$_SESSION['username'];
unset($_SESSION['username']);
}
else
{
$_SESSION['username'] = time();
}
if ($rows > 0)
{
session_register('username');
$_SESSION['username'] = $_POST['username'];
echo $messages;
header("Location:products.php");
exit;
}
else
{
//unsuccessful login
header("Location:login3.php");
exit;
}
?>
-
is it redirecting to login3.php ? is it giving you an error message? please be as specific as possible about what's going on.
in addition, it is always best to use absolute URLs when you use the header() function:
PHP Code:
header("Location: http://www.example.com/page.php");
// is much more reliable than
header("Location: page.php");
// while this works sometimes,
// according to the HTTP/1.1 spec, it technically shouldn't work at all.
-
reply
first when the session has started he need to go to the "products.php" page
using the session name(here using time()).here username is the output of time()
that should be stored in the database.
tell me how to do this one....