PHP Sessions?

From: Date: Wed, 02 Mar 2005 19:18:34 +0000
Subject: PHP Sessions?
Groups: php.general 
Request: Send a blank email to php-general+get-209833@lists.php.net to get a copy of this message
Hi everyone, I am trying to work with the idea of sessions in PHP. Basically I have a self-processing script called index.php but somehow I keep losing my session variable, it works the first time around but when I call it the second time around its gone? I do not reset the variable or destroy the session are there any other reasons why this might occur? The basic layout of the script is this(note this is not the full script, I've just posted the relevant code and left out the other stuff.) <?php if($_POST["username"]=="rory"){//if user logs in as rory start session session_start(); header("Cache-control: private"); $_SESSION['loggedin'] = "yes"; } /*It enters the first time but when I call the script again from the form below this one the session variable is empty?*/ if(strlen($_SESSION['loggedin'])>2){ if($_POST["verify"]=="yes"){
    die("test");
	$CONTENT .= "<font color = \"red\">Your changes have been made.</font><br>";
}
        $CONTENT = "You are currently logged in as ".$_POST["username"].
"<form action=\"index.php\" method=\"POST\"> <input type=\"submit\" value=\"Log out\" /> <input type=\"hidden\" name=\"logout\" value=\"yes\"/></form> <hr>If you would like to change the text on the main page please click here <a href=\"index.php?page=$PAGE_TITLE&action=edit\"><font color=\"blue\">Edit intro page</a><font color =\"#136863\"><hr><h3>File Upload.</h1><hr> Any files will appear in the 'students' page of the website. Files that uploaded here are not availablre to the public and can only be acccessed by students who have logged in. Because of security issues only well know file types such as word, acrobat and text files are legible for upload. <form enctype=\"multipart/form-data\" action=\"index.php\" method=\"POST\">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name=\"userfile\" type=\"file\" />
    <input type=\"submit\" value=\"Upload\" />
<input type=\"hidden\" name=\"arg1\" value=\"yes\"> </form>"; }
    if ($action == "edit")
/*when user submits this is should call teh script again and enter the test above but it doesn't?*/
        {
$CONTENT = "<form method=\"post\" action=\"index.php\"> <textarea name=\"content\" cols=\"60\" rows=\"20\">$CONTENT</textarea> <input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br/> <input type=\"submit\" value=\"$DONE_BUTTON\" /> <input type=\"hidden\" name=\"verify\" value=\"yes\"/></form>"; } Cheers, Rory.

« previous php.general (#209833) next »