1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can't fetch my XenForo site w/ cURL

Discussion in 'General PHP and MySQL Discussions' started by MikeMpls, Jun 11, 2013.

  1. MikeMpls

    MikeMpls Well-Known Member

    Why does this code return a null string for a XenForo site (main forum index)? I've tried it with several of my XenForo sites, works fine w/ sites handled by HTML, PERL & other PHP scripts.

    It displays "0", not "cURL failed".

    PHP:
    <?php
    // create a new cURL resource
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"http://my xenforo site");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_HEADERfalse);

    $data curl_exec($ch);
    curl_close($ch);
    if (
    $data === false)
    {
      echo 
    'cURL failed';
      exit;
    }
    echo 
    strlen($data);
    ?>
     
  2. AndyB

    AndyB Well-Known Member

    I just tested the code and it works for my site. Send me a PC with your URL and I'll try it on your site.
     
  3. MikeMpls

    MikeMpls Well-Known Member

    I got it to work by passing the full path of the ".../index.php" file.

    Strangely, I did not have to do that with sites whose default directory index was a HTML or PERL file.

    So it's still a curiosity as to why this distinction exists.
     
  4. MikeMpls

    MikeMpls Well-Known Member

    Thanks, I'll bet you used the full URL!
     
  5. AndyB

    AndyB Well-Known Member

    Correct, I used the full URL to my forum.
     

Share This Page