Connecting Tech Pros Worldwide Help | Site Map

Redirect before header...?

Newbie
 
Join Date: Dec 2008
Posts: 27
#1: Oct 8 '09
Greetings!

I have a php page where I need to redirect the request but for this i need a script loaded first..

Something like:
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.   function StatusChange(text) {window.status = text; window.status = ''} 
  3. </script>
and later...
Expand|Select|Wrap|Line Numbers
  1. header("Location: javascript: StatusChange ('screen')");
How is this possible when PHP demands the redirect code BEFORE any header?
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,439
#2: Oct 8 '09

re: Redirect before header...?


I hope you are missing something here. May be first you need to understand the difference between the server side scripting language and client side scripting language.
Newbie
 
Join Date: Dec 2008
Posts: 27
#3: Oct 8 '09

re: Redirect before header...?


Quote:

Originally Posted by ak1dnar View Post

I hope you are missing something here. May be first you need to understand the difference between the server side scripting language and client side scripting language.

Ok lets say I need a page to be loaded fully with header and everything, and this page is counting down for a redirect. like on most download sites.. Maybe this where a better way to ask? Please say if im still not understanding.
And forget the JS code..
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,439
#4: Oct 8 '09

re: Redirect before header...?


Pheddy, What you get on your browser when accessing the url of the web is a rendered HTML output of the php script. So there is no way to call the php header() function from your JS code.

If you need to redirect your page after a certain time, again that is impossible only with PHP. So your best approach for that would be a javascript based redirection with a timer.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#5: Oct 8 '09

re: Redirect before header...?


Quote:

Originally Posted by ak1dnar View Post

So your best approach for that would be a javascript based redirection with a timer.

there’s also the HTML refresh meta tag.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,439
#6: Oct 8 '09

re: Redirect before header...?


Quote:

Originally Posted by Dormilich View Post

there’s also the HTML refresh meta tag.

Yep, I agree but I guess we need a script based solution for this as he/she has mentioned that
Quote:
....this page is counting down for a redirect....
So there should be a visible time countdown on the page.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#7: Oct 8 '09

re: Redirect before header...?


Quote:

Originally Posted by ak1dnar View Post

Yep, I agree but I guess we need a script based solution for this as he/she has mentioned that

when I look at the given code, it is not that obvious to me. the given Javascript function is useless, the PHP code (actually it’s the HTTP code) is wrong. all that remains is a redirect, which can be 100% done in HTML, no Javascript required. although Javascript will make it looking pretty… (you can still do that as addition)

and while I’m at it, a javascript download timer can easily be bypassed… ah, and to start a download, you do not use a redirect (well, at least not most of the time).
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#8: Oct 8 '09

re: Redirect before header...?


As Dorm said, PHP is not needed.
If you want a timer and do not want to be limited by something as simple as turning your javascript off: use meta refresh and have a javascript timer totally separate (counting down on its own). Also display a message that if their javascript is off, they will not see the timer, but they have 30secs or what ever.

Basically meta refresh will refresh regardless, provided their browser has not been tweaked, but I think that would defeat the point anyway if it forwards to a download.

I think, Dorm, that this is a system that will have a premium option which will not require waiting, which is why a redirect is desired to start a download.
Reply