// remote.php on http://www.example.com/
<?php
function curl_access()
{ /*
some codes here to detect
this script accessed via
curl or direct and returns $r.
(without checking referrer or user agent)
*/
return $r;
}
$curl_access = curl_access();
if ($curl_access)
{ echo 'Accessed via CURL';
} else
{ echo 'Direct access';
}
?>
// some file on a server
<?php
$h = curl_init();
curl_setopt($c, CURLOPT_URL, "http://www.example.com/remote.php");
curl_exec($c); // returns 'Accessed via CURL'
curl_close($c);
?>
Asked
Active
Viewed 3,471 times
0

user875335
- 11
- 1
- 3
-
Related: http://stackoverflow.com/questions/2705394/how-can-i-prevent-my-asp-net-site-from-being-screen-scraped – karim79 Aug 20 '11 at 06:24
3 Answers
7
You can't. An HTTP request is an HTTP request, and you've ruled out the obvious distinguishing characteristic of a request made by a browser (the contents of the user-agent header).

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
The user may use: curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); – user875335 Aug 20 '11 at 06:34
-
Yes, you can't work around deliberate attempts to pretend to be a browser, but an HTTP request is still an HTTP request. – Quentin Aug 20 '11 at 06:36
1
Since curl work as like any browser, so it is difficult to detect that is man or machine. For that first of all, you can
1.print $_SERVER php variable
2.json_encode this variable
3.put in a database field named server information
4.then browse this site one time
5.and curl execute for this same URL
6.then print both information
Here you can see some different issue. I have found different terms HTTP_COOKIE which not exist in curl request information.
So you can detect
if (!isset($_SERVER['HTTP_COOKIE'])) {
die('Opps! I think, your request is not proper way. Please contact');
}
I think that will be very helpful who want to protect data scrapt from his/her website.

Saidul Haque
- 606
- 7
- 11
0
You can check the visitor's user agent by
_SERVER['HTTP_USER_AGENT']
note that it can be modified when using curl with the -A flag.

Blux
- 196
- 1
- 6
-
The user may use: curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); – user875335 Aug 20 '11 at 06:37