Problems passing the session ID

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
fradal
Forum Newbie
Posts: 2
Joined: Mon Jan 14, 2008 11:07 am

Problems passing the session ID

Post by fradal »

Hi all,

I'm :banghead: with this problem for a week and I really cannot understand how to solve it!

I've got a login script that works like that

Code: Select all

 
<?
session_name("utente");
session_start();
 
#now check if $_POST['username'] and $_POST['password'] are valid, then
 
$_SESSION['userid'] = $userid; #$userid comes from the database
 
# ok, let's go back
?>
<html><head><META HTTP-EQUIV="refresh" content="0;URL=<?= $_SERVER['HTTP_REFERER'] ?>"><body><center><big>Login OK</big></center></body></html>
 
The problem is that $_SESSION, in the second page, is empty and I cannot understand why.

I'm using PHP 5.2.1, configured with --enable-trans-sid
10 days ago it was working, I didn't make any changes to the php configuration, nor to the script and now it is not working

Can you help me figuring out what's wrong?

PS. Sorry for my bad english

Many thanks


Francesco


-----------
I think more information can help me, you and everyone that will read this post in the future

Trying to understand this problem I've made a few changes, and the working script looks like that

Code: Select all

 
<?
session_start();
 
#now check if $_POST['username'] and $_POST['password'] are valid, then
 
$_SESSION['userid'] = $userid; #$userid comes from the database
 
# ok, let's go back
?>
<html><head><META HTTP-EQUIV="refresh" content="0;URL=<?= $_SERVER['HTTP_REFERER'] ?>?<?php echo htmlspecialchars(SID);?>"><body><center><big>Login OK</big></center></body></html>
 
Passing the SID via GET all is working fine.

(Obviously, my costumer don't like the SID appended to all the urls of the site! :cry: )
---------------
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Problems passing the session ID

Post by Kieran Huggins »

session_start() should be the first thing you do, since it wants to send headers. Make sure there's NOTHING before that line in your script, not even white space!
fradal
Forum Newbie
Posts: 2
Joined: Mon Jan 14, 2008 11:07 am

Re: Problems passing the session ID

Post by fradal »

Thank you for the reply Kieran Huggins

There's nothing before session_start (a part from session_name), and I'm absolutely sure because adding the sid to the url sessions are working properly
Post Reply