...

View Full Version : header redirect issues on unix environment, but not on windows (WAMP)



crmpicco
09-21-2009, 03:36 PM
Has anyone experienced an issue before with using code similar to this on a Unix environment? Previously, I have had an issue where it worked on my WAMP environment, but not when it was run on a Linux box. Is it something to do with the header function?




// error - redirect
if (!is_numeric($order_id)) {
header("Location: crmpicco_order.php?order_id=$order_id&errno=2");
exit;
}



Cheers,
Picco

CFMaBiSmAd
09-21-2009, 03:43 PM
The only things that would affect if the posted code worked is what $order_id is and if content has been output that would prevent the header from working.

Have you checked what is in $order_id at that point in the code and are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors is set to ON so that php would help you by displaying all the errors it detects?

SKDevelopment
09-21-2009, 03:49 PM
What $order_id contains ? The redirect happens if it is not numeric. It is better to urlencode (http://php.net/urlencode) it. Also (though probably iy is not the source of the problem) I would recommend to use absolutel URL's, not relative, in Location headers. Relative URL's would be fine with HTTP 1.0 but as far as I know HTTP 1.1 requires URL's to be absolute.

So the code would be something like this:


// error - redirect
if (!is_numeric($order_id)) {
header('Location: http://mysite.com/crmpicco_order.php?order_id=' . urlencode($order_id) . '&errno=2');
exit;
}


Also could you explain what does not work under Linux ? Do you get any error messages ? Maybe "headers already sent" ? Or something else has been wrong ? Could you explain please ?

Edit: while I have been typing CFMaBiSmAd posted a similar answer. Still they are not completely duplicate so I do not delete my post.

crmpicco
09-21-2009, 05:21 PM
I haven't got any specific errors (at the moment anyway) as such as the code hasn't been moved onto the box that is running Linux. It will be shortly, but not quite as yet. However, I had a very similar issue recently where the header function was causing me issues when run on the linux box, but not on my Windows box. I ended up having to re-write logic in the code, but in this case i'm really looking to avoid that. In these instances, there is a lot that can be said of remote development, same environment, same configuration files, same file system etc....

Thanks for the HTTP and urlencode information, i've changed the redirect just incase this is a potential issue between the two environments. Hopefully, this will catch the problem before it arises.



// error - redirect
if (!is_numeric($order_id)) {
header("Location: http://" . $_SERVER["SERVER_NAME"] . "/php_code/crmpicco_order.php?order_id=" . urlencode($order_id) . "&errno=2");
exit;
}

crmpicco
09-21-2009, 05:57 PM
Those recommendations seem to have done the trick on the Linux environment, i'm guessing it's likely to be specifying the full URL rather than just the script. But I suppose the urlencode function is good practice.

Cheers for the help!

Picco



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum