php 注意:未定义索引:HTTP_REFERER
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19976189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Notice: Undefined index: HTTP_REFERER
提问by Mojtaba
Notice: Undefined index: HTTP_REFERER
注意:未定义索引:HTTP_REFERER
$http_referer = $_SERVER['HTTP_REFERER']
$http_referer = $_SERVER['HTTP_REFERER']
i used this from tutorial.and it looks okay
我从教程中使用了这个。看起来不错
also code is calling it from including file
代码也从包含文件中调用它
what should i change?
我应该改变什么?
i added print_r($_SERVER); and now page gives me this
我添加了 print_r($_SERVER); 现在页面给了我这个
Array ([UNIQUE_ID] => UoSxWa56310AAAwUckIAAAAA
[HTTP_HOST] => movafaghha.com
[HTTP_COOKIE] => __utma=210711305.58608218.1372977010.1372977010.1372977010.1; __utmz=210711305.1372977010.1.1.utmcsr=who.is|utmccn=(referral)|utmcmd=referral|utmcct=/whois/movafaghha.com; PHPSESSID=83eb0e2ae7ebe4b6c2eeb071d9f5de71
[HTTP_X_REAL_IP] => 109.109.41.81
[HTTP_X_FORWARDED_HOST] => movafaghha.com
[HTTP_X_FORWARDED_SERVER] => movafaghha.com
[HTTP_X_FORWARDED_FOR] => 109.109.41.81
[HTTP_CONNECTION] => close
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,fa;q=0.6
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => movafaghha.com
[SERVER_ADDR] => 174.122.223.93
[SERVER_PORT] => 80
[REMOTE_ADDR] => 109.109.41.81
[DOCUMENT_ROOT] => /home/memarest/public_html/movafaghha.com
[SERVER_ADMIN] => [email protected]
[SCRIPT_FILENAME] => /home/memarest/public_html/movafaghha.com/tutorials/login200/register.php
[REMOTE_PORT] => 49737
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.0
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /tutorials/login200/register.php
[SCRIPT_NAME] => /tutorials/login200/register.php
[PHP_SELF] => /tutorials/login200/register.php
[REQUEST_TIME_FLOAT] => 1384427865.54
[REQUEST_TIME] => 1384427865
[argv] => Array ( )
[argc] => 0
)
edited the code but still unable to echo all fiedds are required
编辑了代码但仍然无法回应所有需要的字段
<?php
ini_set("display_errors", true);
error_reporting(E_ALL);
require 'core.inc.php';
if(!loggedIn()) {
//check mikunim ke tamame field ha dar form vojod darand va set shudan
if(isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['password_again'])&&isset($_POST['firstname'])&&isset($_POST['surename'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['password_again'];
$firtsname = $_POST['firstname'];
$surename = $_POST['surename'];
//HALA CHECK MIKUNIM KHALI HASTAND YA NA
if(!empty($username)&&!empty($password)&&!empty($password_again)&&!empty($firstname)&&!empty($surename)){
echo 'ok' ;
} else {
echo ' All fields are required';
}
}
?>
<form action="register.php" method="POST">
Username:<br> <input type="text" name="username"><br> <br>
Password:<br> <input type="password" name="password"><br><br>
Password again:<br> <input type="password" name="password_again"><br><br>
Firstname:<br> <input type="text" name="firstname"><br><br>
Surname:<br> <input type="text" name="surename"><br><br>
<input type="submit" value="register">
</form>
<?php
} elseif (loggedIn()) {
echo 'you \'re already logged in';
}
?>
now after adding
现在添加后
"e"
“电子”
page says "all fields are required"
页面说“所有字段都是必需的”
but even when fill all fields message do not change
但即使填写所有字段消息也不会改变
回答by Stephen Byrne
HTTP_REFERERis not guaranteed to be sent by the client:
HTTP_REFERER不保证由客户端发送:
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
将用户代理引用到当前页面的页面地址(如果有)。这是由用户代理设置的。并不是所有的用户代理都会设置这个,有些提供修改 HTTP_REFERER 的能力作为一个特性。简而言之,它不能真正被信任。
In your case it's clearly notbeing sent, so really all you can do is
在你的情况下,它显然没有被发送,所以你能做的就是
if(isset($_SERVER['HTTP_REFERER'])) {
//do what you need to do here if it's set
}
else
{
//it was not sent, perform your default actions here
}
回答by Mahdi Jazini
if (isset($_SERVER['HTTP_REFERER'])) {$THE_REFER=$_SERVER['HTTP_REFERER']}
回答by rn consulting
The Correct way to reffer is
正确的reffer方法是
$my_referer = isset($_POST['referer']) ? trim($_POST['referer']) : (isset($_SERVER['HTTP_REFERER']) ? base64_encode($_SERVER['HTTP_REFERER']) : false);
回答by ashish
Undefined index means the array key is not set, do a:
未定义索引意味着未设置数组键,请执行以下操作:
var_dump($_POST); die();
before the line that throws the error and see that you're trying to get an array key that does not exist.
在引发错误的行之前,并看到您正在尝试获取不存在的数组键。