Jump to content
xisto Community
Sign in to follow this  
ashish_m_k

php header() function help needed automatic re-direct

Recommended Posts

hey ppl, u seem to have real gud knowledge about php, i just wanted a little help...i designed this website, but i want that if i click on certain page, it should open for some few seconds and then browser should automatically redirect me to some other page....i tried this with header() function but i couldnt do the wait n redirect part, ...so somebody plz help....-thanx in advance!

Share this post


Link to post
Share on other sites

I don't think that this is possible with php but you can do it with javascript. This code goes in the <head> tag:

<script type="text/javascript"> function goOnwards() {   window.location = "http://bla.com"; } setTimeout("goOnwards()", 3000); </script>  <!-- Provide an alternative for those without javascript --> <noscript>   <meta http-equiv="refresh" content="3; url=http://bla.com"> </noscript>

Share this post


Link to post
Share on other sites

My answer in other topic:
http://forums.xisto.com/topic/32062-problem-with-page-redirect-help-me-out-with-this-problem/
I think that Header function better... <meta refresh>!

Code like

<meta http-equiv="refresh" content="5;url=http://forums.xisto.com/no_longer_exists/;
can be stopped by Escape button pressing!!!

I think that this code will help U.
<?phpheader("Location: http://http://www.example.com/;; /* Redirect browser *//* Make sure that code below does not get executed when we redirect. */exit;?>  

View full description about Header function at http://php.rinet.ru/manual/ru/function.header.php with some examples.

Share this post


Link to post
Share on other sites

I don't think header function makes any sense as you cannot send headers once you have started your content. It is helpful for redirection if you want to do something without sending any output to browser and then redirect (like one file for doing operations and redirect to other to display UI). But once you have displayed some UI, it would have already committed the headers to browser. So, when you try to redirect, it gives error "headers already sent".

Share this post


Link to post
Share on other sites

Hmm, this topic is pretty old. But anyway, in response to kvkv...

 

Of course the headers need to be sent prior to any output. The headers inform the client of information required to ensure the client knows what to do with the data, and they must come before the data to which they are related. This is not specific to PHP (or Apache or any other web server), but rather to the hypertext transfer protocol, the protocol you are almost definately using to access webpages (see the specification for version 1.1 - the current standard - for details).

 

For example, let's say there are two files the client requests - 'page.html', a webpage, and 'image.jpg', an image. We can associate both files with their types due to their extensions (and, in this case, their full file names), but a web browser is not going to be able to differentiate one from the other unless the server tells it which is which via the 'Content-Type' header, which would be something like 'text/html' for the webpage and 'image/jpeg' for the image. Although some clients do identify files based on their file extension, that's not the way the HTTP works, and is just one of the reasons header information must accompany every packet of data sent from a HTTP server to the client. Without the header information, the client is not going to know what the data is or what to do with it, as well as other critical information (in which case most clients treat the data as 'text/plain', which is why you will sometimes find the contents images or other binary files are being printed to the screen as text).

 

Anyway, my overdrawn, pointless lecture slash rant is done :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.