• 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

[Help] Shorting Urls

horaz

New Member
I have website and all of the page made with pure html page. Also, to many files on my server, sometimes I should type long-long url to get to my page ...
www.domain.com/about.html
www.domain.com/contact.html
www.domain.com/term.html
www.domain.com/gallery.html
www.domain.com/products.html
www.domain.com/about.html
etc etc

How to make it more simple, its look like... Something like dynamic url.
www.domain.com/?page=1
www.domain.com/?page=2
www.domain.com/?page=3
www.domain.com/?page=4

In this case, im using relative path on my html page. Simple PHP Scripts can do this??

Please give me an advice to do that. Thank you.
 
Alright,

create an index.php page and in there write this:

Code:
 <?

$page = $_GET[page];

if($page == "1"){
	include('about.html');
}
elseif($page == "2"){
	include('contact.html');
}
elseif($page == "3"){
	include('term.html');
}
elseif($page == "4"){
	include('gallery.html');
}
else{
	include('home.html');
}

?>

This should work!

To add pages just add:

Code:
elseif($page == "pagenumber"){
	include('filename.html');
}
Before the "else"

And with that command you can access your site with:
index.php?page=1
index.php?page=2
index.php?page=3
etc...
 
Last edited:
ani-m said:

Personally, Ill never use a script for that.

It takes hardly 5 mins to make a php script for that. The script which Pat made is just fine.

On piece of advice, Never write this in the Code ::

PHP:
$page = $_GET[page];
include($page);

It does clear up a lot of php statements & makes your script small but you are leaving your script open for kiddies to come in & take control.
 
this is v true....instead use the full syntax

PHP:
 <?

if($_GET['page'] == "1"){
	include('about.html');
}
elseif($_GET['page'] == "2"){
	include('contact.html');
}
elseif($_GET['page'] == "3"){
	include('term.html');
}
elseif($_GET['page'] == "4"){
	include('gallery.html');
}
else{
	include('home.html');
}

?>
 
I'd much rather using the switch function, much more secure I believe. Head over to zymic.com for an example.
 
PHP:
switch ($_GET['page']) {
case "1" : include 'page1.html';
break;
case "2" : include 'page2.html';
break;
case "3" : include 'page3.html';
}
// This is actually no more secure at all, it all depends on your style of coding
 
Make sure you have a default statement in there.

PHP:
switch ($_GET['page']) {
case "1" : include 'page1.html';
break;
case "2" : include 'page2.html';
break;
case "3" : include 'page3.html';
break;
deafult: include 'home.html';
break;
}

For all you PHP syntax Nazis, I know there doesn't need to be a break statement at the end. I like it better that way though, more organized.
 
not necessary, the switch is on $_GET so if it's set, it will be to one of those pages....
 
Actually, im trying using code from KRAK_JOE

PHP:
<?

if($_GET['page'] == "1"){
    include('about.html');
}
elseif($_GET['page'] == "2"){
    include('contact.html');
}
elseif($_GET['page'] == "3"){
    include('term.html');
}
elseif($_GET['page'] == "4"){
    include('gallery.html');
}
else{
    include('home.html');
}

?>

This works fine for me. But include function wont work with relative path. Image wont load if I using include function. What should I do?
 
PHP:
<?
// Document Root 
$docroot = '/home/yourdocs/public_html/folder/';

if($_GET['page'] == "1"){ 
    include( $docroot . 'about.html'); 
} 
elseif($_GET['page'] == "2"){ 
    include( $docroot . 'contact.html'); 
} 
elseif($_GET['page'] == "3"){ 
    include( $docroot . 'term.html'); 
} 
elseif($_GET['page'] == "4"){ 
    include( $docroot . 'gallery.html'); 
} 
else{ 
    include( $docroot . 'home.html'); 
} 

?>

try this way first, there are others.....so no worries if this don't work...just post.....
 
Back
Top