nerrad Posted July 18, 2007 Share Posted July 18, 2007 Hi people im am doing this login script and i am trying to make it so that after a user has logged in if they for some reason go back to the login page (index.php) then they will be sent back to the members page. and if the user has not logged in then it shows the login form... Here what i got so far: if (!isset($_SESSION['logged_in'])){ // not logged in, show form echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\"> user id <input type=\"text\" id=\"username\" name=\"username\" size=\"30\" value=\"\" /><BR /> password <input type=\"password\" id=\"password\" name=\"password\" size=\"30\" value=\"\" /><br /> <input type=\"submit\" name=\"Login\" value=\"Login\" /></form>"; } else { header("Location: members.php"); } But all this does is show the form even when a user is logged in.. What am i doing wrong??! Thanks Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 18, 2007 Share Posted July 18, 2007 Have you run session_start() (both when setting and when trying to use it)? Quote Link to comment Share on other sites More sharing options...
nerrad Posted July 19, 2007 Author Share Posted July 19, 2007 When the user is logged in session start would have been run but not if a user has not logged in, is there not a way to check if there is a session? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 19, 2007 Share Posted July 19, 2007 first make your login page its own file secondly, why are you doing a redirect, instead simply on members.php do something like <?php session_start(); if(empty($_SESSION['logged_id']){ exit(include("login.html"); } ?> Make login.html be the form with your template on it also Quote Link to comment Share on other sites More sharing options...
mpharo Posted July 19, 2007 Share Posted July 19, 2007 Why even make it that complicated....leave it all on index.php.....after login create a session variable then check to see if it exists. If it does then the person is logged in if it isnt then display the login form. Quote Link to comment Share on other sites More sharing options...
nerrad Posted July 19, 2007 Author Share Posted July 19, 2007 no that wont work (i dont think? lol) i have got the actual login part sorted I just want it so that after people have logged in and they return to the sites home page then it doesnt ask them to log in if they already are but instead takes them to the members page. Any ideas? @mpharo that is what i am trying to do! the session variable logged_id gets set on the main page (via a form) it then directs them to the members page if a sucessfull login, but how can i get it how i'm asking?? Quote Link to comment Share on other sites More sharing options...
nerrad Posted July 19, 2007 Author Share Posted July 19, 2007 Aggh!! Dont u hate it when you cant do something and you just cant figure out why then u finally realise that you was doing it right all along but had just typed what you wanted one letter different AGHHHHH!!!!! THanks for your help people and sorry to waste your time!! btw this is what i did: -index.php //includes session_start(); //form process code if(!$_SESSION['logged_in']) { //show form } else{ header("Location: members.php"); } 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.