注意:未定义的索引:HTTP_REFERER

时间:2013-11-14 11:12:47

标签: php indexing undefined http-referer

注意:未定义的索引:HTTP_REFERER

$ http_referer = $ _SERVER ['HTTP_REFERER']

我在教程中使用了它。它看起来没问题

代码也是从包含文件

调用它

我应该改变什么?

我添加了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] => webmaster@movafaghha.memarestan.com 
        [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 
    ) 

编辑了代码,但仍然无法回显所有fiedd是必需的

<?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';
    }

?>

现在添加

之后
  

“e” 的

页面上写着“所有字段都是必需的”

但即使填写所有字段的消息也不会改变

5 个答案:

答案 0 :(得分:50)

HTTP_REFERER不保证由客户发送:

  

将用户代理引用到当前页面的页面地址(如果有)。这是由用户代理设置的。并非所有用户代理都会设置此功能,有些用户可以将HTTP_REFERER修改为功能。简而言之,它无法真正被信任。

在你的情况下,它显然被发送,所以你所能做的就是

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
}

答案 1 :(得分:4)

if (isset($_SERVER['HTTP_REFERER'])) {$THE_REFER=$_SERVER['HTTP_REFERER']}

答案 2 :(得分:0)

正确的方法是

$my_referer = isset($_POST['referer']) ? trim($_POST['referer']) : (isset($_SERVER['HTTP_REFERER']) ? base64_encode($_SERVER['HTTP_REFERER']) : false);

答案 3 :(得分:0)

未定义索引表示未设置数组键,请执行:

var_dump($_POST); die(); 

在抛出错误的行之前,看到您正在尝试获取不存在的数组键。

答案 4 :(得分:0)

HTTP_REFERER也不为我发送,因此我正在使用该组合:

$my_url = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

我使用print_r($_SERVER)来查看可以使用的发送和接收的内容。