Jump to content

[SOLVED] Passing Requests to index page?


Jeigh

Recommended Posts

I was reading this tutorial http://www.phpfreaks.com/blog/mod-rewrite-ignore-dir on PHPFreaks and read the following at the start of the tutorial:

 

"So i have my little website and like a lot of websites, I have one index page that I simply pass a parameter through a GET request and that determines the output of the site."

 

All websites I've made I just have each feature of the site in a different php file, for example I'll just have addresses like:

www.example.com/register.php

www.example.com/uploadsomthing.php

www.example.com/showsomthing.php?id=1

 

I'm making a new site now and want everything to be as professional as it can be, and to me this always seems very messy and unprofessional.

 

So my question is what exactly is that quote talking about and how is it achieved. I'm assuming it will involve somthing like:

 

if($_GET['p'] == "register"){

(HTML + PHP for register here

}

 

else if($_GET['p'] == "upload"){

(HTML + PHP for uploading page here)

}

 

and the addresses will be www.example.com/index.php?p=register or /index.php?p=upload etc.

 

I also assume having it set up like this would make using mod_rewrite much easier (which I also plan to do). So before start jumping in and doing stuff I want to make sure what I'm assuming is correct or if not how exactly do I go about doing it.

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/
Share on other sites

Yeah, you can do that, but that just means the index page will get a lot of data passed to it. By the way, that method isn't the best solution. It'll make the index page a b*tch to code.

Not necessarily if you code it correctly.

I would do something like:

Index.php:

<?php
if	(strlen($_GET['p']) > 0)
{
switch($_GET['p'])
	{
	case "register":
	include("register.php");
	break;

	case "login":
	include ("login.php");
	break;

	default:
	include ("indexpage.php");	
	}
}	
else
{
include ("indexpage.php");		
}
?>

Pretty simple in my opinion. Just code the pages separately but include them as one page using switch and NOT if statements.

 

Yeah, you can do that, but that just means the index page will get a lot of data passed to it. By the way, that method isn't the best solution. It'll make the index page a b*tch to code.

 

When I want to base everything off index.php I use this:

 

 

 

http://www.somerandomsite.com/index.php?page=whatever

<?php

require_once("includes/header.php");		

if (isset($_GET['mode'])){
	$page_sel = strtolower($_GET['page']) . ".php";	
} else {
	$page_sel = "default.php";
}

if (is_file($page_sel)){
	include ($page_sel);
} else {
	include ("default.php");
}

include("includes/footer.php"); 
?>

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.