Global Value in new page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soupisgood84
Forum Newbie
Posts: 1
Joined: Sun Feb 24, 2008 8:19 pm

Global Value in new page

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Global Value in new page

Post 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.
(#10850)
Post Reply