mike1313 Posted December 23, 2007 Share Posted December 23, 2007 So on one of my pages I use $_GET to display various contents depending. For ex. <?php if(!$_GET[per]){ echo "Main Page Content"; } So basically what I want to try and do is say the users clicks on the URL bar and the filename is page.php?per=find. If anyone types in the url bar and changes the find to like page.php?per=hello it would display some of the page but it would be blank mostly. Is there a certain way to stop this or let me display a message. If a $_GET varaible is used but isn't defined in the pages code? Quote Link to comment https://forums.phpfreaks.com/topic/82899-help-with-using-get/ Share on other sites More sharing options...
Daniel0 Posted December 23, 2007 Share Posted December 23, 2007 You could use a switch: <?php switch($_GET['per']) { case 'a': // do something break; case 'b': // do something else break; default: // if nothing else matches break; } ?> Or you could define an array of pages: <?php $pages = array('a', 'b', 'home', 'something', 'test'); if(isset($_GET['per']) && !in_array($_GET['per'], $pages)) { echo 'invalid page'; } else { echo 'valid page'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82899-help-with-using-get/#findComment-421612 Share on other sites More sharing options...
eRott Posted December 23, 2007 Share Posted December 23, 2007 Just use an else statement to echo some result of a non-defined variable. page.php?per=find would result in "Option 1" page.php?per=hello would result in "Option 2" page.php?per=test would result in "Option 3" page.php?per=OMG IM HACKING YOUR WEBSITE would result in "Option 4" <?php $page = $_GET['per']; if ($page == "find") { echo "Option 1"; } elseif ($page == "hello") { echo "Option 2"; } elseif ($page == "test") { echo "Option 3"; } else { echo "Option 4"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82899-help-with-using-get/#findComment-421614 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.