Jump to content

redirect for a login.php


Hooch
 Share

Recommended Posts

I have a login.php page that will say you have successfully logged in or it will say try again if something is wrong. I wish to change the successfull login from this..

// set a cookiesetcookie( "id", "$id", time()+3600, "/", "", 0 );echo "User Logged in.<br><br><a href=\"index.php\">Continue...</a>";}

To redirecting back to index.php automatically. Can I do this, If so how? Thank you..Hooch

Link to comment
Share on other sites

I suggest you also add this:print '<noscript><a href=\"index.php\">Click here to go back to index.php</a></noscript>';As some browsers don't support javascript. :)

Link to comment
Share on other sites

Hi Chocolate,would it look like this then? // set a cookiesetcookie( "id", "$id", time()+3600, "/", "", 0 );print "<script>location = 'index.php';</script>"; print '<noscript><a href=\"index.php\">Click here to go back to index.php</a></noscript>';}

Link to comment
Share on other sites

Yup, except I don't know why you have an extra bracket at the end. Is that just part of your main script? If so, that should work. You could remove those \'s behind the quotes, though. :)

Link to comment
Share on other sites

You can also just add a header to instruct the browser to redirect (not through javascript):

header("Location: index.php");

This will only work if you haven't started the page output yet, but if you are setting a cookie then headers are still being sent, so it should work here.

Link to comment
Share on other sites

Good php has ' ' and " " and \' \' and \" \"... one time I like need 4 different quotes because I had a dynamic button input code thing, with php writing html with js links writing html that had php variables in it...

Link to comment
Share on other sites

  • 3 months later...

If you clicked on a link to get to the login page, then you would redirect to the referer. The referer for a page is the page where you clicked on a link to reach the current page. I believe that is in $_SERVER['HTTP_REFERER']

Link to comment
Share on other sites

If you clicked on a link to get to the login page, then you would redirect to the referer. The referer for a page is the page where you clicked on a link to reach the current page. I believe that is in $_SERVER['HTTP_REFERER']
OK cool, so would the code be header(Location: $_SERVER['HTTP_REFERER']); ?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...