Page 1 of 1

Validate URL against URL for login script

Posted: Thu Dec 17, 2009 12:23 pm
by jboku
Hey everyone,

Perhaps I am going about this the wrong way but basically here is where I am at:

When someone goes to http://www.myurl.com/blah/cool if they are not logged in it takes them to the login page (http://www.myurl.com/login/login.php. Once they log in it sends them to just http://www.myurl.com/blah and not the page they wanted to get to.

basically, if they came from say google I dont want them to be redirected back to google when they login.

So here is what I have:

$ref=@$HTTP_REFERER;
if ($ref == "http://www.myurl.com/") {
echo $ref;
}
else {
echo "URL not valid";
}

How can I find the base URL of $ref and make sure it matches my URL then have it direct to that page once they log in.

Re: Validate URL against URL for login script

Posted: Thu Dec 17, 2009 1:21 pm
by requinix
parse_url can help.

Re: Validate URL against URL for login script

Posted: Thu Dec 17, 2009 2:11 pm
by timWebUK

Code: Select all

$host  = $_SERVER['HTTP_HOST']; 
Is this what you're after? To grab the base URL of your site, then compare it the referrer?

Re: Validate URL against URL for login script

Posted: Thu Dec 17, 2009 3:38 pm
by jboku
timWebUK wrote:

Code: Select all

$host  = $_SERVER['HTTP_HOST']; 
Is this what you're after? To grab the base URL of your site, then compare it the referrer?
Thank you that is a big help ;)

Re: Validate URL against URL for login script

Posted: Thu Dec 17, 2009 3:59 pm
by jboku
The problem I am having now is when I click to login, the variable changes and it trys to send me back to the login page and not the page I came from. :/. How can I get around this?