TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

php file mangement & extension

Page: 1 Reply
Oct 29th 2003#126949 Report
Member since: Jul 25th 2003
Posts: 489
This maybe really stupid since I have no knowledge of php whatsoever so need some help, you know when you go to a site the web page in the address bar always stays http://blahblah.com/index.php?id=somthing well I was wondering how do you do that or maybe someone can give me a more clear understanding, thanks, also I don't really know what's it called.
Reply with Quote Reply
Oct 29th 2003#126953 Report
Member since: Nov 26th 2001
Posts: 2586
Well that is using Get method rather than Post method. But an example of how to use that sort of dealy in php pages:

1. you create some page called 'index.php'

2. On that page you have a 2 button navigation (to keep it simple.) - Home and Contact.

You break the page into 3 sections - ie. you include the header section, and the footer section so you can easily alter those pages, then include them into your php pages. But instead of creating a new page for each page you have, why not just create one page, then leave the content blank. Then depending on where you go in the site navigation, you let php fill the pages using a GET method.

3. so now we have index.php, header.inc.php, footer.inc.php, home.php, and contact.php. -> where contact.php and home.php are pages without any header or footer - ie they contain only the content.

so how does that work with index.php? example:

[php]/* index.php */

include('header.inc.php');

$id = $_GET['id'];

switch ($id) {

case 'home':
include('home.php');
break;

case 'contact':
include('contact.php');
break;

default:
include('home.php');

} # end switch

include('footer.inc.php');
[/php]
with the default, if someone typed in 'index.php' it would default to the home page.
See how nice and clean those pages are looking? You can break pages into little bits for easy updating and also for logical organisation.

So now how would the url look?

index.php?id=home
index.php?id=contact

etc.

Now if you have even more switch(case) inside of pages, for example you have it so contact page is web form or an about page you could have this inside the contact.php page:

[php]/* inside contact.php page */

$page = $_GET['page'];

switch ($page) {

case 'contact':
*** show contact form ****
break;

case 'about':
**** show about ****
break;

default:
**** show contact form****

} # end switch
[/php]


Now, you could have a link in the nav for an about page that could be:

index.php?id=home
index.php?id=contact&page=contact
index.php?id=contact&page=about

etc....

Another good use of this is using this kind of page design to "wrap" your site. So on the index page you set some constant that must be set when any page is included. example:

(refer back to index.php above) and above the header include function add:
[php]define("CISCO", "The_Cool_Dogg");[/php]

Now on any php page you include add this at the very top:

[php]
if(!defined("CISCO")){

die('Welcome to the www.yoursite.com');

}
[/php]

What happens then is if that constant isn't declared the page will not view. Keeps script kiddies from doing this kind of stuff:

http://www.yoursite.com/includes/admin.inc.php

Now if someone could see your directory structure and you have database passwords or user passwords they could (if directory browsing was enabled) download your pages with that info. This way, (if you also add a index.htm file to all directories, except where index.php is -> make this file blank, then that will shut off directory browsing without having to mess with .htaccess files.

k, i've rambled enough.....
Reply with Quote Reply
Oct 30th 2003#126990 Report
Member since: Jul 25th 2003
Posts: 489
Man, you should teach that or something, it will probably take me a while for it to sink in though thx
Reply with Quote Reply
Nov 26th 2003#130662 Report
Member since: Mar 29th 2003
Posts: 1326
In case anyone was interested...I don't really understand it, but I found this and I think its going to help: (near the bottom)

http://www.w3schools.com/php/php_conditionals.asp

tom :D
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum