首页 > 解决方案 > php $_GET 和未定义的索引 P

问题描述

我在不同的 PHP 服务器上运行我的脚本时遇到问题,在我的旧服务器上,以下代码似乎工作正常 - 即使声明了 p 参数。

<?php
$ACCESSKEY="demo";
header('Cache-Control: no-cache, must-revalidate');

if($_GET['p']==$ACCESSKEY){
  // this is the workaround for file_get_contents(...)
  require_once (dirname(__FILE__).'/PHP_Compat-1.6.0a3/Compat/Function/file_get_contents.php');
  $data = php_compat_file_get_contents('php://input');

  $filename = $_GET['filename'];
  if (file_put_contents($filename,$data)) {
    if (filesize($filename) != 0) {
      echo "Upload success";
    } else {
      header("HTTP/1.0 400 Bad Request");
      echo "bad request";
    }
  } else {
    header("HTTP/1.0 400 Bad Request");
    echo "failed.";
  }
} else {
  header("HTTP/1.0 400 Bad Request");
  echo "Access denied";    
}

?>

和这样的错误:

Notice: Undefined index: p in C:\xampp\htdocs\upload\index.php on line 5

我该如何解决?谢谢

标签: php

解决方案


推荐阅读