How to use proxy with PHP?

Posted on 2004-11-10
Last Modified: 2011-10-03

I want to develop a php program to get information from the website and store them in the local database. The difficulties here is that I am in the internal web, and the machine host my program can only access the internet by proxy. So how can I use php programming to access the internet through the proxy server?

Thank you.
Question by:mryyzx
    LVL 48

    Accepted Solution

    That will only work with the curl-module. Via the normal PHP-function like fopen fget_content, ..there is no support for proxy. For curl see
    LVL 3

    Assisted Solution

    on the contrary, you can do whatever you'd like. use fsockopen to negotiate your proxy.

    you'll basically need something like this:
    $fp = fsockopen ("", 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br>\n";
    } else {
        fputs ($fp, "GET HTTP/1.0\r\n\r\n");
        while (!feof($fp)) {
            echo fgets ($fp,128);
        fclose ($fp);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now