PHP $ _GET方法不适用于服务器,但适用于本地主机

时间:2018-12-30 09:41:43

标签: php .htaccess bootstrap-4

我遇到GET方法的问题, 我有2个名为index.php和packages.php的页面... index.php生成了POST方法请求,并使用以下代码将值传递给package.php

if(isset($_POST["categorystring"])){
$retval = $_POST["categorystring"];
header("location:packages/category/".php_slug($retval)."");
}elseif(isset($_POST["allpackage"])){
$retval = $_POST["allpackage"];
//var_dump($retval);
header("location:packages/details/all-packages/1");
}

function php_slug($string)  
{  
    list($categoryid, $categoryname) = explode(":",$string);
  $url = strtolower(str_replace(' ', '-', $categoryname))."/".$categoryid;
  $slug = preg_replace('/[^a-z0-9-]+/', '-', trim(strtolower($url)));  
  return $url;  
}

和packages.php的另一面,我正在使用GET检索值为:

if(isset($_GET['categorystring'])) {
  $getstring=$_GET['categorystring'];
  list($stringname, $id) = explode("/",$getstring);
$stringname = str_replace("-"," ",$stringname);
$querystring = "category";

}elseif(isset($_GET['allpackage'])) {
  $getstring =$_GET['allpackage'];
  list($stringname, $id) = explode("/",$getstring);
 $stringname = str_replace("-"," ",$stringname);
$querystring = "allpackages";
}

我的URL是用于package.php

http://localhost/ladakh/packages/category/mountaineering-in-ladakh/2

因为我还使用.htaccess来使PHP成为用户友好的URL

RewriteRule ^packages/category/([a-zA-Z0-9-/]+)?$ packages.php? 
categorystring=$1 [NC,L]
RewriteRule ^packages/details/([a-zA-Z0-9-/]+)?$ packages.php?allpackage=$1 
[NC,L]

它在本地主机上运行良好,但在服务器上不起作用,因为我将服务器上的PHP版本从5.4更改为7.1,但是输出是相同的...

这可能是什么原因????

0 个答案:

没有答案