Jump to content

session_start(); before or after redirect?


hey_suburbia

Recommended Posts

I have a very basic login that determines if the email address exists in the DB and if it does they get redirected, if not they get redirected elsewhere:

[code]$fetch_exist=mysql_query("SELECT email FROM memberlist WHERE email = '$email'");

//then check if the email is there
if(mysql_num_rows($fetch_exist)>0)
{

    //it's in the database, bring them to logged in area
header('Location: http://site.com/directory/page.php');
exit;
}

else
{ //it's not in the database, bring them to sign-up
header('Location: http://site.com/page2.html');
exit;
}[/code]

This works great.

The problem occurs when I try to start the session, which is this:

[code]session_start();
$_SESSION ['email'] = $email;[/code]

I tried putting it before the if/else statement, I tried putting it into the if statement.  All return blank fields in the database.

On my sign up page, I have the same thing (without the redirect and it works great).

So, I guess my question becomes, where do I start the session on a page that redirects.  I tried to start it on the page that you get redirected to, but I would have to pass the $email variable to that page...

Any thoughts?

THANKS!!!
Link to comment
Share on other sites

thanks.

So if I put the session_start() before this:

[code]$fetch_exist=mysql_query("SELECT email FROM memberlist WHERE email = '$email'");

//then check if the email is there
if(mysql_num_rows($fetch_exist)>0)
{

    //it's in the database, bring them to logged in area
header('Location: http://site.com/directory/page.php');
exit;
}

else
{ //it's not in the database, bring them to sign-up
header('Location: http://site.com/page2.html');
exit;
}[/code]

It should work, right?
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.