Jump to content

URL question...


phpSensei

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