Solved

PHP header auto refresh doesn't always work

Posted on 2014-11-06
5
361 Views
Last Modified: 2014-12-18
I have a login script where I do some integrity testing for the user submission. If all is fine, I set a session variable and do a refresh.  The code looks like this:

       $url = "https://mysite.com/index.php";
	header('refresh: 0; url='.$url); 
	exit; // to keep the rest of the form from continuing

Open in new window


What happens every once and a while (like 1 in 100) is that the auto refresh doesn't fire and since there isn't any text on the page it appears as if the page has frozen.

I just added this line which at least puts something up on the person's page. Otherwise all they got was a "white screen of death"...
      print 'Your page should auto refresh in two seconds. If not, please click this link: <a href="'.$url.'">'.$ur2.'</a>';

So now people at least see something other than the white screen.

Any insight on how to fix this so that it fires for everybody?
0
Comment
Question by:pkonstan1
  • 2
5 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 40426863
Though it's deprecated by the W3, all browsers support the meta-refresh tag.  You can write this directly to the browser with an echo statement.
<meta http-equiv="refresh" content="0;URL='$url'" />

Open in new window

0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 300 total points
ID: 40427000
Since you are not doing a delayed refresh, you should probably just use 'Location' instead of 'refresh'.  http://php.net/manual/en/function.header.php
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 40427036
0
 
LVL 58

Expert Comment

by:Gary
ID: 40507794
I've requested that this question be closed as follows:

Accepted answer: 500 points for Dave Baldwin's comment #a40427000

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now