|
-
Aug 2nd, 2012, 03:27 PM
#1
Thread Starter
New Member
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 ?
-
Aug 3rd, 2012, 12:06 AM
#2
New Member
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');
}
?>
Last edited by waddle1463; Aug 3rd, 2012 at 11:14 PM.
-
Aug 3rd, 2012, 01:19 AM
#3
Thread Starter
New Member
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!
Last edited by PhiberOpitcs; Aug 3rd, 2012 at 01:21 AM.
Reason: Spelled Shall wrong...
-
Aug 3rd, 2012, 11:10 PM
#4
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|