Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: GZip Script

  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts

    GZip Script

    I found a script online that I'm trying to modify, and I've run into a problem:

    It also prints "Bad Dog. No Bone for You." even when there is a file with the specific name in the URL. For example, I have the file style.css, and with the address of jstyle.php?f0=style.css I still get the die() message.
    PHP Code:
    <?php
    // GZIP JAVASCRIPT + CSS 1.2
    // 6/26/2012
    // © Jason Stockton 2008
    // http://mooglemedia.com.au
    // http://thewebdevelopmentblog.com/
    // PHP 5+ ONLY
    $content="";
    $expires intval(3);
    if(isset(
    $_GET["ex"])) {
    $expires intval($_GET["ex"]);
    }

    if(
    $expires==0){
    $baddog=1;
    }

    for(
    $i=0$i<10$i++) {
        
    $file=$_GET["f$i"];
        if(isset(
    $file)){
            if(
    file_exists($file)){
                
    $ext strtolower(substr($filestrrpos($file".")));
                if(
    $ext==".css" || $ext==".js"){
                    
    $content.= file_get_contents($file);
                    
    $mytype=$ext;
                }
            }
            else{
                
    $content.="// FILE NOT FOUND '$file'\n\n";
            }
        }
        else{
        
    $nofilenamed=1;
        }
    }

    if(isset(
    $_GET["c"])) {
    $expiresOffset=3600 24 $expires;

    else{
    $expiresOffset=20;
    }

    if(
    $mytype==".css"){
    $type="text/css";

    elseif(
    $mytype==".js"){
    $type="text/javascript";

    else{
    $baddog=1;
    }

    if(
    $baddog==|| $nofilenamed==1){
    die(
    "Bad Dog. No Bone for You.");
    }

    header("Content-type: $type; charset: UTF-8");
    header("Cache-Control: public");
    header("Content-Encoding: gzip");
    header("Expires: " gmdate("D, d M Y H:i:s"time() + $expiresOffset) . " GMT");
    $compressed gzencode($content9FORCE_GZIP);
    echo 
    $compressed;
    ?>
    I removed the $nofilenamed from the if statement and it shows the proper css file. So that would mean the portion of the script that has an issue is here:

    PHP Code:
    for($i=0$i<10$i++) {
        
    $file=$_GET["f$i"];
        if(isset(
    $file)){
            if(
    file_exists($file)){
                
    $ext strtolower(substr($filestrrpos($file".")));
                if(
    $ext==".css" || $ext==".js"){
                    
    $content.= file_get_contents($file);
                    
    $mytype=$ext;
                }
            }
            else{
                
    $content.="// FILE NOT FOUND '$file'\n\n";
            }
        }
        else{
        
    $nofilenamed=1;
        }


    EDIT: The issue is $nofilenamed is being set to 1 when I'm calling anything less than 10 files. How can I count the amount of f$i in the url and only loop through amount found?
    Last edited by HDRebel88; 06-26-2012 at 01:04 PM.

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Does anybody see any potential issues with this?

    PHP Code:
    $query_string=$_SERVER['QUERY_STRING'];
    $position=strripos($query_string"&f");
    if(
    $position===false){
    $count=1;
    }
    else{
    $sub=substr($query_string$position+2);
    $count=intval($sub)+1;
    }

    for(
    $i=0$i<$count$i++) {
    // code 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
    •