ShaolinF Posted July 9, 2007 Share Posted July 9, 2007 Hi Guys, I've always wondered how people do this but on the end of URLs of php sites I find these random digits like id=23?e102 etc. How do they do that ? I've never really managed to figure out how to do that. Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/ Share on other sites More sharing options...
trq Posted July 9, 2007 Share Posted July 9, 2007 <a href="foo.php?var=12543">link</a> foo.php <?php if (isset($_GET['var'])) { echo $_GET['var']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-293912 Share on other sites More sharing options...
cooldude832 Posted July 9, 2007 Share Posted July 9, 2007 They are called GET variables and are created in a multiple of ways. First a form can be processed via get and list all input values in the url in the fashion of key=value&key2=value2. Secondly they can be created from hyperlinks a big advantage to using them because you can create a link that has 1 page to a dynamic content. (like a photo gallery the id could be which image to display). The final way is they can mainipulated by the user to make it what they want. A danger to them for they could get info out of your mysql you don't want so be careful and only use when needed. Fyi they also help with SEO because many serach engine can follow GET where POST/SESSIONs fail Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-293916 Share on other sites More sharing options...
teng84 Posted July 9, 2007 Share Posted July 9, 2007 what are you asking the randomizing or the query string $id=rand(10,100); <a href="foo.php?var=".$id> Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-293917 Share on other sites More sharing options...
ShaolinF Posted July 11, 2007 Author Share Posted July 11, 2007 Thanks Guys. This is cool stuff. Can you guys give me an example of this in action ? Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-295399 Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 www.google.com Do a search. Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-295402 Share on other sites More sharing options...
Psycho Posted July 11, 2007 Share Posted July 11, 2007 Create two pages as follows (left out the basic HTML): page1.php: <a href="page2.php?value=A">Value A</a> <a href="page2.php?value=B">Value B</a> page2.php: <?php if (isset($_GET['value'])) { echo "You clicked Value $_GET['value']"; } else { echo "You didn't click one of the links on page1!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-295418 Share on other sites More sharing options...
ShaolinF Posted July 12, 2007 Author Share Posted July 12, 2007 Oh I see. So basically you can have dozens of links in your html and they all link to an IF statement in php file. Quite straight forward. So what does the isset mean ? All the answers I have come across are too complicated. Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-296482 Share on other sites More sharing options...
per1os Posted July 12, 2007 Share Posted July 12, 2007 www.php.net/isset It checks if a variable has been set or not. Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-296485 Share on other sites More sharing options...
LiamProductions Posted July 12, 2007 Share Posted July 12, 2007 That is easy stuff, Use your best friend Google Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-296500 Share on other sites More sharing options...
Psycho Posted July 12, 2007 Share Posted July 12, 2007 Oh I see. So basically you can have dozens of links in your html and they all link to an IF statement in php file. Quite straight forward. Not sure if you really get it. The links do not link to an if statement. The links simply link to a page AND include variables and their values within that link. The page that is being linked to can access those values using $_GET[variablename] So, when using this link www.mypage.com/index.php?val1=a&val2=b the page index.php would have two variable available to it: $_GET['val1'] would equal 'a' $_GET['val2 would equal 'b Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-296594 Share on other sites More sharing options...
ShaolinF Posted July 13, 2007 Author Share Posted July 13, 2007 Oh I see. So basically you can have dozens of links in your html and they all link to an IF statement in php file. Quite straight forward. Not sure if you really get it. The links do not link to an if statement. The links simply link to a page AND include variables and their values within that link. The page that is being linked to can access those values using $_GET[variablename] So, when using this link www.mypage.com/index.php?val1=a&val2=b the page index.php would have two variable available to it: $_GET['val1'] would equal 'a' $_GET['val2 would equal 'b Thanks, very informative. What if I had the following links: <a href="page2.php?value=A">Value A</a> <a href="page2.php?value=B">Value B</a> When I click and it takes me to the IF statement, I want be able to differ between the value contained. For example, if 'value' is 'A' then echo A, whereas if 'value' is 'B' then echo b. Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-297764 Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 switch($_GET['value']) { case 'a': echo 'this is teng'; break; case 'b': echo 'this is teng again'; break; //optional default: echo 'hi im teng'; break; } Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-297771 Share on other sites More sharing options...
ShaolinF Posted July 14, 2007 Author Share Posted July 14, 2007 Ah good ol case. Thanks. what if I used the rand function to create random integers. How would I detect it in the php file ? Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-298184 Share on other sites More sharing options...
pyrodude Posted July 14, 2007 Share Posted July 14, 2007 This would be an easy example of a randnum.php file using $_GET and random numbers: <?php if (isset($_GET[randnum])) { $rand2 = rand(0,100); $message = "Your random number was $_GET[randnum]<br><br>To get a new one, click <a href=\"randnum.php?randnum=$rand2\">here</a>"; } else { $randnum = rand(0,100); $message = "You do not have a random number =(<br><br>To get a random number, click <a href=\"randnum.php?randnum=$randnum\">here</a>"; } ?> <html> <head><title>Random number!</title></head> <body> <?=$message?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/59170-url-endings/#findComment-298286 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.