Validate URL against URL for login script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jboku
Forum Newbie
Posts: 10
Joined: Tue Nov 17, 2009 10:31 am

Validate URL against URL for login script

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Validate URL against URL for login script

Post by requinix »

parse_url can help.
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: Validate URL against URL for login script

Post 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?
jboku
Forum Newbie
Posts: 10
Joined: Tue Nov 17, 2009 10:31 am

Re: Validate URL against URL for login script

Post 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 ;)
jboku
Forum Newbie
Posts: 10
Joined: Tue Nov 17, 2009 10:31 am

Re: Validate URL against URL for login script

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