PDA

View Full Version : Ok then, PHP Help please xD



tekni
26-11-2006, 04:20 PM
In my main content div I have this:


<?php include("home.php"); ?>

So, in my nav div, what would code would I have to put if I wanted to open say news.php into the main content div?

+Rep to any helpers.

RYANNNNN
26-11-2006, 04:23 PM
Are you using iframes, otherwise you just replace home.php with news.php and save it.

tekni
26-11-2006, 04:28 PM
I know how to work iframes, but iframes are crap and should be blown up.

I'm trying to figure out how the hell to use includes.

Florx
26-11-2006, 04:29 PM
Here is sommert i wrote: Hope it is what u need!


<?php
// Assign the requested page to a shorter variable for simplicity.
// The value of $_GET["page"] will be obtained from index.php?page=RIGHT_HERE
$p = $_GET["page"];
// Check for bad requests. This is necessary to prevent the wrong files
// from being included. This is a security measure.
if (strpos($p,"..")) {
// A bad request has been made, exit immediately. Do not proceed
// with the inclusion.
// strpos($p,"..") checks for presence of ".." in the page request.
// ".." can be used to access files in parent directories
die("Bad page request");
}
// File to include.
// this will be something like '/www/page.php'. If $p is empty, fall back
// main.php. THIS FILE MUST EXIST, otherwise bad things will happen.
if (!$p) $p = "main";
$content_file=$_SERVER["DOCUMENT_ROOT"]."/".$p.".php";
// See if $content_file exists. If it does not, redirect to the homepage.
if (!file_exists($content_file)) {
header("Location: {$_SERVER["PHP_SELF"]}");
exit();
}
// At this point everything is fine. Set the appropriate title and then
// include the files.
// Syntax: $variable = (condition) ? value_if_true : value_if_false;
$title = ($p) ? "$p - My Site!" : "Main page - My Site!";
include("header.php");
include($content_file);
include("footer.php");
?>

tekni
26-11-2006, 04:32 PM
No tutorial on how to use it?

Where did you steal that from?

Florx
26-11-2006, 04:35 PM
http://f0rked.com/articles/dynamism

Lol i didnt write it. Well i did but i didnt w.e. here ^

uber
26-11-2006, 04:35 PM
Use the easier way, where you get page.php?id=whatever.
I'll try and find you a tut.

tekni
26-11-2006, 04:37 PM
Thanks dan.

Florx
26-11-2006, 04:39 PM
http://f0rked.com/articles/dynamism go there

uber
26-11-2006, 04:46 PM
<?php
switch( $_GET[’id’] )
{
default:
include ‘main.htm’;
break;

case ‘community′ :
include ‘community.htm’;
break;
}
?>

The code is very simple...

You can copy the 3 lines as many times as you wish (the case, include and break) for more pages.

The top one which says deafault it the page you wish to load when the site is loaded.

You can change the bit at the top that says id to whatever you want, it will appear in the url, e.g. index.php?id=community.

Put the code in your content area.

Off topic: 3 pure for your layout?

tekni
26-11-2006, 04:51 PM
Thanks a hellova lot dan.

Because I suck at PHP:

Parse error: syntax error, unexpected ''' in /home/xvisor/public_html/index.php on line 234
wth?

Off-topic: Sure.

Mentor
26-11-2006, 04:57 PM
Well heres a quick varient on the code i would usealy use



//Get varible from url
$p = $HTTP_GET_VARS['p'];
//Set page dir and defult
$page_dir = "Pages";
$defult_page = "home";
//if $p aint set, we include home page
if(!$p){ include($page_dir."/".$defult_page.".php"); }
else
{ if(file_exists($page_dir."/".$p.".php")){ include($page_dir."/".$p.".php");} // if the file exists in the directory, we know its real and allowed, so we inclucde it.
else{ include($page_dir."/".$defult_page.".php");} // if its not, its ether a wrong dir or bad hacking attempt, so we include the home page again

tekni
26-11-2006, 05:02 PM
Am I bad luck or something:


Parse error: syntax error, unexpected T_VARIABLE in /home/xvisor/public_html/index.php on line 228

$p = $HTTP_GET_VARS['p'];

Mentor
26-11-2006, 05:04 PM
The problem has happened before the line of code in question, most likly in your own code you have forgotten to add a ; or have missed a }

tekni
26-11-2006, 05:07 PM
I'm forced to use iframes because I suck at PHP.

Kanker.
26-11-2006, 11:53 PM
LOL adam <3 Bless. php will work for u one day...

Florx
27-11-2006, 08:48 AM
Unlucky :(
Find other coding stuffs.

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