curiousmike Posted January 4, 2012 Share Posted January 4, 2012 A couple months back, I asked on a gaming forum if anyone knew of a website that would track your *Steam Wishlist and email you when one of your wishlist games went on sale. No one at the time knew of a **solution, so I decided to buy "PHP, MySQL and Javascript" and try to roll my own. I managed to get the basics working. After the basics, I started thinking about fun stuff I could do with the data I collected from Steam regarding the games that go on sale regularly. The first part of my code file_get_content's the ***sale page(s) of games, and sucks out the games name, regular price, sale price, and the games homepage URL on Steam. This is enough to accomplish my basic task. The second part is where I need help, and that's getting more details on the game. The additional details I want to get about the game include its Publisher and Developer, and to get that detail I need to go to the games homepage URL I previously got from the global sale page. The issue is this: Some games have an age-restriction limitation, and you have to fill out a date form before entering the games homepage. An example of one of those pages would be: http://store.steampowered.com/agecheck/app/1250/ I want to be able to POST a legal age to the above URL, and then (this is where I'm hazy) "re-load" the same URL, authorized by my previous POST. Is that possible? * Steam is a digital download service for computer games. ** Subsequently, there was another website found. But I was well into developing my solution and having fun. *** Example: http://store.steampowered.com/search/?specials=1 Quote Link to comment https://forums.phpfreaks.com/topic/254320-newb-post-to-a-remote-url-form-help/ Share on other sites More sharing options...
doddsey_65 Posted January 4, 2012 Share Posted January 4, 2012 you could send post data with CURL and grab the content of the page that way. Eg: $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, 'http://the-website-here'); curl_setopt($ch,CURLOPT_POSTFIELDS,'age-post-options); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); The post options would be something like dob_day=11&dob_month=11&dob_year=1986 This will return the content of the page into the $result variable. You need to have the CURL module installed and active for this to work. Quote Link to comment https://forums.phpfreaks.com/topic/254320-newb-post-to-a-remote-url-form-help/#findComment-1304061 Share on other sites More sharing options...
curiousmike Posted January 5, 2012 Author Share Posted January 5, 2012 Thanks for the suggestion; the curl_exec is giving me an error. It appears the return code is 302 ([http_code] => 302), which Wikipedia tells me is a redirect. I'm completely lost at this point; is curl telling me it succeeded, but fails because of the redirect(?) Isn't the re-direct what I want? <?php $ch = curl_init(); if ($ch) { $bOK = false; $bOK = curl_setopt($ch,CURLOPT_URL, 'http://store.steampowered.com/agecheck/app/1250/'); //$bOK = curl_setopt($ch,CURLOPT_URL, 'http://store.steampowered.com/app/1250/'); if (!$bOK) echo ("error 1<br>"); $bOK = curl_setopt($ch,CURLOPT_POSTFIELDS,'ageDay=1&ageMonth=1&ageYear=1992'); if (!$bOK) echo ("error 2<br>"); $bOK = curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); if (!$bOK) echo ("error 3<br>"); $bOK = curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); if (!$bOK) echo ("error 4<br>"); $result = curl_exec($ch); if ($result) { echo ("got something<br>"); } else { print_r(curl_getinfo($ch)); } curl_close($ch); } else { echo ('error initing curl<br>'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254320-newb-post-to-a-remote-url-form-help/#findComment-1304389 Share on other sites More sharing options...
curiousmike Posted January 5, 2012 Author Share Posted January 5, 2012 I've done some quick reading on curl redirects, and tried a few examples posted by users in the official PHP docs. None have worked. I've gotten further, with a valid response... but the valid response is the age-verification page again. I'm unsure that me POSTing the values is "sticking." $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, 'http://store.steampowered.com/agecheck/app/1250/'); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,'ageDay=1&ageMonth=1&ageYear=1992'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $myPage = curl_exec($ch); if ($myPage) { echo ('success<br>'); // This is happening, and echoing "myPage" results in the age-restricted page coming up echo ($myPage); } else echo ('fail<br>'); Quote Link to comment https://forums.phpfreaks.com/topic/254320-newb-post-to-a-remote-url-form-help/#findComment-1304397 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.