aarrrrrg...i need help with sessions..agian

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

do you have problems with sessions too?

Poll ended at Fri Nov 15, 2002 4:39 pm

Yes
2
50%
No
2
50%
Sessions?
0
No votes
 
Total votes: 4

qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

aarrrrrg...i need help with sessions..agian

Post by qads »

i am useing php version 4.2.3 at home and the sessions work fine on it.
but my host uses 4.2.2, sessions are not saveing any value in them at all.
e.g. $_SESSION["username"] is empty! by the way, the login form is working fine, it passes the values with out a problem.


here is the login page code:

Code: Select all

<?php
session_start();
include("admin/inc/db.inc.php");

if(IsSet($_POSTї'log']))
{
	$username = $_POSTї'user'];
	$password = md5($_POSTї'password']);
	
	//set up the query
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";

$ll = date("j/m/Y");			
	
//run the query and get the number of affected rows
$result = mysql_query($query) or die('error making query');
$affected_rows = mysql_num_rows($result);
$array = mysql_fetch_array($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1)
{
$_SESSIONї'username'] = $username;
$email = $arrayїemail];
$lastl = $arrayїlast_login];

$_SESSIONї'email'] = $email;
$_SESSIONї'lastl'] = $lastl;

$lastlogin = mysql_query("update users set last_login='$ll' where username = '$username' limit 1");
header("Location: main.php");
}
else 
{
session_destroy();
print ("Your Username or password is not correct, please login agian...");
}
}
?>


and here is the code i use to check if a session is active or not:

Code: Select all

<?php
session_start();
include("admin/inc/type.inc.php");

$username = $_SESSIONї"username"];
$email = $_SESSIONї"email"];
$lastl = $_SESSIONї"lastl"];

if(empty($username)) 
{
die
('An error has ocurred. It may be that you have not logged in, or that your session has expired.
Please try <a href="login.php">logging in</a> again...');
}
?>
when it passes a user to main.php, it comes out as "'An error has ocurred. It may be that you have not logged in, or that your session has expired."
so $username is empty :cry:

what can i do to fix this?
is there anything else i can use for this task?

thanks alot for your help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

check the session settings with

Code: Select all

<?php phpinfo(); ?>
  • esp. valid values in
  • session.save_path
  • session.gc_maxlifetime
  • session.use_cookies
  • session.save_handler
after a session is created and values are stored is there a corresponding file in <session.save_path>?
You may also test session.use_trans_sid to check client-side cookie problems
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

my host has wrong settings? 8O

session.save_path = /tmp
session.gc_maxlifetime = 1440
session.use_cookies = On
session.save_handler = files
session.use_trans_sid = 1

these settings are same as my own computer :? , i have emailed them and asked if they could check these settings.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

If you're desperate, you could try displaying errors AND warnings:

php.ini:
error_reporting = E_ALL & E_NOTICE


Also, you might want to log error messages instead of showing them to the world...
php.ini:
display_errors = Off

; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = Off

; Log errors into a log file (server-specific log, stderr, or error_log (below))
; As stated above, you're strongly advised to use error logging in place of
; error displaying on production web sites.
log_errors = On

; Store the last error/warning message in $php_errormsg (boolean).
track_errors = Off

; Disable the inclusion of HTML tags in error messages.
;html_errors = Off

; String to output before an error message.
;error_prepend_string = "<font color=ff0000>"

; String to output after an error message.
;error_append_string = "</font>"

; Log errors to specified file.
;*nix:
error_log = /path/to/log/filename
;Windows:
error_log = c:\path\to\log\filename
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

i would do that but this script is not working on my host where i don't have access to php.ini...works fine on localhost :?
Post Reply