freaksville Posted November 29, 2009 Share Posted November 29, 2009 Hey, I'm a bit of a php n00b and was woundering if anyone could tell me how I can tell my php code to differ depending on what is at the end of the address. (e.g. image.php and image.php?=blue) The reason I want to know is that I have created a countdown to Christmas image (http://count.suprscribble.com/christmas/) and want people to be able to change the background colour depending on what extension of the address they use. Thanks in Advance Brad Quote Link to comment https://forums.phpfreaks.com/topic/183314-php/ Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 You can get values from the query string using the $_GET superglobal. somepage.php?var=something would be accessed like so: echo $_GET['var']; // Something Quote Link to comment https://forums.phpfreaks.com/topic/183314-php/#findComment-967608 Share on other sites More sharing options...
freaksville Posted November 29, 2009 Author Share Posted November 29, 2009 http://count.superscribble.com/christmas/ <- correct link I don't quite understand still. How can I use that to change the output, would I use an if function or something? Quote Link to comment https://forums.phpfreaks.com/topic/183314-php/#findComment-967613 Share on other sites More sharing options...
JAY6390 Posted November 29, 2009 Share Posted November 29, 2009 switch($_GET['var']) { case 'x': // if you have ?var=x then the code here will run break; case 'abc': // if you have ?var=abc then the code here will run break; default: // The default is not required, but code here will run if all of the above case statements aren't matched // (ie var isnt x or abc in this case break; } You could also do the same with an if elseif and else statement if($_GET['var'] == 'x') { // if you have ?var=x then the code here will run }elseif($_GET['var'] == 'abc') { // if you have ?var=abc then the code here will run }else{ // Same as default above } Hope that gives you some help Quote Link to comment https://forums.phpfreaks.com/topic/183314-php/#findComment-967615 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.