Jump to content

Login Redirect


shaunno2007

Recommended Posts

Hi i have a login on my website and i need it to Redirect people to the page that they where on before but i can not seem to do it.

 

I have tryed this   header("Location: ".$_SERVER['HTTP_REFERER']." "); but it keep comming up with this error message:

 

 

Redirect Loop

 

 

 

 

 

 

 

 

 

 

 

 

 

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

 

 

 

 

 

 

The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.

 

* Have you disabled or blocked cookies required by this site?

* NOTE: If accepting the site's cookies does not resolve the problem, it is likely a server configuration issue and not your computer.

 

 

 

And the login script what i am using is this:

 

http://php.about.com/od/finishedphp1/ss/php_login_code.htm

 

 

 

 

My website http://link-search.x10hosting.com/

Link to comment
Share on other sites

Sounds like the page you're redirecting to is redirecting back to the other page.

 

Page 2 redirects to Page 1

Page 1 redirects to Page 2

Page 2 redirects to Page 1

 

And so on and so forth. You just need to find the redirect on Page 1 and fix the conditional logic around it.

Link to comment
Share on other sites

I have got it to stop looping but now when i login it stays on the login page but does not redirecting me back to the page ai was on before ???

 

 

I did the same on my logout page "header("Location: ".$_SERVER['HTTP_REFERER']." ");" and it works it redirects me to the page i was on before so i do not understand why it is not working on my login page

 

Is they another way of redirecting to the page before because this way is not working for me???

Link to comment
Share on other sites

I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url.

 

So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form.

 

<input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" />

 

Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page.

 

I have a system like this working on several of my websites at the minute and it works flawlessly.

Link to comment
Share on other sites

Well what i have done is that:

 

when someone goes on to the page that you need to be logged in to.

 

I have a if and else. so if they r logged in it will show the content that only the members can see but/else, if they are not logged in then they will be shown you need to login to. whatever do you understand what i mean if you dont just look at my website http://www.link-search.co.nr

 

so could i use this so when they click on a link, then it will redirect the user to 'login.php?ref=members.php.

 

Sort of thing ??

Link to comment
Share on other sites

I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url.

 

So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form.

 

<input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" />

 

Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page.

 

I have a system like this working on several of my websites at the minute and it works flawlessly.

 

Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work.

 

if (user_is_logged_in() == false)
{
    header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;
}

// If here, user is logged on so show content

 

Link to comment
Share on other sites

When someone clicks on a page that is for members i don't what it to redirect them to the login.

 

When someone clicks on a link that says "login to see content" then it does your code do you need what i mean??

 

This is hard for me am all over place i thought it would be easy to do what i want but its coming a nightmare

Link to comment
Share on other sites

Say a user is on my page called news.php and then they click on login to see content or lets just say login,

 

then when they do it will do your code that you are saying then when they login, on login.php it will redirect them to news.php and then they will be logged in.

 

Could you use some examples please as well :) thanks

Link to comment
Share on other sites

Rather than using header and redirecting back to the page you would display a page to the user saying...

 

Thank you for logging in.<br />
<a href="javascript:history.back(-1);">Click here to return to your page</a><br />

 

If this doesn't work I would try -2 as opposed to -1.

Link to comment
Share on other sites

Its weird right i put

<a href="javascript:history.back(-1);">Click here to return to your page</a>

 

did not work it redirected me to the login again so i tryed

<a href="javascript:history.back(-2);">Click here to return to your page</a>

 

Still nothing wtf don't get it

 

plus i need it to refresh the page cos it not show you user logged in if it takes them back using history -2 or -1

 

 

Link to comment
Share on other sites

I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url.

 

So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form.

 

<input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" />

 

Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page.

 

I have a system like this working on several of my websites at the minute and it works flawlessly.

 

Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work.

 

if (user_is_logged_in() == false)
{
    header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;
}

// If here, user is logged on so show content

 

 

This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system.

Link to comment
Share on other sites

Yes, but if i use the code that you suggested then when someone goes on that page with that code in it will redirect them to the login, but i dont want that because if i did then i would have to have it on every page because i have a login link on all my pages.

Link to comment
Share on other sites

I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url.

 

So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form.

 

<input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" />

 

 

Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page.

 

I have a system like this working on several of my websites at the minute and it works flawlessly.

 

Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work.

 

if (user_is_logged_in() == false)
{
    header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;
}

// If here, user is logged on so show content

 

 

This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system.

 

What i need is a onclick sort of thing so when people click on a link it will take them to the login plus it will do this as (When they click it)

header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;

Link to comment
Share on other sites

I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url.

 

So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form.

 

<input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" />

 

 

Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page.

 

I have a system like this working on several of my websites at the minute and it works flawlessly.

 

Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work.

 

if (user_is_logged_in() == false)
{
    header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;
}

// If here, user is logged on so show content

 

 

This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system.

 

What i need is a onclick sort of thing so when people click on a link it will take them to the login plus it will do this as (When they click it)

header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']));
    exit;

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.