Jump to content

URL question...


phpSensei

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.