Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

80 users online



PHP Including

PHP Including

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 3
Agatio

Agatio

Neversidian
Status: Offline!

PHP Including

Ok, I have noticed some sites have their links as:

www.domain.com/index.php?page=site/links

And I think it's using the include command so when you click this link, it replaces the current content with site/links. Now, I know I'm just confusing people here, but I woul like to get this cleared up. So basically, when you lcik that link, the PHP engine finds:

www.domain.com/site/links

And loads it into the content area of the site. Replacing what was originally there, be it news, or some other content. So, if anyone understands that, can you tell me the PHP to insert into my pages, and how to insert it.

But first, I need a yes or no answer for this question.

"Does this require a database?"

Ok, well, I sure hope someone here can help me clear this up, as it seems to be a great help for managing sites, and mine is currently using around 80 text files with the include command at the top and bottom, anyway. Yeah, so, help me please Grin

Agatio.

Natural

Natural

Status: Offline!

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

Natural

Natural

Status: Offline!

just on a side note that site is really poorly made. its got html pages, cold fusion pages, php pages, and crappy url rewriting

Agatio

Agatio

Neversidian
Status: Offline!

Domain.com???
I was just using that as an example.
And I know the syntax for the include command, you really didn't read my post did you?

ShaunTobias

ShaunTobias

Neversidian
Status: Offline!

I don't know anything about .htaccess but I think that has something to do with how it's done so if you look that up or maybe somebody else here knows...

I think theres been a post about this recently

___________________

STphp - Modern Web Solutions - CLOSED
ShaunTobias.co.uk - Blog and Portfolio - CLOSED

Look out for LookCreative.co.uk in September.

Agatio

Agatio

Neversidian
Status: Offline!

Well I'm too lazy to look through other threads, and they probably aren't asking exactly what I am.

nertman

nertman

lurker
Status: Offline!

you want to have dynamic switches or includes is what your looking for i believe with your urls like:
domain.com/?id=somepage
or
domain.com/index.php?id=somepage
or
domain.com/somepage.php?id=somepage

well if you was to search the forums for stuff about it you'll find hundreds of ways to do this you can use a database or flatfiles to include your pages here is my code i use to include my flatfiles can be found at this thread http://www.tutorialforums.com/showthread.php?s=&threadid=87335

ShaunTobias

ShaunTobias

Neversidian
Status: Offline!

^ hes not looking for that. hes looking for a way to include say about.php when he goes to

http://www.site.com/about/

___________________

STphp - Modern Web Solutions - CLOSED
ShaunTobias.co.uk - Blog and Portfolio - CLOSED

Look out for LookCreative.co.uk in September.

MinDFreeZ

MinDFreeZ

Status: Offline!

has something to do with mod_rewrite .. I've never done it, but have read about making "user friendly urls" .. google mod_rewrite and friendly urls... sorry I can't help :confused:

-- "Does this require a database?"
no, a .htaccess file and PHP I believe.

___________________

http://www.enhancedps.com/images/random/crap/sig.gif

Avantasia

Avantasia

Neverside Newbie
Status: Offline!

Hey, I have a solution to what I believe your problem is, but there has been a lot of confusion in the thread, so i'll re-write the problem specification first, if it IS what you want to do, read the solution, otherwise, may as well ignore it.

Problem: [i]I want to use the 'include' command to display files within a php page, dependent on appended links (ie index.php?[some code]).[/i]

Solution:

[i]First of all, lets start off with the main file.

On this sort of dynamic website, each logical 'section' of your website (we'll only use one in this example) only has one 'page' that is viewed. We'll call this [b]index.php[/b]. This page may or may not have any [/i]static [i] html, but let's assume you have two things that will change depending on the 'extra stuff' in your links.

This means that no matter what, the user will always be on [b]index.php[/b]. So to change the content on each site, we make use of what are called appended links. Appended links consist of a domain, path and then 'extra' stuff. Like:

[url]www.mySite.com/index.php?id=home[/url]

The path is [b]/index.php[/b] and the extra stuff is [b]id=home[/b]. The extra stuff is added on with the use of a question mark.

To make the page, first off create an HTML page, so you know where everything will go and how it all fits together. Then find an area where you want the content to change. This is normally inside a specific table cell or specific div in pages, if you use them, but it can be anywhere.

Now, look at this section where the content will change, create three separate php files, and in one of them, copy the content that is CURRENTLY in this section. Then write two alternative pieces of content to go in this section. Put them one in each file. (note: the content in these files, can be fully HTML formatted but often it is also just text. Do not put any <html> or <body> tags or anything in it though).

So now you have three pages of content, and an empty content section in your main page. This is where we bring in the link to the page. In the link I posted above, you might have noticed that id=home, almost looks like a variable, but without the $. That's because it is a variable, you can access this variable in your program simply by using $id.

Notice in the link in your browser at the moment, there is a variable 'threadid=87493', to access this in the page, you just use $threadid.

It should now be pretty obvious what you're going to do. It's up to you whether you use [b]switch[/b] or a series of [b]if[/b statements.

Although I would use switch, more people know about if than switch, so i'll use if.

Now, go to the 'content' section of your index.php page that you found earlier. Insert code like this:

[PHP]<?php
$id=$_GET['id'];

if($id=='home') { include("file1.php"); }
else if($id=='news') { include("file2.php"); }
else if($id=='help') { include("file2.php"); }
?> [/PHP]

That's a nice simple version of it. And i'm sure you can work with that to make dynamic pages, but i'll say one more thing about it.

What if the user just goes to [url]http://www.mySite.com[/url] ? The server will (if it's set up that way) default to index.php, but as you can see there is no variable there, so we can modify this program to check if the variable $id has been set. If it has not, we'll include file1.php.
[PHP]
<?php
$id=$_GET['id'];
if(!isset($id)) //if $id has not been set
{
include("file1.php");
}
else if($id=='news') { include("file2.php"); }
else if($id=='help') { include("file3.php"); }
?>
[/PHP]

[/i]

Ok, well I would go on, but I don't even know if that was the question you were asking. If it was, then I hope it helped and feel free to ask questions, if it wasn't, then...oops ::classic:

Edit: If you want to use more than one variable in a link, separate them with & like so:

index.php?id=home&password=bobsyouruncle


Edit#2: Yeah, it doesn't necessarily have anything to do with a database, although you can use them if you want, like:
[PHP]
<?php
$id=$_GET['id'];

$connection=mysql_connect("localhost","averagewhiteband","towerofpower");
$select_database=mysql_select_db("stevie_wonder");

$query=mysql_query("SELECT*FROM pages WHERE page_name=$id");

$page=mysql_fetch_array($query);

if(!isset($id)) { echo "This is default content...do what you like here"; }
else { echo $page; }

?>
[/PHP]

Sorry if some of the database stuff there is wrong....lol, it's been a while since i've done any real PHP.
else:rolleyes:

Edit#3: I added $_GET into the equation, as ShuanTobias reminded me that global vars may be switched off on some servers. You can find out if yours are or not by using phpinfo.

Last edited by Avantasia, December 8th, 2004 01:57 AM (Edited 1 times)

Page 1 out of 3
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0097 seconds.