Redirecting to another page with a message

Thread Solved

Join Date: Sep 2007
Posts: 38
Reputation: BigFormat is an unknown quantity at this point 
Solved Threads: 0
BigFormat BigFormat is offline Offline
Light Poster

Redirecting to another page with a message

 
0
  #1
Jun 18th, 2009
I'd like to redirect the user to another page, i.e. after a login check.
I'm used to doing this via header location directive, it's all ok, but, if I'd like to print a message and redirect the user in 2/3 seconds, like on this forum when you login?

Is it feasible via PHP?
Last edited by BigFormat; Jun 18th, 2009 at 5:37 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: Redirecting to another page with a message

 
0
  #2
Jun 18th, 2009
Heya,

At a guess you could redirect them from say .... login.php to logging.php which echos the message you want!

Then on this page insert a simple piece of redirect javascript such as:

  1.  
  2.  
  3. <script type="text/JavaScript">
  4. <!--
  5. redirectTime = "1500";
  6. redirectURL = "http://www.yourwebsite.com";
  7. function timedRedirect() {
  8. setTimeout("location.href = redirectURL;",redirectTime);
  9. }
  10. // -->
  11. </script>
  12.  
  13. <div style="background-color:#ffcc00;padding:5px;width:100px;cursor:pointer;"
  14. onclick="JavaScript:timedRedirect()">
  15. Click me to redirect
  16. </div>


This will then redirect them after the amount of time you specify to the url you specify!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 455
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Redirecting to another page with a message

 
0
  #3
Jun 18th, 2009
Or you could just do:
  1. header("Refresh: 3; url=http://www.google.com");
  2. echo "You will be redirected to Google in 3 seconds...";
Note, the echo must be after the header, or this will fail.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 38
Reputation: BigFormat is an unknown quantity at this point 
Solved Threads: 0
BigFormat BigFormat is offline Offline
Light Poster

Re: Redirecting to another page with a message

 
0
  #4
Jun 24th, 2009
Which is the difference between the two solutions? I'm using the syntax from Atli's post right now and it fullfills its aim, but I'd like to know the differences, just to learn something and use it for future reference...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 455
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Redirecting to another page with a message

 
1
  #5
Jun 25th, 2009
The one justted posted uses client-side code, JavaScript, to re-set the location being displayed, effectively redirecting the page to another URL.
Being client-side it can be somewhat unreliable, seeing as clients are free to turn of JavaScript and ignore the code completely.

The one I posted uses server-side code to send the HTTP Refresh header, which tells the browser it should refresh the page after the specified amount of seconds using the URL provided.
This method will work on anything worth calling a browser, and I doubt many browsers even provide an option to turn it off.

They will both work with most clients, but I prefer the server-side version. It's less hassle and more reliable.
Last edited by Atli; Jun 26th, 2009 at 12:03 am. Reason: Fixed the header info... was thinking about the wrong one :)
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 38
Reputation: BigFormat is an unknown quantity at this point 
Solved Threads: 0
BigFormat BigFormat is offline Offline
Light Poster

Re: Redirecting to another page with a message

 
0
  #6
Jun 26th, 2009
Perfect, many thanks for these details!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC