0

I don't know if this is more efficient or if it is just as quick to just code out a new page. But what I was wondering is how you create an index page and call on a new page, but the url usually says something like: index.php?page=contact instead of the url saying contact.php
Is this something done through the database and I just called on the page through that or is there really a contact.php page and when the link is clicked it calls on it in a different way?

This is not super important I was just curious on how it was done.

Thanks!

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by bjeffries
0

Well , actualy index.php?page=contact is the same thing as /page/contact
The index.php page is an entry point for the entire site, and the content gets included in the index page, depending on which content is requested. And the to make the urls look pretty (/page/contact) instead of (index.php?page=...) you can use apache mod_rewrite. Its just 2 or 3 lines of code you have to add in the apache config file to make it rewrite your Url's.

Hope this was a bit clear, and i didnt forget any stuff

1

index.php?page=contact

<?php
if(isset($_GET['page']) && $_GET['page'] == 'contact'){
//code for contact

}

?>

Edited by Mike516: n/a

0

Take a look at this code, it dynamically gets the page you request without refreshing the whole page.

<?php

	$page = $_GET['page'];
	if ($page)
	{
		$path = "inc/".$page.".php";
		
		if(file_exists($path))
		{
			include($path);	
		}
		else
		{
			echo "That page does not exist! ";
		}
		
	}
	else 
	{
		include('include.php');
}?>

1.

$path = "inc/".$page.".php";

// this is the folder that should contain the page you want loaded, you can change the folder name ofc, or just remove it if you want your files in the same directory as the index containing this code.

2.

$page = $_GET['page']; //

you can change the "page" to whatever, right now the links should say "index.php?page=((YOUR REQUESTED PAGE))

3.

include('include.php');  YOU CAN INCLUDE A PAGE TO THE INDEX.PHP AS A STARTING PAGE WHEN THE INDEX IS SHOWN, IT WILL NOT SHOW ONCE YOU LOAD ANOTHER PAGE.

4. All of your links should be named "index.php?page=(YOUR REQUESTED PAGE)"

As an example you could do like this;

<table>
<tr>

<td>
THE MENU WITH THE LINKS GOES HERE, BUT DOESNT REALLY MATTER WHERE YOU GOT YOUR MENU OR LINKS
</td>
<td>
THE LINK YOU CLICK ON WILL LOAD THE PAGE INTO THIS CONTENT.
<?php

	$page = $_GET['page'];
	if ($page)
	{
		$path = "inc/".$page.".php";
		
		if(file_exists($path))
		{
			include($path);	
		}
		else
		{
			echo "That page does not exist! ";
		}
		
	}
	else 
	{
		include('include.php');
}?>
</td>

</tr>
</table>

So inside the "inc" folder you name your pages normally, like "search.php" etc... but you got to link to them as "index.php?page=search"

Hope this helps, and even if you didnt look for this, i do hope you like it.

Sincerely,
Sorcher

0

Mike516 summed it up pretty good, but left me with one question which sorcher summed up entirely. Thanks for everything I should be able to get this no problem!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.