简体   繁体   English

if (isset($_GET)) 参数未按预期工作 PHP

[英]if (isset($_GET)) parameter not working as expected PHP

I have this url我有这个 url

http://localhost/example/products.php/full/grains?name_product=rice&refer_url=index-desktop-sidemenu

ON LIVE SERVER SOMETHING LIKE在实时服务器上类似

http:www.example.com/products.php/full/grains?name_product=rice&refer_url=index-desktop-sidemenu

I am trying to check if $_GET["name_product"] is present with if, but it seems not to detect name_product in the URL when its present.我正在尝试检查 $_GET["name_product"] 是否与 if 一起存在,但它似乎没有在 URL 中检测到name_product

This is what I tried.这是我尝试过的。

<?php
if (!empty($_GET["name_product"])){ 
    echo $new_tag = $_GET["name_product"];
    echo "Found";
} else {
    echo "Not found";
}
?>

IT always echo not found even when name_product is in the URL as written above.如上所述,即使 name_product 位于 URL 中,IT 也始终未找到回显。

<?php
if (isset($_GET["name_product"])){  
    echo $new_tag = $_GET["name_product"];
    echo "Found";
} else {
    echo "Not found";
}
?>

Still echo not found even when name_product is in the URL as written above.如上所述,即使 name_product 位于 URL 中,仍然找不到回显。

EDITED: This is my mod rewrite rule已编辑:这是我的 mod 重写规则

 Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^products$ ./products.php
RewriteRule ^index$ ./index.php

RewriteRule ^products/(.*)$ ./products.php?linkcheck=$1&name_product=$2 [NC,L,QSA]

RewriteRule ^404$ ./404.php
RewriteRule ^500$ ./500.php

IndexIgnore *

ADDED products.php to the main file添加 products.php 到主文件

full/grains?name_product=rice where you are using grains? full/grains?name_product=rice您在哪里使用grains? so do you have any .htaccess file, if it exist then you can use like那么你有任何 .htaccess 文件吗,如果存在,那么你可以使用

#RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /grains.php?name_product=$1&refer_url=$2 [L,QSA]

Let me know if it works but this will change the present structure of the url...让我知道它是否有效,但这将改变 url 的当前结构......

I got it to work我让它工作

.htaccess
RewriteRule ^products/(.*)$ ./products.php?name_product=$1&refer_url=$2 [NC,L,QSA]

products.php
if (!empty($_GET["name_product"])){ 
echo $new_tag = $_GET["name_product"];
echo "Found";
} else {
echo "Not found";
}

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

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