Re: PHP Sessions?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks everyone, I'm getting closer. The only problem I have not is that I keep entering that test, I modified it to change the session variable once we enter the test but it somehow does not seem to change it? This is the code,


if(strlen($_SESSION['loggedin']=="yes")){
$_SESSION['loggedin']="no";
$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?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>";
}


When I click the logout button it works fine, but when I click on the link inside the page it simply reloads the same page as if the session variable has not changed at all? If I link to a page like this does it call the script again, or does this need to be done with a form submit? I must apologise for my lack of knowledge here! I program in other languages and as a result I have that I can get really deep in code I don't understand very fast!


Rory Walsh wrote:
Yes I see what you mean. I only wanted to start a session IF the user logged in, but I see your point, the session can be started as soon as anyone opens the main page. I'll give it a go and see if that helps, cheers,
Rory.



Chris W. Parker wrote:

rory walsh <mailto:rorywalsh@xxxxxx>
    on Wednesday, March 02, 2005 1:26 PM said:


The problem there is that I have to test if the user has logged on so
I need to include the if statement? Can the session_start not be
called from within an if statement? Does it really have to be the
very first thing in the script, if so I imagine that this means a
single script cannot be used to manage a complete website?



No session_start(); can go anywhere. It's just that it appears that your logic is setup in such a way that session_start(); is not being called when you need it be. By putting it before everything else you can avoid this.

And as well, is there a reason you wouldn't want to just start the
session at the beginning of the page? I mean, why wait till the user has
submitted the form to start the session?



Chris.

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux