PDA

View Full Version : apply function to other page


weronpc
06-02-2003, 07:00 PM
I created a function called replacement(). It replaces bad keys from user's input. such as key < or > or $

I have to pass a variable (contains bad keys) and the function will return a variable (contains replaced keys)

anyway, my question is, can I save this function in a text file and call it when I need it? I try to use include 'filename.inc' but it doesn't work properly.

Thank you for you help

Spookster
06-02-2003, 07:37 PM
You can define the function in an external file but I would put it in a file with a .php extension. More secure that way.

As for using the external file you need to enclose the code inside <?php ?> tags:


Example:

functions.php


<?php

function getIPAddress(){
return $_SERVER['REMOTE_ADDR'];
}

?>




In your page you would use it like so:

index.php


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

<html>
<head>
<title>My Page</title>
</head>
<body>

<?php
echo getIPAddress();
?>

</body>
</html>