3

I'm looking to detect the $_GET variable name. What I'm trying to detect is:

index.php?login (detect login)
index.php?news (detect news)

I've looked all over and I can't seem to find anyone who has requested this. I'm not looking to detect the value of the variable just that the specific variable exists with no value and if there is a value it is an error. I really appreciate any help.

EDIT: Thanks to a little detective work with the help of zerkms I was able to determine it was being pass through QUERY_STRING so I sent it to a variable through $_SERVER['QUERY_STRING'];

Thank you everyone!

Sergey Kuryanov
  • 6,114
  • 30
  • 52
Ambiguities
  • 415
  • 6
  • 18

3 Answers3

2

Try this

if (isset($_GET['yourvar']) && !strlen($_GET['yourvar']))
    echo "param is set with no value";
fuzic
  • 2,492
  • 16
  • 22
  • funnily enough using zerkms comment i discovered that it is being passed through QUERY_STRING so I used that in the form of $_SERVER['QUERY_STRING']; to save the request into a variable. – Ambiguities Mar 12 '13 at 02:39
0

If requested URL is like, "/test.php?login"

 if(!empty($_SERVER['QUERY_STRING'])) {
    if($_SERVER['QUERY_STRING'] == "login"){
       //do some login thing
    }
 }
sk8terboi87 ツ
  • 3,396
  • 3
  • 34
  • 45
-2

To get the vars and print them, you can utilize the following code:

echo '<pre>';    
print_r($_GET);
echo '</pre>';
Perception
  • 79,279
  • 19
  • 185
  • 195
user888300
  • 83
  • 10