Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-09 22:46:44

ferenczi
Member
Registered: 2005-01-31
Posts: 67

error page redirect after 5-second delay using PHP

When a user gets a 404 or other error and lands on the default error page, I would like to implement a redirect to ‘/’ after a brief delay. In the past I’ve used js for this but am trying to use PHP in this instance. I may simply go back to using js but I want to see if I can do this. Seems so simple. But it doesn’t work.

Having searched through the forum and FAQ I see that the usual way of calling php by <? is not possible (besides, it didn’t work; that’s what I tried first) so I’m doing:

<txp:php> 
header('refresh:5;url=/');
</txp:php>

and I’ve also tried

<txp:php>
ob_start();
header('refresh:5;url=/');
</txp:php>

but that doesn’t work.

I’ve also tried with “send last modified headers” set to yes and to no and it makes no difference. It’s certainly clear from this that I’m no expert on PHP but this seems like it should be straightforward. Anyone have any ideas?

I’m running txp version 4.0.7.
Server is running PHP 5.2.6
htaccess looks like

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /relative/web/path/
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]
	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php
	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
#php_value register_globals 0

Could it have something to do w/the fact that the register globals thing is commented out?

Thanks in advance for any insight.

Last edited by ferenczi (2009-01-09 22:49:40)

Offline

#2 2009-01-10 02:31:42

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: error page redirect after 5-second delay using PHP

First of all, what are your server specs? PHP version? fcgi? Have you tested that standalone? Does your browser support refresh header? Is the header sent? What does your browser report to the header? etc. etc. (you see those from browser header log and servers logs etc).

Secondly, I would recommend to not use refresh headers, because ppl don’t like’em, usually redirects are considered as attacks when they are transparent. For example some browsers try to block refresh -header.

Basically, if want to redirect the page, I would recommend to use plain meta tag:

<meta http-equiv="refresh" content="5; url=/" />

On your error page template and that’s it. Easiest ways are best. Note that older IEs, Netscape, older Operas and some browsers do not support refreshes. Only way to force those browsers to refresh redirect is JavaScript.

Last edited by Gocom (2009-01-10 02:34:33)

Offline

#3 2009-01-10 02:43:01

ferenczi
Member
Registered: 2005-01-31
Posts: 67

Re: error page redirect after 5-second delay using PHP

Thanks so much Gocom. I agree that easiest ways are best and the redirect = attack issue hadn’t occurred to me. That’s a deal-breaker. Basically I was just interested in trying something I hadn’t tried before. I’ll either try your simple meta tag suggestion or use my usual js method with an option to click on link back to home page if user either has js disabled or doesn’t want to wait.

Keep it simple. Less is more.

Thanks again for your prompt and thorough response.

Offline

#4 2009-01-10 03:43:23

ferenczi
Member
Registered: 2005-01-31
Posts: 67

Re: error page redirect after 5-second delay using PHP

Gah, I don’t know how this is possible, but the meta tag method isn’t working for me! I did just as you said, stuck it in the head … not working. Wha? How can it not work?

Offline

#5 2009-01-10 04:23:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: error page redirect after 5-second delay using PHP

ferenczi wrote:

Gah, I don’t know how this is possible, but the meta tag method isn’t working for me! I did just as you said, stuck it in the head … not working. Wha? How can it not work?

What browser you are using? Are you using a real domain, or a made up development address (like txp.localhost).

Also, it might be because the page actually sends 404 header that means that the page doesn’t exist and then your browsers thinks that it must to not follow redirects. Because this is is a client side deal and browsers can kinda deside what to do and what not. It’s kinda like talking to wild animals: they listen but can also accidently eat… your friends head because they don’t understand what you are saying.

It might also help to look up what your browser responds to the meta. Does it read it, what logs say and so on. Look those, they will answer. Logs. Headers. Browser’s :)

Last edited by Gocom (2009-01-10 04:26:41)

Offline

#6 2009-01-10 06:36:24

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: error page redirect after 5-second delay using PHP

Firebug extensioan for Firefox can help to look through recieved headers, besdies this there are addditional plugins for Firefox which allow to manage sent\recieved extensions. Try to google “firebug” :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB