Need help with my php code.
PHP Code:
<?php
$pages_dir = 'pages';
if (!empty($_GET['id'])) {
$pages = scandir($pages_dir, 0);
unset($pages[0], $pages[1]);
$id = $_GET['id'];
if (in_array($id.'.inc.php', $pages)) {
include ($pages_dir.'/'.$id.'.inc.php');
} else {
echo 'Sorry, Page not found!';
}
} else {
include($pages_dir.'/home.inc.php');
}
?>
I wanna make my page script write a .txt file to log the IP/Date/Times someone has reached the Sorry, Page not found!
My old coder is unable to be reached to get this done anyone able to help me ?
Re: Need help with my php code.
Use file_put_contents()
Example:
PHP Code:
<?php
$pages_dir = 'pages';
if (!empty($_GET['id'])) {
$pages = scandir($pages_dir, 0);
unset($pages[0], $pages[1]);
$id = $_GET['id'];
if (in_array($id.'.inc.php', $pages)) {
include ($pages_dir.'/'.$id.'.inc.php');
} else {
echo 'Sorry, Page not found!';
$file="yourfilename";
$content=$_SERVER['REMOTE_ADDR']."| ".time();
file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
}
} else {
include($pages_dir.'/home.inc.php');
}
?>
Re: Need help with my php code.
@waddle1463 Works good i made a change to it so it displays the Month, Day, Year & Time just so i could understand the log better works good though thanks alot ! I shall +REP YOU!
Re: Need help with my php code.
I'm glad it works! If you need help with displaying month and year, php.net has a good overview here