...

View Full Version : how to add a file to this script?



googleit
08-27-2006, 07:00 PM
hi
this is my code wich when i type myfile.php?action=blahblah
i will display the content in the code

<?
$action = $_GET['action'];

function test() {
echo '<a href="index.php"><font colour="#FFFFFF">home</font></a>
blah blah blah';
}
if ($action == "test") {
test();
}
?>
this works fine but i want to include a file so instead of having to type all of the content in the code it will be in that file

Sayonara
08-27-2006, 07:35 PM
If you mean you want to save the function in a separate file and include it into your script, you need to use include_once() or require_once()

If that is not what you mean, you will have to rephrase the question, because it is very vague.

http://uk.php.net/include_once

thunderhoster
08-27-2006, 08:55 PM
Create a file, let's say include.php with your content:


<?php

function test() {
echo '<a href="index.php"><font colour="#FFFFFF">home</font></a>
blah blah blah';
}

?>
And then, your index.php would look like:


<?php
include 'include.php';

$action = isset($_GET['action']) ? $_GET['action'] : ""; //-- To avoid undefined variable notices

switch ($action) {
case "test" : {
test();
}break;
}
?>

googleit
08-27-2006, 08:58 PM
thanks
what i was looking for :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum