Results 1 to 8 of 8

Thread: Random Proxy in PHP

  1. #1
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Random Proxy in PHP

    Hello.
    I am looking for a PHP code that selects a random proxy between almost 400 proxys, and it intercepts in a webpage.
    Lets say that if i put http://www.whatsmyip.org/ as the url of the page that i want the php to intercept, it must show the ip of the proxy.
    I've heard that the function must be curl but i dont know what does this means...

    Can someone help me?

    Thanks.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    What? I really don't follow how that would work. When you say "put the URL" you mean in a form, or in the address bar?

    I think you may be looking at proxies backwards. You go to the proxy then enter the URL you want to go to, rather than the other way around of going to the site and then using a proxy.

    Look at php.net for more info on curl if you want to try that.
    http://php.net/manual/en/book.curl.php

    It's not particularly easy, but it could work.

    Alternatively if you have remote files enabled in your PHP configuration you could just use include() to bring in the content of another page.

    But running a proxy through your server actually means you'd have two levels of proxy-- one is your site and the other is the proxy.

    Proxies are usually useful for either:
    1) Viewing blocked websites from an internet connection.
    2) Hiding your actual browsing activity from anyone who may be watching (on the network or at the other end).
    (Both of which may be used for good or evil, I suppose.)

    I'm not sure how your plan will help with either (1) or (2).

    Secondly, if you use your server as the hub for all of this, then I imagine that proxy sites will start blocking its IP very quickly due to overuse. Every person who visits your site will be going through your server's IP and then that IP will be requesting every document from these proxies. Many of them have limits per user (which in this case would be identical for all of your users-- your server's IP). You're creating a bottleneck that is a little counterproductive, as I see it.


    A simple alternative to all of this is to have a form with a URL input and a submit button that takes you to a random proxy when you click submit. That's just a redirect and would be much easier and in the end much more effective. But sites already exist like that, so I don't know if you'd gain much by doing it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hello, thank you very much for your answer.
    What i really want is to visit a same webpage with different proxy.
    I dont want to click 'submit' or 'go' or any button, i want that when the page loads, it loads a webpage with a random proxy of the list that i have made in the php.
    By saying 'put url' i mean in the php code.

    An example could be this, but i prefer to forget this code because it does not works.
    In the Bolds:
    1. There is the list of the proxys.
    2. The url of the webpage i want the php to intercept with a random proxy.

    <?php
    function get_random_proxy(){
    srand ((double)microtime()*1000000);
    $f_contents = file ("http://www.myweb.com/proxys.txt");
    $line = $f_contents[array_rand ($f_contents)];
    return $line;
    }

    function get_curl_proxy($url){

    $proxy_ip = get_random_proxy();

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
    }

    $u="http://whatsmyip.org/";

    echo get_curl_proxy($u);
    ?>
    So, how can i do this? As i said, this code does not work for me...
    I am literally a noob in php... and i need this, please.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    I'm still entirely missing what the purpose of this is. Why build a proxy (that's what you're building!) that uses other proxies for the information? I just don't get it. And I think it will cause you to run into problems in the end with how it will work.

    curl() is fine. So is include() if you allow remote files.

    Your code seems fine (at least as an approach-- I haven't tested it).


    What i really want is to visit a same webpage with different proxy.
    I dont want to click 'submit' or 'go' or any button, i want that when the page loads, it loads a webpage with a random proxy of the list that i have made in the php.
    By saying 'put url' i mean in the php code.
    So you only want one URL then?


    Now... to the extent that I do understand what you might be doing:
    $u="http://whatsmyip.org/";
    It looks like you may be attempting to violate the terms of service of various proxies by figuring out which IPs they use, and so forth, or possibly to attempt to circumvent either the IP detection website's usage limits, or the proxies' usage limits.
    Any type of request/question that is a violation of the TOS of another website or potentially illegal is strictly not answered here.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Code:
    $u="http://whatsmyip.org/";
    That is only to know if the PHP code is working, otherwise, if i dont link to a webpage to know my IP direction, how could i know if it the php proxy code is working?

    So you only want one URL then?
    Yes, only one url.

    The purpose is to know the real stabilty of a stream server along with different countries visits, but i havent put the stream server in the .php file.

    Could you please use the code and see what's missing? I would be very grateful.
    Thanks.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    That is only to know if the PHP code is working, otherwise, if i dont link to a webpage to know my IP direction, how could i know if it the php proxy code is working?
    Ok, fair enough. But you could do this yourself quite easily in PHP and create a page on your own server. It would be easy and eliminate any possible problems with their limits on the number of requests you can make. You just need this code:
    PHP Code:
    <?php echo $_SERVER['REMOTE_ADDR']; ?>
    (And call that ip.php or whatever you want; use that as your URL and it should work for you.)

    The purpose is to know the real stabilty of a stream server along with different countries visits, but i havent put the stream server in the .php file.
    Oh, here's where it gets tricky. Are you testing media, beyond just HTML (text)? curl() is going to do much for you for any additional elements (even images) being loaded on the page. A full proxy can do this, but you're just grabbing content and effectively pasting the HTML into your current document. It will work for HTML, but not beyond that.

    You'll have to truly build a proxy (probably not in PHP, at the server level instead-- some kind of proxy server, although I don't know the details) to make that really work if you need things like Flash, or even just images to work as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ok, i have made the ip.php
    Well, i put an embed code made of html, flash, etc. But i want to test how many views it can support or how many from which country, etc.
    So what would i need to do in the php code?
    Thanks for your answers.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    You really can't do this, at least not at your level of PHP (or honestly mine). You could do this another way, but PHP is not the right answer.

    You'd need a full proxy server which means that any request is rerouted automatically to the other site.

    What you'd need to do is rewrite the HTML as you go so that the link/href properties of all links and CSS files and Flash embeds and images and whatever else all go to your site. Then you would need to design your proxy to be able to handle requests for content other than html. That's easy enough (well, somewhat difficult, but very possible) with certain file types like CSS or JS, or even images, because PHP has built in ways to do this. But beyond that, once you start doing something like video or plugins like Flash, PHP simply isn't equipped to deal with it. I suppose you could in theory literally expand the capabilities of PHP, but that won't be a practical solution.

    Does that make sense?

    So either look for some proxy server software to us as-is, or don't approach it this way. Here are two alternatives:
    1. Limit the type of files you may deal with, as just a test of speed. So use images (as an example) and maybe use images that are 1mb (very large, good to test for limits). Then run what you're doing (which is still difficult, but possible).
    2. Find some existing site testing software. That's strongly my recommendation here. There are probably services out there that will do all of this for you and tell you how well your website holds up to stress and lots of traffic.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Similar Threads

  1. making a proxy
    By bluewalrus in forum PHP
    Replies: 2
    Last Post: 07-08-2010, 12:51 PM
  2. proxy server
    By amyy in forum Other
    Replies: 1
    Last Post: 08-07-2008, 06:53 PM
  3. CGI Proxy
    By SVTcontourSVT in forum PHP
    Replies: 2
    Last Post: 11-29-2007, 02:53 AM
  4. Why Proxy
    By jass in forum Other
    Replies: 8
    Last Post: 07-23-2007, 06:58 AM
  5. javascript proxy
    By lainlives in forum JavaScript
    Replies: 7
    Last Post: 10-27-2006, 07:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •