use fopen to parse a remote file that uses a cookie

Discussion in 'PHP' started by TeamPlayLotto, Jan 4, 2007.

  1. #1
    I have been playing about with parsing remote files recently and managed to parse a file to get the latest lottery results which works great.

    Now I would like to parse the same page that is shown when you visit http://www.virtualworlddirect.com/g.asp?m=28917 so I can extract the name showing in the red bar.

    I used the normal fopen and fgets to read each line into a buffer and check for a particular set of characters using strstr but the file that is fetched by the script doesn't contain the "Andy B(TheEmpireGroup.co.uk) Welcomes You" red bar.

    I think this is probably due to the fact that when a user surfs the page they get a cookie downloaded and then shown a page for that cookie owner. (it's an affiliate site). As the php is on a separate site, it doesn't get the cookie and so gets shown the page without any affiliate identification. (once you have a cookie on your computer, it doesn't show the page without affiliate identification)

    question is, how do I use php to parse the page as the user would see it? would it require some code to get the cookie first?

    Andy
     
    TeamPlayLotto, Jan 4, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. TeamPlayLotto

    TeamPlayLotto Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for that, I thought it might be something to do with being curly!

    $ch = curl_init("http://www.virtualworlddirect.com/vwdguest/default.asp?rq=0.6251795&m=28917");
    $fp = fopen("example_homepage.txt", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    Code (markup):
    I had to change the url because the text file orginally contained a message saying " this file exists at .."
    Now I have done that, the text file still doesn't contain the "And B.." bit.

    which curly bits am I missing?

    Andy
     
    TeamPlayLotto, Jan 4, 2007 IP