#1
  1. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,353
    Rep Power
    62

    Curl url doesn't give me the redirect meta data, but gives me the page


    So here's the deal. I'm curling a page that does a 301 redirect then shows the data from the redirect. I have no idea how the page is doing the redirect but I can find out if I have to.

    Here's what I'm doing:

    PHP Code:
    $url "somepage.php";
    $ch curl_init();
    curl_setopt($chCURLOPT_HEADER1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1); //Follow any redirects
    curl_setopt($chCURLOPT_URL$url);
    $output       curl_exec($ch);
    $request_info curl_getinfo($ch);
    print 
    "output: $output\n";
    print_r($request_info); 
    Now I get the response from $output, but under $request_info, I get:

    Code:
    Array
    (
        [url] => http://the_url
        [content_type] => text/html
        [http_code] => 301
        [header_size] => 321
        [request_size] => 268
        [filetime] => -1
        [ssl_verify_result] => 0
        [redirect_count] => 0
        [total_time] => 0.200507
        [namelookup_time] => 0.000676
        [connect_time] => 0.003916
        [pretransfer_time] => 0.003968
        [size_upload] => 0
        [size_download] => 28212
        [speed_download] => 140703
        [speed_upload] => 0
        [download_content_length] => -1
        [upload_content_length] => 0
        [starttransfer_time] => 0.195974
        [redirect_time] => 0
        [certinfo] => Array
            (
            )
    
        [redirect_url] =>
    )
    So I actually get back the data, yet the http_code value is still set to 301 (when I would expect it to be set to 200) and redirect_url is not set at all. Are there simply ways to do a redirect that can't be picked up via php's methods? Thanks in advance for any help you guys can give.
    Correspondence chess
    nothingbutchess.com
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    It's not anything that the remote site is doing. If PHP were not able to detect the redirect then you wouldn't have received any content. Beyond that I'm not sure why you're seeing those results.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo