Pedro999 Posted July 22, 2013 Share Posted July 22, 2013 Hi, Just joined the forum. Am new to PHP. Been reading the books,etc, and written a simple program. On the index page I do Start_Session() at the top. I then call a function to log a new visitor by adding a record in a MySQL table. Also call a function to display the visitor number. One the hyperlinks on index.php allows a user to login. If successful various $_SESSION[ ] variables are set. The user is then taken back to the index.php uisng the header statement. The $_SESSION[ ] variables are set ok and are visible in index.php. The question I have, is this. When the user is sent back to index.php, the Add_New_Visitor and Display_Visitor_No functions get called again. How do I stop this? This also happens if the header function is not used and the user is allowed to navigate back to index.php using the browser back arrow key. Thought of doing something like: <? session_start() if ($_SESSION['login']!='Yes') { Add_Visitor(); etc } Is there something easy I should be doing here and something fundamental I am not appreciating? Another question occurs is how do I code a logout? Pedro Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 22, 2013 Share Posted July 22, 2013 look into the use of isset() - to check if login has occured - and unset() and session_destroy() for the logout. Quote Link to comment Share on other sites More sharing options...
Pedro999 Posted July 22, 2013 Author Share Posted July 22, 2013 look into the use of isset() - to check if login has occured - and unset() and session_destroy() for the logout. Hi Muddy, have not tested fully, but what you have suggested appears to be working and has solved the problem. Thank you. Before, instead of using isset(), I was using empty(). The subtleties of PHP, and the ignorance of the newby, I guess! Cheers Pedro Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 22, 2013 Share Posted July 22, 2013 Your welcome - and we were all newbies once upon a time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.