Link to home
Start Free TrialLog in
Avatar of djroh
djroh

asked on

php curl script

I'm using a script to edit the referrer which works but somehow the client ip is not being preserved and the server ip where the php code is hosted become seen as the client ip.  Am I missing something?  

<?php
$url_page = "http://www.google.com";
$user_agent = "Mozilla/4.0";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url_page);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.example.com/index.html');

$string = curl_exec($ch);
header("Content-type: ".curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
curl_close($ch);
echo $string;
?>
Avatar of m4trix
m4trix
Flag of Canada image

Because CURL is being executed on the server, the server IP is what will show up on the destination server. I don't believe there is a way around that...
Avatar of djroh
djroh

ASKER

then is there a way to edit http referrer without using curl? and in php only.
What exactly are you trying to do? Are you trying to visit a website (yourself) and have it see a different http referrer? You can create a new HTTP request in PHP (and CURL is the easiest way to do that) with whatever HTTP_REFERER you would like in it - but the request will always originate from the server that the PHP is running on. If you're trying to access a site yourself and "trick" it into seeing a different HTTP_REFERER, then the simple answer is that no, you cannot use PHP to alter your request headers. There ARE tools that will do that however
Avatar of djroh

ASKER

Can you suggest the tool?  I would be grateful.
It's not super easy to do, and requires a little bit of manual work, but I'd give Live HTTP Headers (for firefox) a try first:
http://livehttpheaders.mozdev.org/

Install, enable via Tools -> Live HTTP Headers
leave the window that pops up open while you browse to whatever site you wanted to visit. Go to back to the pop up window and you'll see all the HTTP requests. Scroll to the one you want, select a row in it and click the "Replay" button. There you can manually type in your own headers and resubmit.

example: User generated image
If you know you'll be using the same referer a lot, I'd suggest trying this firefox addon:
https://addons.mozilla.org/en-us/firefox/addon/modify-headers/
Avatar of djroh

ASKER

That would be great for client side.  Any tools to add on to a script on a server side level.
ASKER CERTIFIED SOLUTION
Avatar of m4trix
m4trix
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial