473,699 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirect before header...?

80 New Member

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?
Oct 8 '09 #1
7 1983
1,584 Recognized Expert Top Contributor
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.
Oct 8 '09 #2
80 New Member
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..
Oct 8 '09 #3
1,584 Recognized Expert Top Contributor
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.
Oct 8 '09 #4
8,658 Recognized Expert Moderator Expert
there’s also the HTML refresh meta tag.
Oct 8 '09 #5
1,584 Recognized Expert Top Contributor
Yep, I agree but I guess we need a script based solution for this as he/she has mentioned that
....this page is counting down for a redirect....
So there should be a visible time countdown on the page.
Oct 8 '09 #6
8,658 Recognized Expert Moderator Expert
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).
Oct 8 '09 #7
1,168 Recognized Expert Top Contributor
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.
Oct 8 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Damo | last post by:
Could someone please help me. I am a newbie at PHP. I downloaded formail.php Version 5.0 from Jacks scripts( http://www.dtheatre.com/scripts/ )and changed the required areas to my email address and the domain server address. (these changes were in the $recipient and $referers section) I have set up the form and can get the form to email me the results. I have two main problems. The first one is that I am trying to get the form to go to a...
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?> Should it not redirect to www.google.com? I can't get the header() function to redirect. I'm trying to take an online reservation... the customer fills out
by: Sentinel | last post by:
here is the entire thread From: "Kimmo Laine" <eternal.erectionN0.5P@Mgmail.com> Subject: Re: script in body Date: Mon, 20 Jun 2005 17:46:28 +0300 Message-ID: <d96klv$8vi$1@phys-news1.kolumbus.fi> Lines: 64 "Sentinel" <support@elma.hr> kirjoitti
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried performing a redirect when I had left in print "Content-type:text/html\n\n";
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script type="text/javascript"> window.location = "http://www.someserver.com/somePage.html"; </script>
by: Mike P | last post by:
I'm using MamboServer for my site, and have switched from SEF URLs to standard URLs. Of course, I'm indexed everywhere with the SEF urls. I'm trying to write a script, so that users and search engines can find the pages using the new url. My goal is, that if I can decode the URL they're requesting, I'll send them a 301 header and redirect them to the new URL. Otherwise, I'll send them a 404 error with a message. It's not working, all I...
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has been sent like If response.IsSentHttpHeader then ....
by: Dave | last post by:
Hi All, Can anyone suggest a reliable solution to php redirect?: header("Location: $redir_url"); if the above times out in $timeout seconds header("Location: $alt_redir_url"); Many thanks,
by: Paul Lautman | last post by:
JRough wrote: What do you mean by "redirect the output to Excel"??? Excel isn't a location, it's a spreadsheet program that some (but not all users) will have on their machine. BTW, Location: is supposed to take a fully qualified URL.
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category and Brand I need to make some changes on a a number of brands in a Category
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.