PDA

View Full Version : index.php?page=10



Nether$
03-12-2006, 09:32 AM
Hi

to make my sites i use front page therefore i cant code php (well i can manually.) however i would like to use this fucntion of php on my site:

mysite.com/index.php?page=1

you know, so the index template is the same and content is from the ?page=1

as i dont have dreamweaver i have to do this manually and im not sure how. i might be able to guess but the problem is i cant preview it as i work!

is there a documentation/tutorial i can use for this???

thank you + rep

CHTom
03-12-2006, 09:36 AM
http://madkid.org/?x=php/phpnav

That gives you a simple version of what your looking for, however...all pages must be the same file type for that code.

(all files must be .html, .php and you must configure that using the tutorial on there)

also - Incase you didnt know - the file your going to put this code in needs to have a .php extention.

- CHTom

Nether$
03-12-2006, 09:46 AM
http://madkid.org/?x=php/phpnav

That gives you a simple version of what your looking for, however...all pages must be the same file type for that code.

(all files must be .html, .php and you must configure that using the tutorial on there)

also - Incase you didnt know - the file your going to put this code in needs to have a .php extention.

- CHTom

yep i know about the .php extention, i had dreamweaver on my old cpu and not this one. + rep

tekni
03-12-2006, 10:28 AM
Why do you need Dreamweaver to code PHP?

Luckyrare
03-12-2006, 10:44 AM
Wrote this for you... Very simple

page.php?page=x


<?php
if($_GET[page] == "1"){
?>
Hello this is page 1 la la la la....
<?php
}
if($_GET[page] == "2"){
?>
This is page 2 do do dooo...
<?php
}
if($_GET[page] == "3"){
?>
This is page 3 mmm mmm mmm....
<?php
}
else{
?>
This is if the page is anything else
<?php
}
?>

:Blobbed
03-12-2006, 10:45 AM
Name each of your pages 1.php and 2.php etc, and do:

<?php
$val = $_GET['page'];
$val .= ".php";
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val);

if (isset($_GET['page'])) {
if (file_exists($val)) {
include "$val";
}
else {
include "404.php";
}
}
else {
include "main.php";
}
?>

CHTom
03-12-2006, 12:52 PM
Erm, I already gave the guy a tutorial on it, lol.

Wasnt really much need for the other two codes....but im sure he/she appreciates it.

omgDAN!
03-12-2006, 01:00 PM
switch ($_GET['page']) {
case "1":
include('1.html');
break;
case "2":
include('2.html');
break;
case "3":
include('3.php');
break;
}

That would work, you just have to add the pages manually.

xRoyal15
03-12-2006, 01:10 PM
<?
if($_GET[page]){
$page = $_GET[page];
}else{
$page = home; //or whatever your default page to show is.
}
?>


then where you want the page displayed put



<?
include("$page.php");
?>


All works fine :P

:Blobbed
03-12-2006, 01:37 PM
Use functions:



<?
function page($url)
{
include <<<EOF
{$url}.php
EOF;
}
?>


Then:



<?
include('func.php');
$url = $_GET['page'];
page($url);
?>

nets
03-12-2006, 04:43 PM
You're better off having an array with the page names as keys, with their corresponding value as the location. Also in the interest of security, unless you need to use PHP within the "included" file, don't include the page. By including the page you're increasing the chance of having malicious PHP evaluated.


<?php

$page[''] = 'pages/home.htm';
$page['news'] = 'pages/news.htm';
$page['info'] = 'pages/info.htm';

if(file_exists($_tmp=$page[$_GET['page']]))
print file_get_contents($_tmp);
else
print "<strong>The page you requested could not be found.</strong>\r\n";

?>



Use functions:



<?
function page($url)
{
include <<<EOF
{$url}.php
EOF;
}
?>


Then:



<?
include('func.php');
$url = $_GET['page'];
page($url);
?>

That is a severe risk to your site's security, since anyone could obtain secret information hidden on your server or (if "allow_url_fopen" is enabled in php.ini) even include a malicious PHP page located on their own server. Furthermore, it was pointless splitting it into a function and using heredoc syntax.

ItchysPaws
03-12-2006, 05:24 PM
with the switch code, your including files, its best having it as functions with the processed html/php in that.

Josh-H
03-12-2006, 06:56 PM
Some nice lil codes/tuts forming in this thread!

ScottDiamond
04-12-2006, 05:53 PM
Would I put this in my iFrame or remove the iFrame and replace it with that? And renaim it to home.php ?

nets
04-12-2006, 08:06 PM
Would I put this in my iFrame or remove the iFrame and replace it with that? And renaim it to home.php ?
You'd replace the Iframe with the PHP code, you shouldn't need to rename anything (as it will be using the files which were being viewed through your Iframe). Be careful about whose script you choose, as some of the scripts posted here aren't secure.

Want to hide these adverts? Register an account for free!