RE: [PHP] Redirection Question
Hi, I'm not sure if this is going to help or not.. Since I understand your issue only barely.. If I understand correctly, regardless of whether the user comes from a.php, b.php or z.php, if they're not authenticated on the system (via sessions or cookies) then the only place for them to go is login.php. RIGHT??? Here's my 2 cents. (part of code I'm working on) =login.php=== if ( check_if_authenticated() ) <--- I have this fucntion located at the top of a.php,b.php,c.php { header_refresh_html("home.php"); <--- Function call -> back to Home.php if logged in exit; } else<--- display login form is not already logged in { top_html(); display_welcome_msg_html(); } == ===html_functions.php == # === # This is where I print headers to redirect pages # Default wait time is 2 seconds # NOTE : WE MUST PRINT THE REDIRECTION BEFORE WE OUTPUT ANYTHING! #Just put the redirection BEFORE the outputs! # === function header_refresh_html($l_refresh_url) <--- the page to redirect to is given as an argument { // This is taken from php-manual header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 header( "Refresh:2;url=$l_refresh_url" ); // Wait default of 2 seconds } function header_redirect_html($l_redirect_url) { header( "Location:$l_redirect_url");// Instant Redirection } = Cheers, Mun Heng, Ow H/M Engineering Western Digital M'sia DID : 03-7870 5168 -Original Message- From: Beauford.2005 [mailto:[EMAIL PROTECTED] Sent: Thursday, July 24, 2003 8:55 AM To: 'PHP' Subject: RE: [PHP] Redirection Question Thanks to all, I got it working - sort of. It works perfectly on Windows, but will not work on Linux. I am using the same versions of PHP, Apache and MySQL on both. I have asked this before and have been told they are interchangeable, but more times than not I have to make a bunch of changes to get it to work on Linux - and this is just another example. I use Windows to do all the coding and design as it has all the tools. Linux is just a bare bones box with no gui or tools. The php.ini and httpd.conf are the same on both platforms (other than what is needed for the specific platform). This makes it a real pain. Oh well, back to my debugging. -Original Message- From: Curt Zirzow [mailto:[EMAIL PROTECTED] Sent: July 22, 2003 7:04 PM To: PHP Subject: Re: [PHP] Redirection Question * Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > Maybe I didn't explain enough. What if they come from b.php or c.php. > How do I automatically log what page they tried to access. So hard > coding login.php?next=a.php would only work for one page. Use the code that Grant Rutherford posted earlier, its the same concept just a whole lot more flexible than mine. Not to mention a bit more secured. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
Beauford.2005 wrote: Hi, I am trying to figure out how to redirect a user back to a page but not having much luck. For example: I click on a menu item on my site which goes to a.php. This file includes another file that determines if they are logged in or not. If not, they are sent to login.php using header(:Location: ). How would I automatically redirect them back to a.php after they have logged in successfully. I have tried using HTTP_REFERRER, but it isn't redirecting. Well, you know you're in a.php when you realize the log in is not valid. So save $_SERVER['PHP_SELF'] somewhere in the session or pass it along to the login page. After you re-validate the login, redirect back to the page that was saved in the session or URL. If no page was saved, then redirect to a default page. Pick up the next copy of PHP|Architect, because I think I'm going to include a larger write up of this method as a tip. :) -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Redirection Question
Thanks to all, I got it working - sort of. It works perfectly on Windows, but will not work on Linux. I am using the same versions of PHP, Apache and MySQL on both. I have asked this before and have been told they are interchangeable, but more times than not I have to make a bunch of changes to get it to work on Linux - and this is just another example. I use Windows to do all the coding and design as it has all the tools. Linux is just a bare bones box with no gui or tools. The php.ini and httpd.conf are the same on both platforms (other than what is needed for the specific platform). This makes it a real pain. Oh well, back to my debugging. -Original Message- From: Curt Zirzow [mailto:[EMAIL PROTECTED] Sent: July 22, 2003 7:04 PM To: PHP Subject: Re: [PHP] Redirection Question * Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > Maybe I didn't explain enough. What if they come from b.php or c.php. > How do I automatically log what page they tried to access. So hard > coding login.php?next=a.php would only work for one page. Use the code that Grant Rutherford posted earlier, its the same concept just a whole lot more flexible than mine. Not to mention a bit more secured. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Redirection Question
Maybe I didn't explain enough. What if they come from b.php or c.php. How do I automatically log what page they tried to access. So hard coding login.php?next=a.php would only work for one page. TIA -Original Message- From: Curt Zirzow [mailto:[EMAIL PROTECTED] Sent: July 22, 2003 4:16 PM To: PHP Subject: Re: [PHP] Redirection Question * Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > Hi, > > I am trying to figure out how to redirect a user back to a page but > not having much luck. > > For example: I click on a menu item on my site which goes to a.php. > This file includes another file that determines if they are logged in > or not. If not, they are sent to login.php using header(:Location: > ). How would I automatically redirect them back to a.php after > they have logged in successfully. I have tried using HTTP_REFERRER, > but it isn't redirecting. You can use the HTTP_REFERRER, but i wouldn't depend on it, it isn't a required header for the client. what you prolbably should do is when the arn't logged int, you can send them to something like: header('location: login.php?next=a.php'); Then on your login form add a hidden variable: Finally when the user submits this form, and the user logs in successfully you know that you need to redirect them to the a.php. HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
* Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > Maybe I didn't explain enough. What if they come from b.php or c.php. > How do I automatically log what page they tried to access. So hard > coding login.php?next=a.php would only work for one page. Use the code that Grant Rutherford posted earlier, its the same concept just a whole lot more flexible than mine. Not to mention a bit more secured. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
The other methods suggested avoid that entanglement. Kevin "Beauford.2005" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Maybe I didn't explain enough. What if they come from b.php or c.php. > How do I automatically log what page they tried to access. So hard > coding login.php?next=a.php would only work for one page. > > TIA > > -Original Message- > From: Curt Zirzow [mailto:[EMAIL PROTECTED] > Sent: July 22, 2003 4:16 PM > To: PHP > Subject: Re: [PHP] Redirection Question > > > * Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > > Hi, > > > > I am trying to figure out how to redirect a user back to a page but > > not having much luck. > > > > For example: I click on a menu item on my site which goes to a.php. > > This file includes another file that determines if they are logged in > > or not. If not, they are sent to login.php using header(:Location: > > ). How would I automatically redirect them back to a.php after > > they have logged in successfully. I have tried using HTTP_REFERRER, > > but it isn't redirecting. > > You can use the HTTP_REFERRER, but i wouldn't depend on it, it isn't a > required header for the client. > > what you prolbably should do is when the arn't logged int, you can send > them to something like: > header('location: login.php?next=a.php'); > > Then on your login form add a hidden variable: > > > Finally when the user submits this form, and the user logs in > successfully you know that you need to redirect them to the a.php. > > HTH, > > Curt > -- > "I used to think I was indecisive, but now I'm not so sure." > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Redirection Question
Nope. What if it's b.php, or c.php. They could come from many pages. I wish it was that easy. -Original Message- From: Chris W. Parker [mailto:[EMAIL PROTECTED] Sent: July 22, 2003 4:02 PM To: Beauford.2005 Subject: RE: [PHP] Redirection Question Beauford.2005 <mailto:[EMAIL PROTECTED]> on Wednesday, July 23, 2003 12:44 PM said: > How would I automatically redirect them back to a.php after they have > logged in successfully. header("Location: a.php"); chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
Use sessions or cookies to store the first page they are trying to access. Then if not logged in redirect them to the login.php page. After login is successful then they can be redirected to the values that was specified in the cookie or seesion variable. -- BigDog On Wed, 2003-07-23 at 13:44, Beauford.2005 wrote: > Hi, > > I am trying to figure out how to redirect a user back to a page but not > having much luck. > > For example: I click on a menu item on my site which goes to a.php. This > file includes another file that determines if they are logged in or not. > If not, they are sent to login.php using header(:Location: ). How > would I automatically redirect them back to a.php after they have logged > in successfully. I have tried using HTTP_REFERRER, but it isn't > redirecting. > > Any help is appreciated. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
* Thus wrote Beauford.2005 ([EMAIL PROTECTED]): > Hi, > > I am trying to figure out how to redirect a user back to a page but not > having much luck. > > For example: I click on a menu item on my site which goes to a.php. This > file includes another file that determines if they are logged in or not. > If not, they are sent to login.php using header(:Location: ). How > would I automatically redirect them back to a.php after they have logged > in successfully. I have tried using HTTP_REFERRER, but it isn't > redirecting. You can use the HTTP_REFERRER, but i wouldn't depend on it, it isn't a required header for the client. what you prolbably should do is when the arn't logged int, you can send them to something like: header('location: login.php?next=a.php'); Then on your login form add a hidden variable: Finally when the user submits this form, and the user logs in successfully you know that you need to redirect them to the a.php. HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Redirection Question
Hello there, I had the same problem, and to solve it I put the following code in my "check login" include file: // code to detect no login session_start(); session_register('target'); $_SESSION['target'] = "http://"; . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; header("Location: " . $loginpage); This stores the user's original destination into a session variable. I then just have the login page check to see if target is set: // code to authenticate login session_start() if (!empty($_SESSION['target'])){ $target = 'Location: ' . $_SESSION['target']; session_unregister('target'); header($target); } // if I hope this helps, Grant Beauford.2005 wrote: Hi, I am trying to figure out how to redirect a user back to a page but not having much luck. For example: I click on a menu item on my site which goes to a.php. This file includes another file that determines if they are logged in or not. If not, they are sent to login.php using header(:Location: ). How would I automatically redirect them back to a.php after they have logged in successfully. I have tried using HTTP_REFERRER, but it isn't redirecting. Any help is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Redirection Question
Hi, I am trying to figure out how to redirect a user back to a page but not having much luck. For example: I click on a menu item on my site which goes to a.php. This file includes another file that determines if they are logged in or not. If not, they are sent to login.php using header(:Location: ). How would I automatically redirect them back to a.php after they have logged in successfully. I have tried using HTTP_REFERRER, but it isn't redirecting. Any help is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php