• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

How do you this in php files?

ozaidum

New Member
I've seen this on some sites but I don't know how to do it or what is it called. It's like the php file is converted into a folder. And when you're in it you can see on the address bar that it's a folder.

Example: I have a file mypage.php on my website example.com/pages. The url of the file is example.com/pages/mypage.php. The one I saw, the file became example.com/pages/mypage. And if the file is mypage.php?p=file it becomes example.com/pages/mypage/p/file.

How do you do it? also, how do yo call it?
 
Last edited:

BeIIy

New Member
Code:
<?php 
if(isset($_GET['page']))
  if(file_exists("./pages/" .$_GET['page']. ".php"))
    include("./pages/" .$_GET['page']. ".php");
  else
    include("./pages/404.php");
else
  include("./pages/main.php"); ?>
^ loads main if no ?page= is set. Loads 404 if ?page= is set to an invalid page
 

ozaidum

New Member
sorry but i know how to make this --> .php?=n

but what im looking for is how a file becomes a folder:
example.com/mypages/mypage.php ---> example.com/mypages/mypage
example.com/mypages/mypage.php?p=n ---> example.com/mypages/mypage/p/n
 

felguard

New Member
If you're using this code:
<?php
switch($id) {
default:
include('index.html'); <-- the url to your main page
break; case "page1": <-- link id, the "title" what ever you wanna call it
include('page1.html'); <--- the link id page file, the file it will go to
break; case "page2":
include('page.html');
break; case "page3":
include('page.html');
break; case "page4":
include('page.html');
break; case "page5":
include('page.html');
}
?>
and you want it to be like .php?=n, then just change:
switch($id) {
to:
switch($n) {
Put the entire code in your layout where your content changes.
 

DarkBlood

NLC
NLC
Yeah that can work pretty well... and that's how it works normally... but what if the person also wants to get that? (I believe that was explained earlier, but I'll explain it again.)

Code:
<?php
switch($id) { 

default: 
include('index.html'); // the url to your main page
break;

case "page1": // This is what id is set to. If id is set to "page1" the below will execute.
include('page1.html'); // the file it will go to. If you want to make it so that if this file IS NOT THERE and is required to run this script, use require('page1.html'); instead.
break;

case "page2": 
include('page.html'); 
break;

case "page3": 
include('page.html'); 
break;

case "page4": 
include('page.html');
break;

case "page5": 
include('page.html');
} 
?>
Code:
$_GET['id'] // This will output whatever the variable "id" is set to (if it is set in the URL. If it sin't set in the URL, this will result in either "null" or no value at all.
 
Top