using cURL to grab captchas and display it to users?

Discussion in 'PHP' started by BlackPropeller, Apr 5, 2011.

  1. #1
    Hey,
    I've been trying to figure this one out for the last 3 days...but no luck.

    Basically, I scrape YouTube Video ID's and i sometimes get hit with captchas due to "excessive traffic coming from my network". I would like that captcha to be passed thru and shown to that website visitor, who would need to enter that captcha and submit it on my site, and php will use sessions to submit the captcha on youtube's page.


    Can this be done using PHP and cURL?
    Any other suggestions will be appreciated.
    :)
     
    BlackPropeller, Apr 5, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Yes it can. Use cURL to grab the page contents, if you detect a captcha, retrieve the captcha image URL (simple parsing), and then use curl to download it to the local hard disk, and then show to the user. Alternatively, you may be able to use output the image using the URL on Youtube directly on to the page, but I have no knowledge as to how exactly Youtube manages it's Captcha. I'm guessing they would just use reCaptcha.
     
    Alex Roxon, Apr 6, 2011 IP
  3. BlackPropeller

    BlackPropeller Greenhorn

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks Alex!

    Here's the captcha on youtube's page: http://www.youtube.com/das_captcha

    I'm not sure how the image downloading would work.
    Do I need to create a session, or a cookie?
    If I download the image (aka access the captcha page) and display it to the visitor, they enter the letters and hit submit on my page, the server would try to submit the form but when it is submitted or makes another request to submit the page won't another image/captcha be displayed? or would I have to keep the captcha session open until the user enters the captcha?
     
    BlackPropeller, Apr 6, 2011 IP
  4. SametAras

    SametAras Well-Known Member

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    113
    #4
    You can't do this with PHP. It's impossible in my opinion. :)
     
    SametAras, Apr 6, 2011 IP
  5. BlackPropeller

    BlackPropeller Greenhorn

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    @SametAras, do you have any other ideas then? could I do it via some other web-dev. language?
     
    BlackPropeller, Apr 6, 2011 IP
  6. SametAras

    SametAras Well-Known Member

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    113
    #6
    Unfortunately, I haven't got any idea in this topic. Maybe this is useful to you: http://decaptcher.com/client/ (I don't know that support to Youtube Captcha.)
     
    SametAras, Apr 6, 2011 IP
  7. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You would need to look into how the Captcha actually works with each of the sites, there must be some method each site is using to identify the post back be it a sessionID in a cookie or hidden field or something similar.

    With your postback to them with the user input you would need to ensure that the identifiers are also there/ available.

    We don't use PHP so cannot comment on cURL specifically but I would be surprised if PHP didn't have this sort of functionality available
     
    AstarothSolutions, Apr 6, 2011 IP
  8. ama

    ama Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    It should be doable provided you send exactly the same post and header info as YouTube are expecting.
     
    ama, Apr 6, 2011 IP
  9. ngcoders

    ngcoders Active Member

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #9
    It is doable and had been doing it for last 2 years. Though requires some Smart coding ... not recommend for new comers.

    There is a lot more to it :) , You tube has recently changed security stuff added a token and now somehow a simply proxying with correct code gives Authorization Error.

    Anyhow i am too working on this , with not much luck ... my earlier version worked fine , but new one somehow is not working .
     
    ngcoders, Apr 6, 2011 IP
  10. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #10
    This is so simple, don't even listen to the people who say otherwise, they have no idea how it works.

    Easy - use PHP to grab the page contents, if you can detect the captcha, simply use curl to download it (retrieve the URL, send the curl request to that url, and saved the returned file as image.gif). Then output image.gif to the user. You'll need to configure curl to properly handle cookies - most of the time these captchas are session based, and the session id is returned in the form a cookie. When the user submits the captcha text, submit the HTTP request to the server with the captcha value (making sure you send the same cookie).

    There's no reason it won't work. You're mimicking a browser. Paypal won't have anything in place to block it, as you're not doing anything out of the ordinary.
     
    Alex Roxon, Apr 7, 2011 IP