Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post

    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

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,047
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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.
    Last edited by SKDevelopment; 09-21-2009 at 02:52 PM.

  • Users who have thanked SKDevelopment for this post:

    crmpicco (09-21-2009)

  • #4
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    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;
        } 

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •