Login Script Help
Posted: Fri Jul 29, 2005 9:27 am
I am very new too php and am just experimentting with a very simple php login script.
The code is below.
I dont understand what code to put at the top of each secure webpage to make sure that the session is still logged in.
I'm pretty sure that this should be very simple. With my code below could anyone please write out the short code I need to place on the top of each of my secure pages.
<?php
import_request_variables ("PCG");
if (empty($Surname) || empty($Password))
{
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/StudentErr.html");
}
else
{
//open database connection
$connection = mysql_connect("xxxxxxxxxxxxx,xxxxxxxxx,xxxxxxx") or die ("Error Connecting
to the database.");
//select the database
mysql_select_db("ar1?db", $connection) or die ("Failed!");
$result = mysql_query("select * from Student where Surname='$Surname' AND Password='$Password'",$connection);
//check that at least one row has been returned.
$Checkrow = mysql_num_rows($result);
if($Checkrow > 0)
{
while($row = mysql_fetch_array($result))
{
//start session
session_start();
session_register('Surname');
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/Form1.php");
}
}
else
{
//Invalid Password or User ID: Return to Login Page
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/StudentErr.html");
}
}
php?>
I hope this is enough infomation.
The code is below.
I dont understand what code to put at the top of each secure webpage to make sure that the session is still logged in.
I'm pretty sure that this should be very simple. With my code below could anyone please write out the short code I need to place on the top of each of my secure pages.
<?php
import_request_variables ("PCG");
if (empty($Surname) || empty($Password))
{
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/StudentErr.html");
}
else
{
//open database connection
$connection = mysql_connect("xxxxxxxxxxxxx,xxxxxxxxx,xxxxxxx") or die ("Error Connecting
to the database.");
//select the database
mysql_select_db("ar1?db", $connection) or die ("Failed!");
$result = mysql_query("select * from Student where Surname='$Surname' AND Password='$Password'",$connection);
//check that at least one row has been returned.
$Checkrow = mysql_num_rows($result);
if($Checkrow > 0)
{
while($row = mysql_fetch_array($result))
{
//start session
session_start();
session_register('Surname');
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/Form1.php");
}
}
else
{
//Invalid Password or User ID: Return to Login Page
header("Location: http://project.cs.cf.ac.uk/A.Rabindran/StudentErr.html");
}
}
php?>
I hope this is enough infomation.