View Full Version : ?page= script and ?image=


joshg678
10-23-2003, 09:30 PM
Well as the title says i think you know what im talking about.
I started a script that would allow me to use one template (layout) and have a bunch of pages useing the same layout. But when I made the script it did not work right, so I turned to james (my friend), he fixed it up for me and it works just the way I wanted it to. (and some help from here)

First create a folder called my_pages, then put a default.php, that will show when nothing i specified, make page_not_found.php, that will display when the file can not be fond.


<?
$content_folder = "my_pages/";

if(!isset($_GET['page']) || $_GET['page'] == ""){
$inc_ref = "default";
}
else{
$inc_ref = $_GET['page'];
}
if(!file_exists($content_folder.$inc_ref.".php")){
$inc_ref = "page_not_found";
}

include($content_folder.$inc_ref.".php");
?>


for this to work all pages in the folder "my_pages" have to be the .php extension, and to get to the page you want, lets say its wee.php. To get to it, the link would be domain.com/index.php?page=wee






If you want the title to change just put the <title> tags in the page that you include.



Also here is one that works with images.


<?
print "<html>\n";
print "<body>\n";
$i = $_GET['img'];
if(!isset($i)){
print "No Image Specified";
}
else{
if(file_exists($i)){
print "<img src=\"$i\" border=\"0\">\n";
}
else{
print "Image does not exist";
}
}
print "</body>\n";
print "</html>\n";
?>


I don't have an example of this one yet, but i'll have one soon.

joshg678
11-08-2003, 04:21 AM
Here is another totorial that should help.



Lots of pages in one 1 layout


ok what you do is the index.php file you use that as your layout and everything, and make sure the code does not get messed up.
code______________________________
<?
$content_folder = "my_pages/";

if(!isset($_GET['page']) || $_GET['page'] == ""){
$inc_ref = "default";
}
else{
$inc_ref = $_GET['page'];
}
if(!file_exists($content_folder.$inc_ref.".php")){
$inc_ref = "page_not_found";
}

include($content_folder.$inc_ref.".php");
?>
___________________________________
and the folder "my_pages" should not be changed unless you know what your doing, each page you put in the my_pages folder has to have the same file extenction, right now it is set as .php
so if you put a page in there (hello.php) to get to it useing the script you would do www.mydomain.com/index.php?page=hello
that would include the page. Also you only need to add text in the file because all the colors and further stuff will be added with the index.php

Inside the my_pages folder there are the following files, index.php (for blocking people from seeing your pages, don't forget to change the route adress), the page_not_found.php (this is the page that will be included if the page typed in can not be found, and there is a default.php (this is what will be included if there is only index.php typed in).

i hope that is all

also, if you are going to include a pic or do a link, the files in the my_pages folder are included and thinks they are in the lower directory. (ex: image location "www.dsg.com/images/bla.gif" php file in my_pages <img scr="images/bla.gif> and NOT ../images/bla.gif

hope you understand.

thinglie
01-03-2004, 05:58 PM
Thanks!