943,722 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4394
  • PHP RSS
Jun 18th, 2009
0

Redirecting to another page with a message

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
BigFormat is offline Offline
45 posts
since Sep 2007
Jun 18th, 2009
0

Re: Redirecting to another page with a message

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:

PHP Syntax (Toggle Plain Text)
  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!
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Jun 18th, 2009
0

Re: Redirecting to another page with a message

Or you could just do:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Jun 24th, 2009
0

Re: Redirecting to another page with a message

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...
Reputation Points: 10
Solved Threads: 0
Light Poster
BigFormat is offline Offline
45 posts
since Sep 2007
Jun 25th, 2009
1

Re: Redirecting to another page with a message

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 :)
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Jun 26th, 2009
0

Re: Redirecting to another page with a message

Perfect, many thanks for these details!
Reputation Points: 10
Solved Threads: 0
Light Poster
BigFormat is offline Offline
45 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: LevelTen Formmail script generating auto-response email
Next Thread in PHP Forum Timeline: Warning: mysql_fetch_array(): error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC