| | |
Redirecting to another page with a message
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 38
Reputation:
Solved Threads: 0
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?
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.
•
•
Join Date: Dec 2007
Posts: 136
Reputation:
Solved Threads: 2
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:
This will then redirect them after the amount of time you specify to the url you specify!
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)
<script type="text/JavaScript"> <!-- redirectTime = "1500"; redirectURL = "http://www.yourwebsite.com"; function timedRedirect() { setTimeout("location.href = redirectURL;",redirectTime); } // --> </script> <div style="background-color:#ffcc00;padding:5px;width:100px;cursor:pointer;" onclick="JavaScript:timedRedirect()"> Click me to redirect </div>
This will then redirect them after the amount of time you specify to the url you specify!
Or you could just do:
Note, the echo must be after the header, or this will fail.
php Syntax (Toggle Plain Text)
header("Refresh: 3; url=http://www.google.com"); echo "You will be redirected to Google in 3 seconds...";
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
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.
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!
And use [code] tags!
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Message to be called on the same page in php (PHP)
- Its not redirecting to the same page (ASP.NET)
- Hotmail - ERROR ON PAGE (Geeks' Lounge)
- Hotmail "error on page" problem (Web Browsers)
- page.php?page=1,2,3,4,..inf. (PHP)
Other Threads in the PHP Forum
- Previous Thread: LevelTen Formmail script generating auto-response email
- Next Thread: Warning: mysql_fetch_array(): error
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop parse paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





