Hello guys. 🙂
I hope you can help please.
I have the following script, which is a Contact page. When first loaded, it lists the members of staff, and then has links to the same page, with a numeric ID for their profile. Their profile is stored as a .html file in a 'staffinfo' directory.
For example, the /staff/index.php?id=2 will load 2.html from the 'staffinfo' directory to be loaded.
This works perfectly, however we want to change it a bit.
Instead of numeric Id's, we want names. Let's take the name Bob.
How can we make it so we can use /staff/index.php?name=Bob, and it would load a Bob.html from 'staffinfo' directory? Yep, with name= too instead of id=..
Current code, could we add an array for the staff names (hard-coded):
<?php
include_once('/home/me/htdocs/header.php');
$id = (int)$_GET['id'];
if ($id <= 13 && $id >= 1) {
$info = "/home/me/htdocs/staffinfo/$id.html";
if (file_exists($info)) {
readfile($info);
} else {
echo "<p class=\"pagetitle1\">Sorry, that staff ID does not exist. Please try again.</p>\n";
}
}
else {
?>
Staff list here.
<?php
}
include_once('/home/me/htdocs/footer.php');
?>
Many thanks!