CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Question Page download - cookie problem

    What I am doing:
    Simply downloading page using
    file_get_contents('somesite_url'), or implode('',file('somesite_url'))


    Problem:
    The page requries a cookie be present on client computer which is done after clicking a button on site, if I go to url through browser normally and click 'agree' button it saves cookie on my pc and page loads fine and that 'agree' button page is not loaded again, but when I load same page through php it returns contents of the page that shows button to agree.

    Question:
    How can I bypass this cookie problem, and report to remote site that cookie is present so that it returns me the contents of actual page rather than the page having 'agree' button?


    Need quick input and ideas for some solution.

    regards
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Page download - cookie problem

    You will need to use cURL. That way, you can retain a cookie, and then download the file.

    http://us.php.net/curl
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: Page download - cookie problem

    I resarched some abotu curl.
    Unfortunately constant CURLOPT_COOKIESESSION is not defined even in php 4.4.6.
    I actually cant go on higher version than this 4.x.x since this is the requirement.

    Using default wau of loading page using curl and maintaining buffer to get contents, it does not let cookies remain.

    Thanks for reply btw. You have any example that implement without CURLOPT_COOKIESESSION, let me know please.

    regards
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Page download - cookie problem

    Having a requirement of PHP 4 is not smart. PHP 4 is old and declared end of life.

    Either way, you don't need CURLOPT_COOKIESESSION. You need to use CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR. Then it will store the cookies to the hard disk and you can use them all you want.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: Page download - cookie problem

    Its not my script that needs cookies but the remote site that writes cookie for the first time it is fetched by php, and from second attempt it must load other pages rather than 'agree' page. So storing cookie in file is o no use to me.

    Any solution?

    regrads
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Page download - cookie problem

    You misunderstand. CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR create a file on your hard disk with the cookies set by the connections created using cURL. Once you load the first page which loads the cookies, then you load the second page. After the loading of the second page, you can then close the cURL connection.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: Page download - cookie problem

    Great PeejAvery thanks for your concern.
    I just was interested in quick solution so that I meet deadline and I got class called 'snoopy' http://snoopy.sourceforge.net/, so did not reinvent wheel .

    thanks for your answers.

    regards
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  8. #8
    Join Date
    Jan 2008
    Posts
    20

    Re: Page download - cookie problem

    You don't really need to store the cookie in a file, you can just place its name->value in a variable and send it to the remote host when it requires it.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured