/    Sign up×
Community /Pin to ProfileBookmark

file_get_contents question

Hi,

I am using file_get_contents to get the content of an external website. This however lets me only view the content if I accept cookies. Is there a way that I can accept this cookie?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Mar 19.2007 — Yes - but with cURL.
Copy linkTweet thisAlerts:
@stephan_gerlachauthorMar 19.2007 — do you have any example on how to do it? I never used cURL but just looking at it now
Copy linkTweet thisAlerts:
@stephan_gerlachauthorMar 19.2007 — This is what I have
[code=php]
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
$data = curl_exec($ch);
curl_close($ch);
[/code]


not sure what the code really does but it is not working. How can I find out if the cookies the website (i.e. www.domain.com ) is setting or trying to set?
Copy linkTweet thisAlerts:
@bokehMar 19.2007 — This however lets me only view the content if I accept cookies[/QUOTE]This doesn't make any sense. How does the remote site know you are not saving the cookie? Are there multiple requests?
Copy linkTweet thisAlerts:
@NightShift58Mar 19.2007 — not sure what the code really does but it is not working.[/QUOTE]What isn't working?

If the website/page wants you to accept cookies, it's probably because it sets them somewhere else and on this particular page, it's only checking if you've accepted it in the past.

You may have to "backup",by which I mean use cURL to get another page where the cookie is being sent/set, store it and then go to the page where the site is checking for the existence of the cookie (multiple request, as Bokeh alluded).

Is the page you're trying to get "public" - can anyone see it?
×

Success!

Help @stephan_gerlach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...