LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-09-2004, 12:53 AM   #1
Elijah
Member
 
Registered: Feb 2003
Location: Philippines
Distribution: Debian, Mandrake, Redhat
Posts: 90

Rep: Reputation: 15
Question PHP Redirect


I have a page in php that has some protection for hijacking a page(editing the browser URL address to go to another page), it compares some variables during the session & if there's an illegal entry, it redirects the user back to the home page.

I tried using 'header' for redirecting but it gives me this error:

Code:
Warning: Cannot add header information - headers already sent by....

Next I tried is javascript :
document.location.href='mainpage.php'

It works but .. for half a second before redirecting, the user can get a glimpse of the page, that's not supposed to happen. I noticed that this security issue can be noticed in konqueror but not in firefox browsers. In firefox the redirection is done without continuing to load the page.

Any suggestions on what other redirect codes I could use?? or probably some way to quickly stop the page from loading before redirecting?

Last edited by Elijah; 09-09-2004 at 01:08 AM.
 
Old 09-09-2004, 04:50 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
This should do it:
Code:
header("Location: http://www.example.com/");
...but you already tried and got a "headers already sent" warning.
This is because it deals with http headers, not html headers. HTTP header need to be sent before any "normal" output.

So to solve it, either put the header() call before any echo-ing or html and it will work. You could also make PHP buffer its output, so the web-server will not start sending anything until the PHP-script is finished.

Search for "buffer" at http://php.net/header for more information on this.
 
Old 09-09-2004, 09:56 PM   #3
Elijah
Member
 
Registered: Feb 2003
Location: Philippines
Distribution: Debian, Mandrake, Redhat
Posts: 90

Original Poster
Rep: Reputation: 15
ob_start(); worked, I also added in

echo "<!--";

after the redirection code for good measure Thanks!
 
  


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
Php redirect script newuser455 Programming 2 08-03-2005 07:23 PM
Coding a redirect function in php mrobertson Programming 2 06-22-2005 08:40 AM
how to redirect PHP code to another page bahadur Programming 3 03-21-2005 05:59 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
php header redirect problem after upload rvn Linux - Newbie 2 02-08-2004 07:19 AM

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

All times are GMT -5. The time now is 03:43 AM.

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