Hopefully you understood that
Question
Started by Davis, Jun 22 2008 08:52 AM
7 replies to this topic
#1
Posted 22 June 2008 - 08:52 AM
Okay well yes I have a question but it's going to be hard to explain. I've seen it done on Clan Templates design templates and I wanted to do it to mine. I know with every page you make that has the same information on the previous page on say a side bar. You have to change that on every page when ever you want to update it. What I want to do is make it like a URL where it receives all its text from another php file. Like say index.php (has a sidebar with information exactly the same on every page) and then it receives its information from another php file like testimonials.php. What code do I put in to make that work.
Hopefully you understood that
Hopefully you understood that
#2
Posted 22 June 2008 - 10:36 AM
There are different ways of doing this. The most easy way will be to just include the sidebar by using the following code:
Theres also a way to make an index page and use $_GET in the url to include the information.
When you've done this. The url will be:
<?php include ("menu.php"); ?>
Theres also a way to make an index page and use $_GET in the url to include the information.
if (isset($_GET['value'])) {
// Get the $_GET value and put .php behind it.
$val = $_GET['value'];
$val .= ".php";
// Strip some stuff
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val);
// Checks if the value in the $_GET exists
if (file_exists($val)) {
// Include
include "$val";
} else {
// Not found
echo "The page you are looking for can't be found..";
}
} else {
// Include this when nothing is set
include "main.php";
}
}
When you've done this. The url will be:
index.php?value=<file name without .php behind it>So:
index.php?value=testimonials
Edited by 023-jimmy, 22 June 2008 - 02:13 PM.
#3
Posted 22 June 2008 - 05:11 PM
Thanks. I am trying the first one now. Although for my index information, what your saying is when I click on a link, everything opens in the content area and not in a new page, reopening the entire page.That would be great having it like something like flash, is that possible?
EDIT: Also, for my side bar. Is it possible to make it scrollable. Like you can scroll up/down
EDIT: Also, for my side bar. Is it possible to make it scrollable. Like you can scroll up/down
Edited by Davis, 22 June 2008 - 05:17 PM.
#5
Posted 22 June 2008 - 07:41 PM
Can you atleast explain what he means by that
if (isset($_GET['value'])) {
// Get the $_GET value and put .php behind it.
$val = $_GET['value'];
$val .= ".php";
// Strip some stuff
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val);
// Checks if the value in the $_GET exists
if (file_exists($val)) {
// Include
include "$val";
} else {
// Not found
echo "The page you are looking for can't be found..";
}
} else {
// Include this when nothing is set
include "main.php";
}
}
if (isset($_GET['value'])) {
// Get the $_GET value and put .php behind it.
$val = $_GET['value'];
$val .= ".php";
// Strip some stuff
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val);
// Checks if the value in the $_GET exists
if (file_exists($val)) {
// Include
include "$val";
} else {
// Not found
echo "The page you are looking for can't be found..";
}
} else {
// Include this when nothing is set
include "main.php";
}
}
#6
Posted 23 June 2008 - 05:10 PM
http://forums.clante...ad.php?t=125559
You can find an explanation there. The script I gave you does the same thing.
You can find an explanation there. The script I gave you does the same thing.
#7
Posted 28 June 2008 - 02:02 AM
That code he gave you is pretty hard for a beginner to understand. A simpler way of doing the same thing would be:
Now granted, jimmy's version checks to see if a file exists before you include it, it's pretty hard to understand. To explain my code is easy
The first part of the code if(!$_GET[value] || $_GET[value] == "") etc. translates into english as:
If there is no ?value after index.php in the url OR (||) ?value is equal to nothing print the news page.
The second part after the else statement translates into english as:
If ?value is equal to something then strip anything other than the name of the file away from that value and include the php file with that name.
The reason you do an htmlspecialchars(); is so that people can't inject some nasty code into your url and take down your website or even worse steal information from you. Hope that helps out.
<?php
if(!$_GET[value] || $_GET[value] == "") {
include ("news.php");
} else {
$someval = htmlspecialchars($_GET['value']);
include($someval . ".php");
}
?>
Now granted, jimmy's version checks to see if a file exists before you include it, it's pretty hard to understand. To explain my code is easy
The first part of the code if(!$_GET[value] || $_GET[value] == "") etc. translates into english as:
If there is no ?value after index.php in the url OR (||) ?value is equal to nothing print the news page.
The second part after the else statement translates into english as:
If ?value is equal to something then strip anything other than the name of the file away from that value and include the php file with that name.
The reason you do an htmlspecialchars(); is so that people can't inject some nasty code into your url and take down your website or even worse steal information from you. Hope that helps out.
#8
Posted 28 June 2008 - 07:12 AM
Youre right. The code you gave is easier to understand for a beginner.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
