logon wont stayed logged on!

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
taech
Forum Newbie
Posts: 4
Joined: Mon Oct 27, 2003 4:47 pm

logon wont stayed logged on!

Post by taech »

heres my login(.php) page:

Code: Select all

<?php
session_start();
$username = $_POST&#1111;'username'];
$password = $_POST&#1111;'password'];

if(!$_POST)
&#123;
include 'html/loginform.html';
&#125;
elseif((!$username) || (!$password))
&#123; 
    echo "Please enter ALL of the information! <br />"; 
    include 'html/loginform.html';
&#125;
else
&#123;
	$qstr = "SELECT * from members where username = '$username' and password = '$password'";
	$result = mysql_query($qstr);
	if (mysql_num_rows($result))
	&#123;
	$result = mysql_fetch_array($result);
		$banned = $result&#1111;"banned"];
		$email = $result&#1111;"email"];
		$name = $result&#1111;"name"];
		$password = $result&#1111;"password"];
		$points = $result&#1111;"points"];
		$post = $result&#1111;"post"];
		$user_level = $result&#1111;"user_level"];
		$_SESSION&#1111;'banned'] = $banned;
		$_SESSION&#1111;'email'] = $email;
		$_SESSION&#1111;'name'] = $name;
		$_SESSION&#1111;'password'] = $password;
		$_SESSION&#1111;'points'] = $points;
		$_SESSION&#1111;'post'] = $post;
		$_SESSION&#1111;'user_level'] = $user_level;
		$_SESSION&#1111;'username'] = $username;
		echo "<br><font color=#008000><Center><b>**Successful Login**</b></Center></font>";
	&#125;
	else
	&#123;
		echo "<br><font color=#ff0000><Center><b>**Failed Login**</b></Center></font>"; 
	&#125;
&#125;
?>
and as stated in the title, when I login it wil login all right, but then when i got to the next page, it forgets that i have logged on :(...

so, any help?

-thx
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

becuase post isn't set on all pages. it can be on form pages, but not on all. do you check for the session variable to see if someone's logged in anywhere?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

do you have session_start(); on all pages?

and do you declare
$username = $_SESSION['username'];
and
$password = $_SESSION['password'];
on each page?
taech
Forum Newbie
Posts: 4
Joined: Mon Oct 27, 2003 4:47 pm

Post by taech »

m3rajk i do know that post isnt set on all pages also i do check the sessions but only where i need it.

yes i do LiLpunkSkateR
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

What do you see if you;

Code: Select all

// change...
echo "<br><font color=#008000><Center><b>**Successful Login**</b></Center></font>";

// ...to...
echo "<br><font color=#008000><Center><b>**Successful Login**</b></Center></font>";
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
taech
Forum Newbie
Posts: 4
Joined: Mon Oct 27, 2003 4:47 pm

Post by taech »

**Successful Login**

Array
(
[banned] => 0
[email] => email@email.com
[name] => myname
[password] => mypass
[points] => 10
[post] => 0
[user_level] => 3
[username] => admin
)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Bah, I was hoping that I could narrow it down abit, but no. As that works the session is indeed set. Other thing i thought of was missing to use session_start() on the next page, but you allready stated that you did...

Sorry, but I'm stumped...
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Post by zenabi »

Not sure if this will help, but I found this from php.net:
If you have problems with getting "session_start()" working on a Windows XP machine try this:
Change "session.save_path" in the "php.ini" file from "session.save_path = /tmp" to "C:\WINDOWS\Temp".
Post Reply