GetDotted Domains

Viewing Thread:
"The PHP Include tag"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Tue 12/02/02 at 22:29
Regular
Posts: 787
Hiya. You know that PHP Include tag? Well, how does it work? I can do it so that it references a seperate file, but can I give it a name and a URL like 'www.mysite.com/myfile.php?referencedid=data'. Do you know what i mean, or am I just jibba jabbering about?
Fri 15/02/02 at 10:50
Regular
"Pouch Ape"
Posts: 14,499
Excellent, it works! Cheers CJH! Oh boy, that's useful.
Thu 14/02/02 at 18:31
Regular
"Eff, you see, kay?"
Posts: 14,156
You don't even need the .inc on it:


if (!ereg(".inc$", $File)) {
$File .= ".inc";
}

..::STUFF::..

?>

*cough*

:)
Wed 13/02/02 at 18:48
Regular
"It goes so quickly"
Posts: 4,083
... and if you can, let me know if they work ok :o).
Wed 13/02/02 at 18:46
Regular
"It goes so quickly"
Posts: 4,083
thats cool :o)

Alternativly, try this:

using the same $File in the Web Address, but including the whole file you want to include:

http://www.yoursite.com/index.php?File=Page1.inc
http://www.yoursite.com/index.php?File=Page2.inc
http://www.yoursite.com/index.php?File=Page3.inc
etc...

and try use this:

if (file_exists("$File")) {
include("$File");
} else {
include("index.inc");
}
?>

It checks the file is there first and includes it, but if it's not there (for whatever reason) the index is shown :o)

If thats any better, and easier to understand, not to mention less to write when adding new pages, then use that :o)
Wed 13/02/02 at 18:42
Regular
"Pouch Ape"
Posts: 14,499
Cheers, that was really useful. Nice one!
Wed 13/02/02 at 18:39
Regular
"It goes so quickly"
Posts: 4,083
Sorry I didn't write the example in my last post, but I was in college, and just wanted to make sure what I wrote was correct. Didn't want you using something that I wrote wrong :o).


Lets just say that your links were set up with the $File as the variable.

http://www.yoursite.com/index.php?File=Page1
http://www.yoursite.com/index.php?File=Page2
http://www.yoursite.com/index.php?File=Page3
etc...

and your files which your including are in the same location as the index.php file(ie the htdocs folder)

have this type of code in the index page:

switch($File) {
case "Page1" :
include("Page1.inc");
break;
case "Page2" :
include("Page2.inc");
break;
case "Page3" :
include("Page3.inc");
break;
default:
include("index.inc");
}
?>

The $File is used to checked and if a match is found, the specified include is used, if no match is found, the default is used, which is likely to be your index file anyway.

For this example, i've assumed that your extra files that you want to include are .inc files, as in include files, but you can have any file type you like: .html, .htm, .php etc...


Hope that was clear enough for you to understand, if not, let me know and I'll try again :o)
Wed 13/02/02 at 16:21
Regular
"Pouch Ape"
Posts: 14,499
Yeah, that would be useful. I don't really use PHP that much, but I can see how useful it is.
Cheers
Wed 13/02/02 at 13:03
Regular
"It goes so quickly"
Posts: 4,083
Yeah you can do that I think (if I think you mean what you mean)

You could use what Turbo said, or a little mor complex, but with the IF or SWITCH statments thing.

I'll write an example of a switch later if you want one.
Wed 13/02/02 at 09:27
Regular
"Pouch Ape"
Posts: 14,499
Er...yeah, i think so. Can you set the $file from a link to that page?
Wed 13/02/02 at 00:42
Regular
"Eff, you see, kay?"
Posts: 14,156
Er...

Um...

I think so. Just set the file to reference as $file, call index.php as index.php?file=foo, and put in index.php

Is that it?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Just a quick note to say thanks for a very good service ... in fact excellent service..
I am very happy with your customer service and speed and quality of my broadband connection .. keep up the good work . and a good new year to all of you at freeola.
Matthew Bradley
Everybody thinks I am an IT genius...
Nothing but admiration. I have been complimented on the church site that I manage through you and everybody thinks I am an IT genius. Your support is unquestionably outstanding.
Brian

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.