if (isset($_GET)) parameter not working as expected PHP
Get the solution ↓↓↓I have this 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 detectname_product
in the URL when its present.
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.
<?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.
EDITED: This is my mod rewrite rule
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
Answer
Solution:
full/grains?name_product=rice
where you are usinggrains?
so do you have any .htaccess file, if it exist then you can use like
#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...
Answer
Solution:
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";
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: too few arguments to function laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.