Results 1 to 4 of 4

Thread: Need help with my php code.

Hybrid View

  1. #1
    New Member
    Join Date
    Jul 11
    Posts
    3

    Need help with my php code.

    PHP Code:
    <?php
    $pages_dir 
    'pages';
    if (!empty(
    $_GET['id'])) {

    $pages scandir($pages_dir0);
    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 ?

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    12

    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_dir0); 
    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$contentFILE_APPEND LOCK_EX);



    } else { 
    include(
    $pages_dir.'/home.inc.php'); 



    ?>
    Last edited by waddle1463; Aug 3rd, 2012 at 11:14 PM.

  3. #3
    New Member
    Join Date
    Jul 11
    Posts
    3

    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...

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    12

    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
  •