Jump to content

Using $_GET


adamking217

Recommended Posts

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

Link to comment
Share on other sites

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

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.