Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342

    I am having a problem with PHP-Please Help(easy

    This is what the file support to do:

    Get a Banner ID (randomly).
    check if it is there
    if it is, check its limitation and if is able to be views (else do again).

    if it is ok, read its info from a file, save it

    then read its stats (not saving it, but save the other stats for other banners)..

    Read in the stats, and then update them

    read them back in.


    Everything seems to be ok, except 2 things:

    1) it makes a new line after each reading (not a problem)
    2) whenever the banner id is 2 , it erases the stats for banner id 0?--->Big problem

    Thanks For Helping out guys,

    PHP Code:

    <?php 

    //Select ALL Banners
    $fp = @fopen("files/bannerlist.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/bannerlist.txt</font>' );
    $data fread($fpfilesize($fp));
    $num NULL;
    while(!
    feof($fp)) {
        
    $stats fgets($fp1024);
        
    $tempme explode('|',$stats);
        if(
    $tempme[2] != NULL){
        
    $num++;
        }
    }
    fclose($fp);
       
    //Select Numbers Of All Banners

    //If No Banner Exists, Show Nothing
    if($num == NULL){
    header ("Location: index.php");
    exit();    
    }

    ?>
    <script type="text/javascript" language="JavaScript1.2" src="status.js"></script>

    <? 
    //Select A Banner randomly
    $isgood 1;
    //This will only do the loop 100 times or until a banner is good.
    // It is always recommened to delete banners if you dont want to view them
    $count 0;

    while(
    $isgood == && $count != 100){
        
        
    //Check if the count is already up
        
    $count $count +1;
        
    srand(time());
        
    $random = (rand()%$num);

        
        
    $fp = @fopen("files/bannerlist.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/bannerlist.txt</font>' );
        
    $data fread($fpfilesize($fp));
        while(!
    feof($fp)) {
            
    $stats fgets($fp1024);
            
    $thero explode('|',$stats);
                if( 
    $tempme[0] == $random && $tempme[0] != NULL){
                    
    $thero explode('|',$stats);
                    
    $getinfo $stats;
                }
        }
        
    fclose($fp);
        
        if(
    $thero[5] == 'OFF'){
            
    $isgood 0;
        }
            
        
    $fp = @fopen("files/stats.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/stats..txt</font>' );
        
    $data fread($fpfilesize($fp));
        while(!
    feof($fp)) {
            
    $statsit fgets($fp1024);
            
    $thero explode('|',$statsit);
                if( 
    $tempme[0] == $random && $tempme[0] != NULL){
                    
    $newrow explode('|',$statsit);
                }
        }
        
    fclose($fp);
        
        
    $hits1 $newrow[6];
        
    $views1 $newrow[8];
        
    $todayis date('m') . '/' date('d') . '/' date('Y');
        
        if(
    $isgood == true){
            
    $breakit explode(',',$thero[5]);
            
    $part1 $breakit[0];
            
    $part2 $breakit[1];
        
        if(
    $part1 == 'V'){
            if(
    $part2 $views1){
                
    $isgood 0;
                
            }    
        } else {
            if(
    $part1 == 'H'){
                if(
    $part2 $hits1){
                    
    $isgood 0;
                    
                }
            } else {
                if(
    $part1 == 'D'){
                    
    $off false;
                    
    $rowd explode('/',$part2);
                    
    $month $rowd[0];
                    
    $day $rowd[1];
                    
    $year $rowd[2];
                    
    $myday date('d');
                    
    $mymonth date('m');
                    
    $myyear date('Y');
                    
                    if(
    $myyear == $year){
                        if(
    $mymonth == $month){
                            if(
    $myday == $day){
                                
    $off true;
                                
                            }
                        }
                    }
                    
                    if(
    $off == false && $myyear $year){
                        
    $off true;
                        
                    }
                    
                    
                    if(
    $off == false && $mymonth $month && $myyear >= $year){
                        
    $off true;
                        
                    }
                    
                    if(
    $off == false && $myday $day && $mymonth >= $month && $myyear >= $year){
                        
    $off true;
                        
                    }
                    
                                    
                    if(
    $off == false){
                        
    $isgood 0;
                    }
                    
                }
            }    
        }
    }
            
    }    


    if(
    $count != 100 && $isgood == 0){
    //Check if user is unique or not
    $isit 0;
    $ip $_SERVER['REMOTE_ADDR'];

    $fp = @fopen("files/ips.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/ips.txt</font>' );
        
    $data fread($fpfilesize($fp));
        while(!
    feof($fp)) {
            
    $isip fgets($fp1024);
                
    $ipis explode('|',$isip);
                if( 
    $ipis[0] == $ip && $ipis[0] != NULL){
                    
    $isit 1;
                    
                }
        }
    fclose($fp);

    if(
    $isit == 0){
        
    $unique true;
        
    //Insert Ip Into List (after saving it)
        
    $fp = @fopen("files/ips.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/ips.txt</font>' );
        
    $data fread($fpfilesize($fp));
            while(!
    feof($fp)) {
                
    $temips fgets($fp1024);
                
    $temptheip explode('|',$temips);
                    if(
    $temptheip[0] != NULL){
                        
    $iplist .= $temips;
                        
                    }
            }
        
    fclose($fp);

        if(
    $iplist == NULL){
            
    $iplist .= $ip '|X';
        } else {
            
    $iplist .=  "\r\n" .  $ip '|X';
        }

        
    $Open = @fopen("files/ips.txt""w")  or die($fileerror ':<font color="red"> ' 'files/ips.txt</font>' );
        
    fwrite ($Open$iplist);
        
    fclose($Open);
    }

    echo 
    $random '--';
    //Edit The Banner Stats
    $fp = @fopen("files/stats.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/stats.txt</font>' );
    $data fread($fpfilesize($fp));
        while(!
    feof($fp)) {
            
    $tempstat fgets($fp1024);
            
    $tempit explode('|',$tempstat);
                if(
    $tempit[0] != NULL && $tempit[0] == $random){
                    
    $row explode('|',$tempstat);
                    
                } else {
                    
    $newtoadd .= $tempstat;
                    echo 
    $tempstat;
                }
        }
    fclose($fp);


    //Get width & Heigth

    $made $row[1];
    $location $row[2];
    $width $row[3];
    $length $row[4];
    $hits $row[5];
    $uni_hits $row[6];
    $views $row[7];
    $uni_views $row[8];
    $views $views +1;

    if(
    $unique == true){
        
    $uni_views $uni_views +1;
    }
    //Insert Back In



    if($newtoadd == NULL){
        
    $newtoadd .= $random '|' $made '|' $location '|' $width '|' $length '|' $hits '|' $uni_hits '|' $views '|' $uni_views;    
    } else {
        
    $newtoadd .=  "\r\n" $random '|' $made '|' $location '|' $width '|' $length '|' $hits '|' $uni_hits '|' $views '|' $uni_views;    
    }



    $Open = @fopen("files/stats.txt""w")  or die($fileerror ':<font color="red"> ' 'files/stats.txt</font>' );
    fwrite ($Open$newtoadd);
    fclose($Open);
        
        
    //Get Banner Information
    $fp = @fopen("files/options.txt""r+")  or die($fileerror ':<font color="red"> ' 'files/options.txt</font>' );
    $data fread($fpfilesize($fp));
    while(!
    feof($fp)) {
        
    $options fgets($fp1024);
    }
    fclose($fp);

    $myrow explode('|',$options);
    $overalljava $myrow[0];

    $row explode('|',$getinfo);
    $id $row[0];
    $openmode $row[7];

    if(
    $row[2] == 'NONE'){
        
    $mouseover '';
    } else {
        
    $mouseover $myrow[2];
    }

    $location $row[3];
    $urlto $row[4];

    //Check if Java On

    if($row[6] == 'OFF' || $overalljava == 'NA'){
        
    $javait NULL;    
    } else {
        
    $javait ' onMouseOver="return visit()" onMouseOut="return clearit()" ';
    }

    // Check Size
    if($width == 'NA' || $length == 'NA'){
        
    $dosize NULL;
    } else {
        
    $dosize 'width="' $width '" height="' $length '"';
    }

    $link 'href="catchadd.php?id=' $id '" target="' $openmode '"' $javait;


    ?>

    <a <? echo $link;?> ><img src="<? echo $location;?>" alt="<? echo $mouseover;?><? echo $dosize;?> border="0"></a>
    <? ?>

  2. #2
    Join Date
    Jan 2003
    Posts
    1,715
    With no comments and lousy variable names (tempme and threo mean very little to me), it's difficult to say what is and is not a bug. For instance, you pick a row based on the row count here:
    $random = (rand()%$num);

    But you search for the selected banner by first column:
    if( $tempme[0] == $random && $tempme[0] != NULL)

    That could lead to some interesting behavior if the banner list is not in precisely 1...n order. You also load $data, but don't seem to use it. Those situations also create race conditions where you blank files that concurrently running copies may be reading (thus they will load a 0-byte copy).

    Learn SQL. Forget this mess. This takes about 2-3 SQL queries and the SQL server will eliminate most of the pitfalls you've stumbled into.
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

  3. #3
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    i already did it with mysql....... im trying to do it in files...

    ur right i did use very lousy veriables ( i thought i was the only one to look at it)..

    i was about to rephrase them when im done...

    This is how the bannerlist.txt is formatted:

    0|Banner Text|Banner Mouseover|Banner Location|Banner URLTO|Banner ....

    The stats file also start the same thing, except with different info...

    0|Banner name|.....

    What i did first with
    $random = (rand()%$num);
    is to select the number of banenrs there is ($num), then pick one out randomly.

    This:
    if( $tempme[0] == $random && $tempme[0] != NULL)
    Checks if the banner id retreived from the list is the one picked randomly, so i can check if i am allowed to view it.

    Sorry again for such slopy code :$

  4. #4
    Join Date
    Mar 2003
    Location
    VA
    Posts
    640
    I am not sure if this what you're trying to get at or not...

    PHP Code:
    $random = (rand()%$num);
    $bfile "files/bannerlist.txt";
    $cfile file($bfile);
        
    while(list(,
    $value) = each($cfile)) {
        list(
    $id,$b_text,$b_mover,$b_location,$b_urlto) = split("|"$value);
        if (
    $id == $random && $id != NULL) {
            
    // print "your banner stuff";
        
    } else {
            
    // print "invalid or some error message";
        
    }


Posting Permissions

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