help curl headers

Posted on 2006-06-07
Last Modified: 2008-01-16
im trying to open a webpage with a fake ip on my own server for testing my logs in apache access.log
but it still shows my real ip in apaches logs ?

echo file_get_contents_as_mozilla(""); //not a real url

function file_get_contents_as_mozilla($url) {
   // create a new curl resource
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Internet Explorer/6.0 (X11; U; Windows XP SP2; en-US; rv:1.7.2) Gecko/20040804');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept-Language: en-us,en;q=0.7,de-de;q=0.3',
        'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    // close curl resource, and free up system resources

    return $page;

Question by:aot2002
    LVL 10

    Expert Comment

    Why would it be that simple to spoof the ip address?   If you really want to test something in the logs, spoof the UserAgent.  While there are ways to spoof the IP address, there's really no legitimate reason for doing so.  And if I, or anyone else, were to post on here how to do it, it would provide tons of wannabe hackers with details of how to attack websites from a spoofed IP address.
    LVL 1

    Author Comment

    its not simple thats why im asking.
    there is a legitimate reason im testing a custom ip blocking program for my site security...!
    i understand your unsure but lets allow someone else to answer it.

    LVL 10

    Assisted Solution

    Think about your logic for a moment.  The answer to your question would provide people with a means to bypass the same IP blocking you're attempting to test.  Ergo, the solution would foil your system and negate what you're trying to accomplish.  As I said, there's no legitimate reason for doing this.  If you want to test IP blocking software, ask a few friends to help out by giving you their IP address so you can set it up to block them and then see if they get through.  
    LVL 1

    Author Comment

    i found out how it was done thanks anyway i wont post it so it doesnt upset EE rules
    LVL 40

    Accepted Solution

    You didn't actually execute the CURL command.

    You would need something like this BEFORE the curl_close($ch);

    $page = curl_exec();

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    745 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

    14 Experts available now in Live!

    Get 1:1 Help Now