I have a script which uses cURL to post form data to an online game's register page (name not to be mentioned for the sake of ridicule), and it either makes the account if the username is available, or doesn't if it is taken. The problem is, when the script runs I want the username to insert into database if it is successful, not if the username is taken. So any ideas ?
Going to assume it checks whether the account was created or not... If so, then simply branch out if($account_created)-style and use a standard MySQL query ('INSERT INTO...') to add it, if it hasn't been created then it won't be run. Dan.
You will need to get the html response and get a element tag that explain if register was made or not with a regular expression. Appears to be simple...
I've been trying to get the result ($result) from the cURL output, but I cannot read nor store it, but if I print it, it displays but I cannot access any contents.
Make sure you have: curl_setopt ($ch_CurlHandler, CURLOPT_RETURNTRANSFER, 1) Then, when you curl_exec, do it this way: $result = curl_exec($ch_CurlHandler); Then simply: echo "<textarea rows='40' cols='100'>" . htmlspecialchars($result) . "</textarea>"; and you should be able to display/see the results of your curl .... then go through using regex or however you'd like to search for a string telling you whether the name was taken or if it was successfully created.
Eyy thanks mate! It worked. I'm not so good with RegEx so how would i find this string: Sorry, that username is not available. Code (markup):
if (strpos($result, 'Sorry, that username is not available') === false) { // sql stuff } PHP: Is preferred (or !== if you need that.) is recommended, as you can get 0 which evals to (bool) false, but means it's actually in the string.