My website hosts a PDF file www.abc.com/abc/xyz.pdf - where if some one opens this link in browser they get the PDF.
I need to write/implement a PHP script before opening the PDF, which checks the IP address of the user who is requesting the PDF file against IP addresses that are available in an array.
The PHP script should run in background or something. As my users will click directly on the pdf link and that PHP validation script needs to be executed and redirect accordingly.
Any help in validating these users is appreciated.
$ips = array('127.0.0.1', '34.43.43.12');
if(!in_array($_SERVER['REMOTE_ADDR'], $ips))
{
echo 'no access';
}
else
{
//access
header('Content-type: application/pdf');
readfile('file.pdf'); //change location to your file
}
You could find this code. Try do some research before posting a question next time.
Use this to get IP of client system : $_SERVER['REMOTE_ADDR']