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!

2
  • var_dump($_SERVER); Commented Mar 12, 2013 at 2:33
  • It's not called the "$_GET variable name", it's called the "query string". That should help you find relevant results. Commented Mar 12, 2013 at 2:39

3 Answers 3

2

Try this

if (isset($_GET['yourvar']) && !strlen($_GET['yourvar']))
    echo "param is set with no value";
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

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

 if(!empty($_SERVER['QUERY_STRING'])) {
    if($_SERVER['QUERY_STRING'] == "login"){
       //do some login thing
    }
 }

Comments

-2

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

echo '<pre>';    
print_r($_GET);
echo '</pre>';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.