Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > php page redirecton question...

php page redirecton question...
Thread Tools
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Jul 11, 2003, 06:48 PM
 
Hi.

I am playing around with PHP4, and I keep encountering a problem with redirecting the browser to a new page.

In the past, when using ASP or JSP, I would do some business logic in a page and then do a page redirect if necessary. With PHP I've seen code that adjusts the header of the page.

Here is what I'm currently doing...

$theNextPage = "/errorpage.php";
// do some stuff here
if( strlen($myerrormsg) > 0 ) {
header(sprintf("Location: %s", $theNextPage ));
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Jul 11, 2003, 09:13 PM
 
i know the following works:
[php]
header ("Location:http://domain-here.com/path/to/page.html");
[/php]


but remember, if you have send ANY other data you will get an error that headers have already been sent.

if you need to do that your best bet is with javascript

if you know where the page is don't bother with a printf statement, i can't think of any other reason that wouldn't work

--will
edit: don't automaticly parse url's
     
Fresh-Faced Recruit
Join Date: May 2001
Location: USA
Status: Offline
Reply With Quote
Jul 14, 2003, 08:04 PM
 
I know where you're coming from man. We java developers instinctively try to use redirects to seperate controller and view. I know the header() function will get you there, but, I hope someone corrects me if I'm wrong, it's not really the recommended way to handle things with PHP. Like the first reply said, it's a hassle to try to move the redirect to the very beginning of the page or to use output buffering - ob_start() and ob_end_flush().
I've started to simply use includes instead. They're easier and you get access to variables from the controller.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2