AZForums: PHP - Dynamic Includes - AZForums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP - Dynamic Includes Gives you a cool URL which ends like - index.php?id=page

#1 User is offline   Adrenaline Icon

  • GFX God
  • PipPipPipPipPipPipPip
Group:
Members
Posts:
667
Joined:
08-September 05

Posted 17 October 2005 - 07:38 PM

Strings are things like the Includes, except it gives you that cool URL. You know the ones like http://www.domain.co...php?id=filename? Well anyway, here you will learn how to do it.

Add this code to a document and name it includes.php:
<?PHP
// This determines that the string will be called "id"v $id = $_GET['id'];

if(!$id){
include"index.php";
}
elseif($id=="filename"){
include"includes/filename.php";
}
// and if there is an incorrect string, we can direct to a 404 page

else {
include"404.php";
}
?>


-----------------------------------------------

Now it is time to separate it so you people can understand it a little bit more.

-----------------------------------------------
This part of the coding tell the browser to use index.php as the first page that comes up. Most people will need to change this to the name of the file they want to appear on the index page. For example I would put the news into it so my code would me:

if(!$id){
include"index.php";
}


My Example!

if(!$id){
include"news.php";
}



Now thats out of the way, time to move onto:

Now this gives the cool URL. Where it says elseif($id=="filename"){, this is what will be on the end of the URL for example; index.php?id=filename. Just change the name from filename to what you want.
Now this bit is what it will include into the page; include"includes/filename.php";. Just change the path to the correct path to the file you want to include. Here is my example:

} elseif($id=="filename"){
include"includes/filename.php";
}



My Example!

} elseif($id=="photoshop"){
include"includes/photoshop_page.php";
}



Now this bit adds a 404 Error page, if the page you have put doesn't exsist:

else {
include"404.php";
}


This will just include a 404 page if the page the browser is looking for doesn't exsist.

------------------------------------------
Adding to your page
Now I will explain how to add the includes to your page. Open up your index page or whatever your main page is, now go to the part where you want all the includes to show. Now put this code:

<?PHP include ("path/to/your/includes.php"); ?>



And finally, how to add them to your links. This part is simple:

<a href="index.php?id=filename">Link<a">


-------------------------------------------
If you have any query's about this tutorial, please contact me via PM or IM. You could even post here.
Posted Image
0

#2 User is offline   JustMadMike Icon

  • AZ Newbie
  • Pip
Group:
Members
Posts:
7
Joined:
17-October 05

Posted 17 October 2005 - 11:06 PM

Thanks, that was great to read! I don't really know PHP yet, so i could be wrong, but isnt

Quote

<PHP include ("path/to/your/includes.php"); ?>

meant to be

<?PHP include ("path/to/your/includes.php"); ?>


JustMadMike

This post has been edited by JustMadMike: 17 October 2005 - 11:10 PM

0

#3 User is offline   Blade Icon

  • -«{ Corrupted }»-
  • PipPipPipPipPipPipPipPipPip
Group:
+ Platinum
Posts:
3,089
Joined:
29-August 05

Posted 18 October 2005 - 11:31 AM

Thanks alot man.

Do you know how to code PHP properly then? :arg:
Posted Image
\\ Respect: Apple, crewfan19, sophiebro, SKB //
0

#4 User is offline   Adrenaline Icon

  • GFX God
  • PipPipPipPipPipPipPip
Group:
Members
Posts:
667
Joined:
08-September 05

Posted 18 October 2005 - 08:24 PM

I know it properly, but I am still learning if you get me. I don't understand it as much as I should.
Posted Image
0

#5 User is offline   Spikeh Icon

  • Jedi Master
  • PipPipPipPipPipPipPip
Group:
Members
Posts:
656
Joined:
30-August 05

Posted 19 October 2005 - 02:57 PM

PHP is something I can edit sort of and understand but still learning how to do it myself. It doesn't seem to respond to my usual way of learning which consists of me prodding at various bits of code until I break it then figure out how to fix it.

EDIT: Forgot to give my opinion on the coding. Very nice I might use it on Spikeh.com

This post has been edited by Spikeh: 19 October 2005 - 03:18 PM

0

#6 User is offline   Virus Icon

  • Instant Reflects
  • PipPipPipPipPip
Group:
Members
Posts:
158
Joined:
30-October 05

Posted 03 November 2005 - 02:10 AM

Very nice, thats what I've read in 23 of my other computer books.
Yes, I am back!
0

#7 User is offline   Blade Icon

  • -«{ Corrupted }»-
  • PipPipPipPipPipPipPipPipPip
Group:
+ Platinum
Posts:
3,089
Joined:
29-August 05

Posted 03 November 2005 - 11:01 AM

Ive even started making my own website <_<
Posted Image
\\ Respect: Apple, crewfan19, sophiebro, SKB //
0

#8 User is offline   Adrenaline Icon

  • GFX God
  • PipPipPipPipPipPipPip
Group:
Members
Posts:
667
Joined:
08-September 05

Posted 03 November 2005 - 08:14 PM

Good for you =D
Posted Image
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users