cURL Post Succession?

Discussion in 'PHP' started by Supah!, Jan 5, 2009.

  1. #1
    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 :D?
     
    Supah!, Jan 5, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    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.
     
    Danltn, Jan 5, 2009 IP
  3. Supah!

    Supah! Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    That's the thing, I want to check if it was created or, if the username was taken/other error.
     
    Supah!, Jan 5, 2009 IP
  4. infernaliuns

    infernaliuns Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    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...
     
    infernaliuns, Jan 5, 2009 IP
  5. Supah!

    Supah! Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    Supah!, Jan 5, 2009 IP
  6. Th3DarkOn3

    Th3DarkOn3 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    Th3DarkOn3, Jan 5, 2009 IP
  7. Supah!

    Supah! Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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):
     
    Supah!, Jan 5, 2009 IP
  8. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #8
    Just do
    
    if (!strpos($result, 'Sorry, that username is not available')) {
       // sql stuff
    }
    
    PHP:
     
    Kaizoku, Jan 6, 2009 IP
  9. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #9
    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.
     
    Danltn, Jan 6, 2009 IP
  10. Supah!

    Supah! Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Alright, I appreciate it guys :).
     
    Supah!, Jan 8, 2009 IP