This inquiry focuses on logging into Barnes & Noble's mobile website using Curl, while encountering difficulties due to the use of SSL and cookies.
To resolve the issue, consider the following adjustments:
The following code incorporates these adjustments into a working example:
// Constants $EMAIL = '[email protected]'; $PASSWORD = 'yourpassword'; $COOKIE_FILE = "/tmp/cookies.txt"; $LOGIN_URL = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signIn"; $AGENT = "Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)"; // Curl Initialization $ch = curl_init(); // Basic Headers $headers = ["Accept: */*", "Connection: Keep-Alive"]; // Curl Options curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $AGENT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIE_FILE); curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIE_FILE); // Step 1: Initialize with Login URL curl_setopt($ch, CURLOPT_URL, $LOGIN_URL); curl_exec($ch); // Step 2: Extract Form Fields $content = curl_getinfo($ch); $fields = getFormFields($content); // Populate Form Fields $fields['emailAddress'] = $EMAIL; $fields['acctPassword'] = $PASSWORD; // Extract X Value $loginUrl = "https://cart2.barnesandnoble.com/mobileacct/op.asp?x={$x}"; // Construct POST Fields $postFields = http_build_query($fields); // Update Login URL and POST Options curl_setopt($ch, CURLOPT_URL, $loginUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); // Perform Login and Retrieve Result $result = curl_exec($ch); print $result;
For further assistance in using Curl, consider these additional resources:
The above is the detailed content of How to Log into Barnes & Noble's Mobile Website Using Curl, Cookies, and SSL?. For more information, please follow other related articles on the PHP Chinese website!