Results 1 to 2 of 2

Thread: Problem With Date() and If Function

  1. #1
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Problem With Date() and If Function

    In my script I need to check the time but it for some reason it totally forgets the whole thing. Hope this makes sense what I am asking! Here is my script:

    PHP Code:
    <?php
    ignore_user_abort
    (true);
    set_time_limit(70000000000000000000000000000000000);

    error_reporting(0);
    $time=date('g A');
    $directory 'users/';
    if (
    $handle opendir($directory)) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
    $file preg_replace('/(.*)\..*/''$1'$file);

    $fp=fopen("$file/log.txt","r");        //Opens the Pass.txt file
    $date=fgets($fp);    

    $fp=fopen("$file/email.txt","r");        //Opens the Pass.txt file
    $newemail=fgets($fp);    

    $newdate=$date-3;
    $today=date('d');

    if (
    $time "3 am") {

    if (
    $date== $today-4) {.........

            }
    }
            }
        }
        
    closedir($handle);
    }
    ?>

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    <?php 
    // why are you doing this?
    ignore_user_abort(true); 
    // same question?
    // your web host will probably kill the script if it takes close to this long anyway.
    // at least, I'd hope they would;
    // otherwise you might hang the server if someone kept clicking "refresh."
    set_time_limit(70000000000000000000000000000000000); 

    // this is a big problem right now -
    // something is going wrong, and you can't find out what it is
    // because you're suppressing all errors.
    // remove this (or set it very high) and see what you get.
    // error_reporting(99999999); 

    $time=date('g A'); 
    $directory 'users/'
    if (
    $handle opendir($directory)) { 
        while (
    false !== ($file readdir($handle))) { 
            if (
    $file != "." && $file != "..") { 
                
    $file preg_replace('/(.*)\..*/''$1'$file); 
                
    // are you trying to use the $file variable you created above?
                // if so, don't "quote" the variable name
    //          $fp=fopen("$file/log.txt","r");
                
    $fp=fopen($file."/log.txt","r");
                
    $date=fgets($fp);
                
    // same deal
    //          $fp=fopen("$file/email.txt","r");
                
    $fp=fopen($file."/email.txt","r");
                
    $newemail=fgets($fp);  
                
    $newdate $date 3;
                
    $today=date('d'); 
                
    // here, you are *setting* $time, _not_ *comparing* $time.
    //          if ($time = "3 am") { 
                // I assume you meant to do this:
                
    if( $time == "3 am" ){
                     if (
    $date == $today 4) {/*....do whatever.....*/
                } 
            } 
       } 
       
    closedir($handle); 

    ?>
    It looks like this is only part of the code you're working with - it doesn't seem to do anything, and leaves several things unused. Also, though I have no real idea of what you're trying to do, I'm sure there's an easier way to do it.
    (I am curious as to what you can only do at 3am, four days after you did it last.)

    Perhaps you could explain what you're trying to accomplish?
    Last edited by traq; 08-15-2011 at 02:31 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •