Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ZicklePop

macrumors member
Original poster
I'm new to php and I would like to figure out how to do the thing where websites send you to something like visit test.php?string=variable1 to see one webpage and test.php?string=variable2 to see another webpage. How would I do this any is there any tutorials or something? Thank you.
 
i would use something like a switch statement.. look it up in the PHP documentation if you need help.

PHP:
<?php
$area = $_GET['area'];

switch($area){
 	case "1": 
 		include("pageone.php");
 		break;
 	case "2": 
 		include("pagetwo.php");
 		break;
 	default:
 		echo "Invalid area code";
 } // switch
?>
Of course you can change the numbers to strings and replace the filenames. I hope you get the idea.. the PHP documentation is a great place to look 🙂
 
neoserver said:
i would use something like a switch statement.. look it up in the PHP documentation if you need help.

Of course you can change the numbers to strings and replace the filenames. I hope you get the idea.. the PHP documentation is a great place to look 🙂
Thanks alot, is there any way to do it in the same file though? 'Cause currently I do something like that.

And I'ma going to go look at it(PHP Documentation) heh..
 
so you want the entire webpage in one file? thats not a problem 🙂

just replace the switch statement with this one

PHP:
switch($area){ 
    case "1": 
?>
        HERE IS THE HTML FOR THAT PAGE 
<?php
        break; 
    case "2": 
?>
        AGAIN HTML FOR THE PAGE
<?php
        break; 
    default: 
        echo "Invalid area code"; 
} // switch

or if you had actual PHP code to produce your pages you could just replace the include functions with the actual PHP code to generate your pages 🙂Hope i have helped.
 
neoserver said:
so you want the entire webpage in one file? thats not a problem 🙂

just replace the switch statement with this one

or if you had actual PHP code to produce your pages you could just replace the include functions with the actual PHP code to generate your pages 🙂Hope i have helped.
Ah, thank you!
 
what i would do is make the index.php generate all the common stuff like the logo etc. Then i would use the code i have given you already and place it into that page.. now, then i would move the content and put it in different .php files and include them using the first sample. Thats how i would do it but you could do it the second way i showed you and put everything in one file, that is certainly the easiest.
 
generally, i split pages in the 3 areas, headers, body, and footer then you can have dynamic universal headers and footers for everypage and a dynamic body as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.