Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Page on Page, but with ?blahblah in url??
Reply
 
Thread Tools Display Modes
(#11 (permalink))
Old
Shadowrider50's Avatar
Member
Shadowrider50 is on a distinguished road
 
Posts: 76
Join Date: Jan 2012
Smile Fixed it - 04-27-2012, 12:41 AM

I've fixed it up and tested it, it should be fully working now

PHP Code:
<?php
$documentfolder 
'documents/'//Put the name of the directory where your documents are located here
$directory array_flip(scandir($documentfolder)); // scan the files & lists them
if (($_GET["page"]) && (isset($directory[($_GET['page'])]))){ //verifies file
include $documentfolder . ($_GET['page']);} //include the file
else { echo "404 Page Not Found"; } // error if not found
?>
Name this script whatever you want to name it, but just make sure that the directory in line 1 of the script exists and that the page you send exists.

An example of usage:
script would be public_html/index.php
Directory would be public_html/documents/
Page to load would be test.php (Located in the documents directory)

Then test it by using www.example.com/index.php?page=test.php
If it works it will show test.php within your page when you load it

You create more files in that directory and it will work for each one, just specify it in the url where it say page=test.php change it to page=filename.
Filenames are case sensitive and you have to type the extension.

If you want to not type the extension, you can use this alternate version but it will only work for .php files
PHP Code:
<?php
$documentfolder 
'urlkey/'//Put the folder where your documents are located here
$directory array_flip(scandir($documentfolder)); // scan the files & lists them
if (($_GET["page"]) && ((isset($directory[(($_GET['page']) . ".php")])))){ //verifies file
include $documentfolder . (($_GET['page']) . ".php");} //include the file
else { echo "404 Page Not Found"; } // error if not found
?>
Usage is same as normal version except with this you don't have to type .php at the end of the url

Last edited by Shadowrider50; 04-27-2012 at 12:56 AM.
Reply With Quote
Sponsored Links
(#12 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 06-16-2012, 10:38 PM

It's not working for me.
Reply With Quote
(#13 (permalink))
Old
Junior Member
tittbit is on a distinguished road
 
Posts: 12
Join Date: Feb 2012
Default 07-30-2012, 03:21 PM

if you want to avoid hassle of php coding, you can use iframe in html.

just select target of iframe as parent, or whatever name you want to give your new i frame
Reply With Quote
(#14 (permalink))
Old
kuroneko's Avatar
Senior Member
kuroneko is on a distinguished road
 
Posts: 112
Join Date: Jul 2012
Default 07-30-2012, 03:31 PM

Nope, creating those urls should be simple and easy. You don't even need a database to do that! Why would you need a database when you only have to parse each template files? You should only use database queries in the template files.

Code:
<?php
/**
 * Template auto run
 *
 * @package Frostproject
 */

/** Try to load various template files. */
$get = ( isset( $_GET['page'] ) ) ? $_GET['page'] : '';
$load = htmlentities( $get );
if ( ! isset( $load ) || empty( $load ) ){ $load = 'home'; }
switch( $load )
{
	case 'home' :
		include_once( 'frontpage.php' ); //template file # 1
	break;
	case 'aboutus' :
		include_once( 'about.php' ); //template file # 2
	break;
	default :
		header( 'Location: 404.php' ); // template file for 404 in case some curious visitor wants to play with your code
	break;
}
?>
The code above should fetch each php files according to the page you requested. In this case:
  • page?index
  • page?aboutus

The code above is safe. This is what I use in my frostproject cms. Think like this, what if some user want to fiddle with your website and entered index.php?page=lalala? In this code they will be transferred to the 404 page.

Shadowrider50's is good too. If you want to use his code change this code:
Code:
$documentfolder = 'documents/'
into:

Code:
define( 'script_path', dirname(__FILE__) . '/' );
define( 'directory_path', script_path. 'directory/' );

$documentfolder = directory_path;


Anything about web design and development
frostproject.org

Last edited by kuroneko; 07-30-2012 at 03:38 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com