简体   繁体   English

我可以添加什么来获取我的.php脚本中的域值

[英]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 请问如何将域名值打印到下面的php中,请帮忙

 <?
   $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. 您可以使用$ _SERVER超全局的HTTP_HOST属性。 ie $_SERVER['HTTP_HOST'] should give you the domain name or IP address requested. 即$ _SERVER ['HTTP_HOST']应该为您提供所请求的域名或IP地址。 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. 如果您遵循MVC样式模式(所有请求都通过项目根目录的index.php文件),那么您可以使用它来定义域名和项目文件夹的常量,称为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. 这仅适用于Linux,因为Windows将在文件路径的开头添加C:。 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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