PDA

View Full Version : How do I enable Sessions?


Skeptical
Wed 22nd May '02, 8:04pm
I have a script and it tells me I have to enable sessions. How do I enable this?

Right now I can't get this 'if' statement to become true:


if(isset($_POST['imagetext'])&&strlen($_POST['imagetext'])==7&&isset($_SESSION['text'])&&
strtolower($_POST['imagetext'])==$_SESSION['text'])
{

blah blah...

}

Mark Hensler
Wed 22nd May '02, 8:09pm
lol, nice sig.

Can you show us the error?

Skeptical
Wed 22nd May '02, 8:14pm
Originally posted by Mark Hensler
lol, nice sig.


Haha thanks :)

Can you show us the error?

Actually there are no errors. It's just that the code inside the 'if' statement never executes.

Ok, looking further down the code, it appears there's this:

<form name=form method=post action=<?=$_SERVER['PHP_SELF']?>?<?=SID?>>

However, <?=SID?> always output as blank. I'm thinking it should be a session ID.

Mark Hensler
Thu 23rd May '02, 1:15am
Quoted from PHP Docs: XCI. Session handling functions (http://www.php.net/manual/en/ref.session.php)
There are two methods to propagate a session id:
o Cookies
o URL parameter

The session module supports both methods. Cookies are optimal, but since they are not reliable (clients are not bound to accept them), we cannot rely on them. The second method embeds the session id directly into URLs.

PHP is capable of doing this transparently when compiled with --enable-trans-sid. If you enable this option, relative URIs will be changed to contain the session id automatically. Alternatively, you can use the constant SID which is defined, if the client did not send the appropriate cookie. SID is either of the form session_name=session_id or is an empty string.

scoutt
Thu 23rd May '02, 5:27pm
sounds like you need to enable sessions in the php.ini file. also make sure you set teh tmp directory to teh correct place or it won't work.

hope that is what you are after.

Zoombie
Sun 2nd Jun '02, 2:39am
To quickly check if a session is ready, you can make a call to session_id:

echo session_id();

Also, sessions are usually started by called session_start. I think that a call to any session function automatically starts a session, but the $_SESSION variables might not be available until you explicitly start a session.