www.webdeveloper.com
Results 1 to 12 of 12

Thread: 302 redirect works fine locally, not when online

  1. #1
    Join Date
    Mar 2005
    Posts
    140

    302 redirect works fine locally, not when online

    I have a page which is a one php page and when there is POST data it calls a function that does a 302 redirect (header sending). Locally it works just fine, but online it gives out a Warning (headers already sent).

    The nature of the warning is well understood. What I do not get is how come on my local machine it works fine?

  2. #2
    Join Date
    Mar 2010
    Posts
    97
    try this chap:

    PHP Code:
    <?php
    $url 
    "http://whatever.org";

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: ".$url);
    exit;
    ?>
    i ran into the same issue a month ago, i was using AppServ to run PHP in windows, everything worked lovely, i uploads me whole site and absolutely nothing worked - i depend on header redirects heavily.

  3. #3
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Are there any IP or hostname contingent statements in the app/page?
    Are you seeing any errors in the browser when you connect remotely?

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    Are you uploading the files via FTP? If so, are you ensuring that you are doing so in ASCII mode? Also make sure your editor is saving files without a BOM - though I am greatly suspecting it is the FTP issue so check that first.

  5. #5
    Join Date
    Mar 2005
    Posts
    140
    ASCII mode did not help. Saving files without BOM.
    (do I have to use ASCII mode for all files or just for code? it seemed to break some images)

    But why any of those things could matter anyway?
    And are there any other ideas I could look into?
    Last edited by Louigi Verona; 09-25-2010 at 07:45 AM.

  6. #6
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    compare server tech: iis vs apache
    compare phpinfo(); on both machines.

    edit: is this only a problem with redirection, or are more things different?
    Last edited by eval(BadCode); 09-25-2010 at 07:57 AM.

  7. #7
    Join Date
    Mar 2005
    Posts
    140
    Hey!
    Thanks for a quick reply!
    Only redirect is a problem, the rest is very well.

    The difference I found is this:
    Local: Server API Apache 2.0 Handler
    Online: Server API CGI

    But online server is using Apache, I checked.

    phpinfo give lots of info and some of it is different, some is not. I need to know what to look for. What setting might affect this?

    On the other site I am doing it, redirect works fine, but the warning is still there (data will be resent) if I go BACK. Localy it does not happen and whole reason of using such a redirect would be to avoid this situation.
    Last edited by Louigi Verona; 09-25-2010 at 08:48 AM.

  8. #8
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Code:
                       
                             cgi
    Directive                         Local Value    Master Value
    cgi.check_shebang_line                 1              1
    cgi.fix_pathinfo                       1              1
    cgi.nph                                0              0
    cgi.rfc2616_headers                    0              0
    
    No idea honestly... search for stuff with "header", "redirect", "cgi"?
    I found all 3 in mine, then figure out what it means I guess- if it's different anyways.

  9. #9
    Join Date
    Mar 2005
    Posts
    140
    It is so weird. Thanks, I will search.

  10. #10
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    It could also be .htaccess, I know you can redirect using those also. Just a shot in the dark. Otherwise I don't think I can be of much more help.

    PHP Versions?

  11. #11
    Join Date
    Mar 2005
    Posts
    140
    Wait a minute.

    Ha!


    Well, look. I understand why the warning is issued - indeed, it should. The header is called when some html IS actually output, since that header is INSIDE one function I am using. However, it works fine offline. By the book - it shouldn't. But it does. How come?

    Here's how the function looks, it is called after some html had been output.

    PHP Code:
    elseif($_POST['usingitem'] && CheckInventory($item)==false){    

        
    $_SESSION['try']=$page;

        unset(
    $_POST);

        
    header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?page='.$page);

        } 
    It's just part of the function where it is used.

    Weird?

  12. #12
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Heh. That would always be my first guess when I get that headers already sent problem.

    edit: lol cgi.check_shebang_line

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles