Page 1 of 1

Global Value in new page

Posted: Sun Feb 24, 2008 8:30 pm
by soupisgood84
I have a mysql db that will authenticate a user to a website. The problem that I am running into is that I would like to display the user name on another page but I am having trouble with the global values. The below code labeled connect.php and login.php will connect to the DB and authenticate but I need a little guidance with the last step name tempager.php. Thanks in advance.

connect.php

Code: Select all

 
<?php
$connect = mysql_connect ('localhost','dbaccess','only');
mysql_select_db('backuplog', $connect);
?>
 
login.php

Code: Select all

 
<?php
include "connect.php";
$sql = "select name from user where login='$id' and password='$password' ";
$result = mysql_query ($sql, $connect);
$row = mysql_fetch_array($result);
$username = $row[name];
 
if($row)
{
echo ("
<body bgcolor='white'>
        Name: <font color='red'> $username</font>
</body>
<br><br><meta http-equiv='refresh' content='2; url=tempager.php'>
");
}
else {
        echo ("
        <html>
        <head><title></title>
        <meta http-equiv='refresh' content='0; url=login.html'>
        </head>
        <body bgcolor='white'>
        </body>
        </html>
        ");
}
?>
 
tempager.php

Code: Select all

 
<?php
echo include "login.php";
echo ("
Name: <font color='red> $username</font>
");
?>
 
The code written the way it is will constantly request a login and password.

Re: Global Value in new page

Posted: Sun Feb 24, 2008 11:38 pm
by Christopher
All variables in PHP are created and destroyed every request. So it will not work as you have written it. Try saving the username in the session. See the manual for examples.