/    Sign up×
Community /Pin to ProfileBookmark

CURL & login form

Hi guys,

I need a help here. I’m trying to create a script with CURL PHP to login and post something. So it will have 2 or more pages to follow before the real posting.

I’ve search the php.net and created a code below. However, the return from CURL is just the login page for both execution, and it’s not even logged in.

I’ve tried to:
– close the curl after 1st exec and open it again at 2nd –> no result
– put curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); –> no result

Any help?

Regards,

[code]<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER,’http://www.site.com’);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, “/cookie.txt”);
curl_setopt($ch, CURLOPT_URL,”http://www.site.com/login/login.php”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “username=user&password=pass”);
curl_exec ($ch);

curl_setopt($ch, CURLOPT_COOKIEFILE, “/cookie.txt”);
curl_setopt($ch, CURLOPT_URL,”http://www.site.com/folder/save.php”);
curl_exec ($ch);
curl_close ($ch);
?>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @mr_zhang 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...