Jump to content

Recommended Posts

Usually it would be something like ?num=1 and they'd use $_GET['num'];

I think to get the 1 in the situation you described you'd have to get the url using $_SERVER['REQUEST_URI'] and then a string manipulation function to get the values after the ?

Link to comment
https://forums.phpfreaks.com/topic/66914-url-question/#findComment-335478
Share on other sites

I think you'd go for $_SERVER["QUERY_STRING"] - since this contains only the text after the ?

 

It always seems like an ugly method to me though - as jesirose said, you're better off putting the variable in the URL and retrieving it from the GET array.

Link to comment
https://forums.phpfreaks.com/topic/66914-url-question/#findComment-335482
Share on other sites

You can get them by looping over the $_GET array...

 

http://website.com/index.php?1

 

The above URL has a GET argument called 1 and its value is ''. Try this:

 

<?php

if($_GET) {

    foreach($_GET as $key => $value) {

        echo "Key: " . $key . "<br>";
echo "Value: " . $value . "<br><br>";
    }
}
else {

    echo "No GET arguments supplied";

}
?>

 

Try this script here http://wuhtzu.dk/random/get.php - it will print all the key-value pairs which is supplied in the URL and http://wuhtzu.dk/random/get.php?1 will print 1 as key and '' as value....

 

 

http://wuhtzu.dk/random/get.php?1&2&3

http://wuhtzu.dk/random/get.php?a&b&c

http://wuhtzu.dk/random/get.php?a=1&b&c=3

 

But as jesirose said it is not normal practice to leave out the value of a GET argument ... e.g. index.php?1

 

Link to comment
https://forums.phpfreaks.com/topic/66914-url-question/#findComment-335487
Share on other sites

Usually it would be something like ?num=1 and they'd use $_GET['num'];

I think to get the 1 in the situation you described you'd have to get the url using $_SERVER['REQUEST_URI'] and then a string manipulation function to get the values after the ?

 

I used explode and got the values after the "?"...

 

I call this method junk, and thats my opinion. I always use the other method, and its better off like you guys said to get it off the variable...

Link to comment
https://forums.phpfreaks.com/topic/66914-url-question/#findComment-335633
Share on other sites

You can get them by looping over the $_GET array...

 

http://website.com/index.php?1

 

The above URL has a GET argument called 1 and its value is ''. Try this:

 

<?php

if($_GET) {

    foreach($_GET as $key => $value) {

        echo "Key: " . $key . "<br>";
echo "Value: " . $value . "<br><br>";
    }
}
else {

    echo "No GET arguments supplied";

}
?>

 

Try this script here http://wuhtzu.dk/random/get.php - it will print all the key-value pairs which is supplied in the URL and http://wuhtzu.dk/random/get.php?1 will print 1 as key and '' as value....

 

 

http://wuhtzu.dk/random/get.php?1&2&3

http://wuhtzu.dk/random/get.php?a&b&c

http://wuhtzu.dk/random/get.php?a=1&b&c=3

 

But as jesirose said it is not normal practice to leave out the value of a GET argument ... e.g. index.php?1

 

 

also, thankyou for your explanation, everything is clear now.

Link to comment
https://forums.phpfreaks.com/topic/66914-url-question/#findComment-335636
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.