adamking217 Posted September 8, 2010 Share Posted September 8, 2010 I cannot seem to get my link to work.. I want to build a php script that has more than one $_GET command.. The link I want to make is: index.php?section=tutorial&viewing=18-classes_or_ids. Here is my PHP code.. <?php $section = $_GET['section']; switch ($section) { case "home": include("home.html"); break; case "register": include("register.html"); break; case "tutorial_home": include("tutorial.html"); break; default: include("home.html"); } $tutorial = "?section=" . urlencode('tutorial&viewing') . $_GET['tutorial&viewing']; switch ($tutorial) { case "18-classes_or_ids": include("classesorids.html"); break; } ?> Please help me!! Quote Link to comment https://forums.phpfreaks.com/topic/212878-using-_get/ Share on other sites More sharing options...
The Eagle Posted September 8, 2010 Share Posted September 8, 2010 You've got your GET tags correct. $section = $_GET['section']; $viewing = $_GET['viewing']; Didn't really, know what you wanted to accomplish... Quote Link to comment https://forums.phpfreaks.com/topic/212878-using-_get/#findComment-1108775 Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Hi there adamKing217, The way as you have constructed your links means that to access $_GET information, you would need to look at how you have done the link:- index.php?section=tutorial&viewing=18-classes_or_ids. The bits I have highlighted are the pieces available in the $_GET array when the link is sent to the browser (at least this is how I understand it to be) If you did print_r($_GET); on your page when the link was sent you would see the parts highlighted available from the array to use, this is where the use of isset() is paramount as a form/processing handler. So in your link $_GET would be this (set variables):- $_GET['section'] => tutorial $_GET['viewing'] => 18-classes_or_ids Also when constructing links, the & needs to be made into & for validation purposes if you are into that sort of stuff. $tutorial = strip_tags($_GET['viewing']);//gives you that extra added security switch ($tutorial){ case "18-classes_or_ids": include("classesorids.html"); break; } And also for this:- <?php $section = strip_tags($_GET['section']);//added security switch ($section){ I have added the strip_tags() function so that you can have a safer script, I think that it is prudent to always be thinking of security, but that'a just my opinion. Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/212878-using-_get/#findComment-1108853 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.