restricting access to a php script, so it can only be called by particular domain.

Can you restrict access to a php script?
Would like to set it up so:\myscript.php can only be called from:

1. webpage served by
2. fsockopen from

Is it possible?  
Thank you.  
Who is Participating?
you should be able to use htaccess to allow only domain1.
You can use this code to check that the script is called from a particular IP address. I think that placing this at the head of your script should do what you want:

if($_SERVER['REMOTE_ADDR'] != $valid_ip)
mtnr, are you still monitoring this question? Both answers you've received can do the trick. It's just a question of how and where you want to deploy the solution.
By the way, for either of these solutions to work, you must serve up a php webpage on domain2 by using code like this:

echo file_get_contents('');

or open a socket like this:

$fp = fsockopen('', 80);
$header = "GET myscript.php HTTP/1.1\r\n";
$header .= "Host:\r\n";
$header .= "Accept: */*\r\n";
fwrite($fp, $header);
while (!feof($fp)) {
  echo fread($fp, 8192);
mtnrAuthor Commented:
very good answers, thank u!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.