Simple page redirection in php (referred url redirection)?

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
mittul
Forum Newbie
Posts: 4
Joined: Tue Jul 26, 2011 4:27 am

Simple page redirection in php (referred url redirection)?

Post by mittul »

hello .. i have some PHP web pages in which i have LOGIN.PHP , profile.php and another pages in PHP ..

now some of the pages needs to be logged in by user then only we can see those ..

i have my login page in which if the USERNAME, PASSWORD is correct then he will be redirected to only PROFILE.PHP page coz i have used
--------------------------------------…
header('Location:profile.php')
--------------------------------------…

but suppose here if the user is another page and bcoz of hes not logged in hes redirecting to LOGIN.PHP and now he has written the right account details .. then he must be gone to the PARTICULAR PAGE which he was trying to see b4 login instead of the PROFILE.PHP page ..

how can i do it .. how can i redirect the USER right into that page after login which he wanted to see b4 login ..

(referred url redirection) i think its called .. how to do this ..
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Simple page redirection in php (referred url redirection

Post by flying_circus »

Using sessions would be a good tool.

When the user navigates to a page that is restricted, set a session variable with the requested url, $_SESSION['restricted'], then redirect to the login pagin. Upon successful login, check the session for the $_SESSION['restricted'] and if it exists, take the user there, else take the user home.
Post Reply