Issue
I am using the following $_SERVER variables in my include file.
$page_url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$ip_address = $_SERVER['REMOTE_ADDR'];
When I include this file to my PHP script located in the home directory for my Cron jobs, it's throwing errors Undefined array key "HTTP_HOST"
, Undefined array key "REQUEST_URI"
, Undefined array key "REMOTE_ADDR"
to the error_log file.
To avoid this, I want to make this code to show only if the file is in the public_html
directories. How do I say it with PHP if
statement?
Thanks!
Solution
Based on iazaran's response, this code is working for me!
if (strpos(getcwd(), 'public_html') !== false) {
$page_url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$ip_address = $_SERVER['REMOTE_ADDR'];
}
I thought it could be useful for someone like me.
Answered By - Sakkir