Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2009, 02:36 PM   PM User | #1
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
header redirect issues on unix environment, but not on windows (WAMP)

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?

PHP Code:

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

Cheers,
Picco
crmpicco is offline   Reply With Quote
Old 09-21-2009, 02:43 PM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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?
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 09-21-2009, 02:49 PM   PM User | #3
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
What $order_id contains ? The redirect happens if it is not numeric. It is better to 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:
PHP Code:
// 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.
__________________
PHP Programmer

Last edited by SKDevelopment; 09-21-2009 at 02:52 PM..
SKDevelopment is offline   Reply With Quote
Users who have thanked SKDevelopment for this post:
crmpicco (09-21-2009)
Old 09-21-2009, 04:21 PM   PM User | #4
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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.

PHP Code:
    // 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 is offline   Reply With Quote
Old 09-21-2009, 04:57 PM   PM User | #5
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
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
crmpicco is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 AM.


Advertisement
Log in to turn off these ads.