Jump to content

[SOLVED] Using Query String - Index.php?section=x - HELP!


MxGucci

Recommended Posts

Hi,

 

I used to know how to code in PHP back in 2002, I need to refresh my memory while I create a new site. However, I am stuck with this code, it should be working as I got this off the net, and even got many other same type of codes, but for some reason they don't work on my site.

 

I am trying to create a page so I can use Query String to direct my visitors to pages using index.php?section=x.

 

Here is the code I have used:

 

<?

 

ini_set("register_globals", "on");

 

if($QUERY_STRING == "") {

    // Main Page

    echo "main page!!";

} elseif($QUERY_STRING == "about") {

    // About page

    echo "about page!!";

} elseif($QUERY_STRING == "contact") {

    // Contact page

    echo "contact page!!";

} else {

    // Page not found

    echo "Oops.. Page not found (404)";

}

 

?>

 

-- When I went to www.tiltnation.com/beta/scripts/test.php .. it at first seems to work by saying "MAIN PAGE!!"

 

but when I go to www.tiltnation.com/beta/scripts/test.php?=contact .. it still says "MAIN PAGE!!"

 

So I went and found another snippet off a site, and still same thing, below is the code I used for this snippet:

 

<?php

 

$page = $GET['page'];

 

switch ($page) {

case '1':

echo 'This is page 1';

break;

case '2':

echo 'This is Page 2';

break;

case '3':

echo 'This is Page 3';

break;

default:

echo "Sorry Page $page doesn't exist";

break;

}

 

?>

 

The link is www.tiltnation.com/beta/scripts/switch.php .. again actual page says what it should, but when I go www.tiltnation.com/beta/scripts/switch.php?page=1 .. nothing happens.

 

Can someone PLEASE HELP!?

 

Could this be something to do with my server settings? I am with godaddy hosting, how do I edit the php settings?

 

Thanks for your help!

Alot has changed since 2002. Don't use register_globals bad practice and exploitable.

 

Instead of using QUERY_STRING, use $_GET and $_POST.

 

The main problem is you forgot the _ in $GET, it needs that underscore to check correctly.

Alot has changed since 2002. Don't use register_globals bad practice and exploitable.

 

Instead of using QUERY_STRING, use $_GET and $_POST.

 

The main problem is you forgot the _ in $GET, it needs that underscore to check correctly.

 

Thanks for your help, could you possibly tell me where I would use $_GET and $_POST in the first snippet I had pasted? Please and thank you!

<?php

//The next line was missing the underscore in $_GET
$page = $_GET['page'];

switch ($page) {
case '1':
echo 'This is page 1';
break;
case '2':
echo 'This is Page 2';
break;
case '3':
echo 'This is Page 3';
break;
default:
echo "Sorry Page $page doesn't exist";
break;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.