LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2005, 12:27 AM   #1
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
PHP redirection after showing a message


I have seen this functionality at this forum. After logging in, a message is displayed and the page redirected to the index page.

I would like to know how to achieve this. Unfortunately the header () command fails when there is some page output.

How can I redirect after displaying a success or failure message.

The header statement comes with this warning and no redirection takes place:
Code:
Warning: Cannot modify header information - headers already sent by (output started at /home/hari/web/links_directory/include/template.php:81) in /home/hari/web/links_directory/register.php on line
Is there any other way to redirect normally? I really don't want to use "include" statement as this may lead to some problems.
 
Old 07-08-2005, 12:42 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
To redirect after say 5 seconds, put the following at top of your PHP page, before you've output anything:

header("REFRESH:5;URL=http://redirection.url.com");

It has to be before any HTML has been sent. You can send HTML after the header function is called, however.

Another alternative is to use the equivalent HTML meta tag by putting the following in between the <head></head> tags:

<META HTTP-EQUIV="REFRESH" CONTENT="5" URL="http://redirection.url.com">
 
Old 07-08-2005, 01:32 AM   #3
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Well. I'm using templating system and all my HTML files are templates. I cannot use the META tags here because the PHP file outputs different HTML files for different contexts.

Is there any more generic way to redirect? I know it's a long shot, but I feel that using the header is a problem because the PHP output is different in different circumstances.
 
Old 07-08-2005, 01:39 AM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Scratch the previous message regarding the META tag. This strategy works!

header("REFRESH:5;URL=http://redirection.url.com");

I can call this statement from any place in my PHP file before outputting any content.

Thanks for the help.
 
Old 07-10-2005, 07:42 PM   #5
kcorkins
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Rep: Reputation: 0
Thumbs up Thanks! It worked for me too!

Thanks for the thread! It was exactly what I was looking for!
 
Old 07-11-2005, 07:18 PM   #6
Runnerdave
LQ Newbie
 
Registered: Jul 2005
Location: Australia
Posts: 13

Rep: Reputation: 0
Question very good and it works but...

It works perfect in firefox but I noticed that in IE 6 sp2 if I refresh the page before the automatic redirect happens it stays and the redirection is not performed, any solution for this?



 
Old 07-12-2005, 07:58 AM   #7
kcorkins
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Rep: Reputation: 0
I found this on the php documentation site;
Code:
<?php header("Location:http://www.redirection.url.com/");?>
I put that as the only line in index.php in the root folder where I had moved some pages. No page is displayed, and the browser is automatically redirected.
 
Old 07-12-2005, 10:40 AM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Yeah, the location option works well too. I typically use that, but in the case of the original poster where you want to display some message before redirecting, it doesn't work so well.

So far as Runner Dave's problem, I'm not sure. You could do what most sites I've seen do and provide a link on the page as well in case the browser doesn't redirect properly. Or just tell your IE users not to refresh the page!
 
Old 07-12-2005, 06:17 PM   #9
Runnerdave
LQ Newbie
 
Registered: Jul 2005
Location: Australia
Posts: 13

Rep: Reputation: 0
hi deiussum I will put the link, thanks a lot it "sort of" solves the problem :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel Message Redirection mschutte Linux - General 2 09-11-2005 02:47 AM
Have installed PHP for Apache2 but source code showing Tomo3000 SUSE / openSUSE 4 08-04-2005 07:14 PM
PHP: changing row color showing mysql results emilioestevezz Programming 15 09-13-2004 06:27 PM
Is there a way to use a message box with PHP? patpawlowski Programming 4 02-23-2004 06:38 PM
PHP Message Board Crashed_Again Linux - Software 5 02-25-2003 09:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration