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;
?>
PHP

Avatar of undefined
Last Comment
m4trix

8/22/2022 - Mon
m4trix

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...
djroh

ASKER
then is there a way to edit http referrer without using curl? and in php only.
m4trix

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
djroh

ASKER
Can you suggest the tool?  I would be grateful.
m4trix

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: example
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/
djroh

ASKER
That would be great for client side.  Any tools to add on to a script on a server side level.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
m4trix

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.