Torrie Posted May 19, 2017 Share Posted May 19, 2017 There's a website that does NOT use cookies and does NOT use javascript. When I log in, I get an html page with a single form input. Hidden in the source code, there's also a random number that gets generated with every page reload (I'll call that a "security token"). Using a regular web browser, I type in my product barcode into the form input and the website will return the item "size" and item "weight." PROBLEM: When I replicate browser input using CURL, the website only returns the item size! (The html table where the item "weight" should appear is MISSING when I use CURL). In trying to solve this myself, I discovered that Google Chrome has a nifty tool in the "Network" tab called "Copy As CURL" which goes something like this: I visit the website using Google Chrome browser, input my product barcode, and the website returns the "size" and "weight." I then use Google Chrome's "Copy as CURL" and now I've got a CURL script. Obviously, I use substitute some of the script with a bit of php code to retrieve and repost the randomly generated "security token." But it never works. The code IS successful at retrieving the "security token" because when that is unsuccessful, I get an error page. So I know at least the "security token" part of the CURL code works. However, the CURL code only returns the "size" and NOT the item "weight." Here's the code: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://www.website.com/index.html?user=username&pass=password'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/601.7.0 (KHTML, like Gecko) Version/9.0.1'); // visits website, get the Security Token:$result = curl_exec($ch); preg_match('/ControlNumber\"\svalue=\"(.*)\"/',$result,$number); $token = $number[1]; // with Security Token in hand, now posts the variables just as I would do using a web browser:curl_setopt($ch, CURLOPT_POSTFIELDS, array('controlNumber'=>$token,'inputname1'=>"productNumber",'javascript'=>'none')); $websiteResponse = curl_exec($ch); // The following var_dump only returns the product "size" and NOT the product "weight"var_dump($websiteResponse); ?> Please, would anyone know what I'm doing wrong? The problem is that CURL returns a different page than a web browser does. Quote Link to comment Share on other sites More sharing options...
Torrie Posted May 20, 2017 Author Share Posted May 20, 2017 Zero views? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.