I want to redirect a page automatically in PHP
Logout.php:
Where base.php calls the database and starts the session:
When pressing logout, I am not getting back to
Eric Leschinskiindex.php
.93.8k4040 gold badges336336 silver badges288288 bronze badges
Javeria HabibJaveria Habib15722 gold badges44 silver badges1515 bronze badges
4 Answers
This should work, you had an extra
=
before 0
: Linky https://en.wikipedia.org/wiki/Meta_refresh
Ry-♦174k4242 gold badges356356 silver badges374374 bronze badges
cristi _bcristi _b
As far as I know,
HTML
, JavaScript
and PHP
provide their own way of page / header redirection. Here are three examples, showing how to redirect to http://google.com
# JavaScript:
# HTML:
Note The 0 in
content='0;
, is a value for seconds. It tells the browser how many seconds it should wait before starting the redirect. # PHP:
Note A PHP
samayosamayoheader()
must be Always be placed before outputting anything to the browser; even a single empty space. Otherwise, it will cause the infamous 'header already sent' errors.10.4k1212 gold badges5656 silver badges8787 bronze badges
you can put this on your PHP code:
Note that as per all headers, this must be placed before any output (even whitespace).
Nick5,49311 gold badge2525 silver badges4545 bronze badges
gamehelp16gamehelp1692711 gold badge66 silver badges2121 bronze badges
Meta refresh syntax is slightly wrong
More details herehttp://en.wikipedia.org/wiki/Meta_refresh
The cleaner way is to send a http redirect header
More details herehttp://en.wikipedia.org/wiki/HTTP_301
logout.php
Concerning absolute URIs in redirects W3C says
14.30 Location
The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. Uncharted 3 pc game license key. For 201 (Created) responses, the Location is that of the new resource which was created by the request. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.
An example is:
Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Michel FeldheimMichel Feldheim14.5k44 gold badges4545 silver badges7171 bronze badges
Not the answer you're looking for? Browse other questions tagged phphtmlhttp or ask your own question.
What do I have to do to have a function on a website where it says it will redirect you to the site in 3 seconds or so?
codedude
codedudecodedude3,0901313 gold badges5151 silver badges7676 bronze badges
7 Answers
Darin DimitrovDarin Dimitrov865k231231 gold badges30533053 silver badges27742774 bronze badges
You're probably looking for the
meta
refresh
tag:Note that use of
LukeHLukeHmeta
refresh
is deprecated and frowned upon these days, but sometimes it's the only viable option (for example, if you're unable to do server-side generation of HTTP redirect headers and/or you need to support non-JavaScript clients etc).213k4646 gold badges317317 silver badges387387 bronze badges
If you want greater control you can use javascript rather than use the meta tag. This would allow you to have a visual of some kind, e.g. a countdown.
Here is a very basic approach using
mbrevoortmbrevoortsetTimeout()
3,30344 gold badges3232 silver badges4747 bronze badges
Here's a complete (yet simple) example of redirecting after X seconds, while updating a counter div:
The initial content of the
noamtmnoamtmcounter
div is the number of seconds to wait.4,7401212 gold badges4848 silver badges7979 bronze badges
The simplest way is using HTML META tag like this:
noamtm4,7401212 gold badges4848 silver badges7979 bronze badges
EhsanEhsan1,71311 gold badge1515 silver badges3030 bronze badges
Place the following HTML redirect code between the and tags of your HTML code.
<meta HTTP-EQUIV='REFRESH'>
The above HTML redirect code will redirect your visitors to another web page instantly. Theauthor'>Muhammad SaqibMuhammad Saqib
1,13011 gold badge2424 silver badges3939 bronze badges
Use this simple javascript code to redirect page to another page using specific interval of time..
Please add this code into your web site page, which is you want to redirect :
Sunny S.MSunny S.M3,13111 gold badge2727 silver badges3030 bronze badges
protected by Community♦Aug 15 '15 at 6:05
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged htmlredirect or ask your own question.
Is it possible to set up a basic HTML page to redirect to another page on load?
chobochobo13.7k3232 gold badges107107 silver badges176176 bronze badges
26 Answers
Try using:
Note: Place it in the head section.
Additionally for older browsers if you add a quick link in case it doesn't refresh correctly:
<p><a href='http://example.com/'>Redirect</a></p>
Will appear as
This will still allow you to get to where you're going with an additional click.
Sébastien8,6621111 gold badges4040 silver badges6060 bronze badges
ValerijValerij23.4k11 gold badge2121 silver badges3737 bronze badges
I would use both meta, and JavaScript code and would have a link just in case.
For completeness, I think the best way, if possible, is to use server redirects, so send a 301 status code. This is easy to do via
Billy MoonBilly Moon.htaccess
files using Apache, or via numerous plugins using WordPress. I am sure there are also plugins for all the major content management systems. Also, cPanel has very easy configuration for 301 redirects if you have that installed on your server.42.1k1919 gold badges101101 silver badges203203 bronze badges
connectyourcharger1,02811 gold badge66 silver badges2525 bronze badges
amit_gamit_g25.6k55 gold badges4848 silver badges105105 bronze badges
I would also add a canonical link to help your SEO people:
Auto Redirect Html Code Generator
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
lrkwzlrkwz4,03922 gold badges2626 silver badges4444 bronze badges
This is a sum up of every previous answers plus an additional solution using HTTP Refresh Header via .htaccess
1. HTTP Refresh Header
First of all, you can use .htaccess to set a refresh header like this
This is the 'static' equivalent of using the
header()
function in PHPNote that this solution is not supported by every browser.
2. JavaScript
With an alternate URL:
Without an alternate URL:
Via jQuery:
3. Meta Refresh
You can use meta refresh when dependencies on JavaScript and redirect headers are unwanted
With an alternate URL:
Without an alternate URL:
Using
<noscript>
:Optionally
As recommended by Billy Moon, you can provide a refresh link in case something goes wrong:
If you are not redirected automatically:
<a href='http://example.com/alternat_url.html'>Click here</a>
Resources
Mateusz Konieczny90611 gold badge1414 silver badges3434 bronze badges
RafaSashiRafaSashi10.7k66 gold badges5959 silver badges7575 bronze badges
The following meta tag, placed between inside the head, will tell the browser to redirect:
Replace seconds with the number of seconds to wait before it redirects, and replace URL with the URL you want it to redirect to.
Alternatively, you can redirect with JavaScript. Place this inside of a script tag anywhere on the page:
IllidanS47,11922 gold badges3232 silver badges6262 bronze badges
Peter OlsonPeter Olson84.3k4141 gold badges175175 silver badges229229 bronze badges
It would be better to set up a 301 redirect. See the Google's Webmaster Tools article 301 redirects.
RickyA9,95844 gold badges5454 silver badges8181 bronze badges
Alex KAlex K
If you are looking forward to follow modern web standards, you should avoid plain HTML meta redirects. If you can not create server-side code, you should choose JavaScript redirect instead.
To support JavaScript-disabled browsers add a HTML meta redirect line to a
noscript
element. The noscript
nested meta redirect combined with the canonical
tag will help your search engine rankings as well.If you would like to avoid redirect loops, you should use the
location.replace()
JavaScript function.A proper client-side URL redirect code looks like this (with an Internet Explorer 8 and lower fix and without delay):
Paul15.3k1212 gold badges6161 silver badges8888 bronze badges
Patartics MilánPatartics Milán3,72744 gold badges1616 silver badges2929 bronze badges
You could use a META 'redirect':
or JavaScript redirect (note that not all users have JavaScript enabled so always prepare a backup solution for them)
But I'd rather recommend using mod_rewrite, if you have the option.
Kamil Kisiel12.3k99 gold badges4040 silver badges5353 bronze badges
CzechnologyCzechnology12.4k88 gold badges5050 silver badges7878 bronze badges
As soon as the page loads, the
Peter Mortenseninit
function is fired and the page is redirected:14.2k1919 gold badges8888 silver badges115115 bronze badges
kkkkkk1,14111 gold badge1515 silver badges3232 bronze badges
Place the following code between the <HEAD> and </HEAD> tags of your HTML code:
The above HTML redirect code will redirect your visitors to another web page instantly. The
Peter Mortensencontent='0;
may be changed to the number of seconds you want the browser to wait before redirecting.14.2k1919 gold badges8888 silver badges115115 bronze badges
Muhammad SaqibAuto Redirect Html Script Contoh Free
Muhammad Saqib1,13011 gold badge2424 silver badges3939 bronze badges
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
SebiSebi
I found a problem while working with a jQuery Mobile application, where in some cases my Meta header tag wouldn't achieve a redirection properly (jQuery Mobile doesn't read headers automatically for each page so putting JavaScript there is also ineffective unless wrapping it in complexity). I found the easiest solution in this case was to put the JavaScript redirection directly into the body of the document, as follows:
This seems to work in every case for me.
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
ScotsmanScotsman
The simple way which works for all types of pages is just to add a
parvusmeta
tag in the head:3,38633 gold badges2727 silver badges5151 bronze badges
P. BANERJEEP. BANERJEE
You should use JavaScript. Place the following code in your head tags:
kriscross07kriscross07
You can auto redirect by HTTP Status Code 301 or 302.
For PHP:
Flexo♦71.3k2222 gold badges153153 silver badges237237 bronze badges
Vô VịVô Vị
Just for good measure:
Make sure there are no echo's above the script otherwise it will be ignored.http://php.net/manual/en/function.header.php
rubo778,8371515 gold badges7676 silver badges162162 bronze badges
EdwardEdward1,07744 gold badges1414 silver badges3030 bronze badges
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
pat capozzipat capozzi1,05911 gold badge1515 silver badges1515 bronze badges
I use a script which redirects the user from index.html to Login Page
ZolfaghariZolfaghari
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
JoshYates1980JoshYates19802,36822 gold badges2828 silver badges4848 bronze badges
Pirate of MarmaraPirate of Marmara
You don't need any JavaScript code for this. Write this in the
<head>
section of the HTML page:As soon as the page loads at 0 seconds, you can go to your page.
Peter Mortensen14.2k1919 gold badges8888 silver badges115115 bronze badges
Yash JainYash Jain
As far as I understand them, all the methods I have seen so far for this question seem to add the old location to the history. To redirect the page, but do not have the old location in the history, I use the
Peter Mortensenreplace
method:14.2k1919 gold badges8888 silver badges115115 bronze badges
Paul OgilviePaul Ogilvie19.5k33 gold badges1212 silver badges3535 bronze badges
This is a redirect solution with everything I wanted but could not find in a nice clean snippet to cut & paste.
This snippet has a number of advantages:
- lets you catch and retain any querystring params folks have on their url
- makes the link unqiue to avoid unwanted caching
- lets you inform users of the old and new site names
- shows a settable countdown
- can be used for deep-link redirects as retains params
How to use:
If you migrated an entire site then on the old server stop the original site and create another with this file as the default index.html file in the root folder. Edit the site settings so that any 404 error is redirected to this index.html page. Torchlight 1 free download full version crack. This catches anyone who accesses the old site with a link into a sub-level page etc.
Now go to the opening script tag and edit the oldsite and newSite web addresses, and change the seconds value as needed.
Save and start your website. Job done - time for a coffee.
Vanquished WombatVanquished Wombat4,09011 gold badge1414 silver badges4040 bronze badges
Use this code:
Please pay attention:put it in the head tag.
AmerllicAAmerllicA
GameMaster1928GameMaster1928