Jump to content

[SOLVED] user login redirect


nerrad

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.