|
-
Jul 31st, 2004, 01:40 PM
#1
Thread Starter
Addicted Member
Basic
Hi, i am having a few problems i have only just started php
but could you take a look at this and tell me why its not pulling the $username from the database
Many Thanks
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?PHP
$username = $HTTP_SESSION_VARS['username'];
?>
<body>
<h1>Well Done</h1><br>
<?php echo"$username" ?> is <font color="#FF0000">logged in</font>
</body>
</html>
Thanks again
-
Jul 31st, 2004, 01:45 PM
#2
Frenzied Member
do you really want it to get the data from a database? if so try out this page to learn how to do that.
Have I helped you? Please Rate my posts. 
-
Jul 31st, 2004, 01:50 PM
#3
Thread Starter
Addicted Member
no i have already connected to a the database in the previous page,but for some reason i cant load the variable into this page ? :S
do you want to see my login_auth page. (the one that links to this page)
Thank Adam
-
Jul 31st, 2004, 04:28 PM
#4
Frenzied Member
well. I'm no expert on mySQL, but the code that creates that variable would be handy.
Have I helped you? Please Rate my posts. 
-
Aug 1st, 2004, 02:04 PM
#5
Stuck in the 80s
First off, $HTTP_SESSION_VARS is deprected in PHP 4.1 and up, so use $_SESSION instead if you're using a recent version.
You also need to start the sessions using session_start(). Here's an example:
Code:
session_start(); // you must do this before any output to the browser
if (isset($_SESSION['username'])) {
echo 'Welcome back, <b>' . $_SESSION['username'] . '</b>.';
} else {
echo 'You are not logged in.';
}
To start the session:
Code:
session_start(); // you must do this before any output to the browser
// I'm going to assume you got some login information
// from a database and use $user as the database record:
if ($user = mysql_fetch_array($users)) {
$_SESSION['username'] = $user['name'];
} else {
echo 'Invalid information';
}
Then, until the browser closes, $_SESSION['username'] should be there, as the session ID is stored either in a cookie on the users computer, or passed along in the query string.
Hope this helped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|