简体   繁体   中英

PHP cURL: How do I make it visit this website before continuing?

I am passing post data to a website, but I have to visit the homepage first before I can navigate to any other parts of the website. So how can I do that? Do I just use a header redirect and then have it execute the rest of the cURL?

Update:

I think this might be better than the solution below: http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/

Just run two cURL calls using the same object. So first initialize cURL with the homepage URL, and execute the session:

$curl = curl_init("http://example.com");
curl_exec($curl);

Then using the same object, set a new URL, and execute it with your set parameters:

curl_setopt($curl,CURLOPT_URL,"your_new_url");
curl_setopt($curl,CURLOPT_POSTFIELDS,"var1=value&var2=another_value");
curl_exec($curl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM