SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    The Omnipresent [ArcanE]'s Avatar
    Join Date
    Mar 2005
    Location
    Belgium
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    script executed 2 times when using header()

    Anyone has an idea why the query in the following code gets executed 2 times and when i comment out the header() functions at the bottom it just executes one time as it should?

    PHP Code:
    <?php
    session_start
    ();

    error_reporting(1);
    ini_set('display_errors'1);

    /**
     * Location Detection Functions
     */
        
    function http_get$url ) {
          
    $request fopen$url"rb" );
          
    $result false;
        
          while( !
    feof$request ) ) {
            
    $result .= fread$request8192 );
          }
        
          
    fclose$request );
        
          return 
    $result;
        }
        function 
    get_tag_contents$xml$tag ) {
          
    $result "";
          
    $s_tag "<$tag>";
          
    $s_offs strpos$xml$s_tag );
        
          
    // If we found a starting offset, then look for the end-tag.
          //
          
    if( $s_offs >= ) {
            
    $e_tag "</$tag>";
            
    $e_offs strpos$xml$e_tag$s_offs );
        
            
    // If we have both tags, then dig out the contents.
            //
            
    if( $e_offs >= ) {
              
    $result substr(
                
    $xml,
                
    $s_offs strlen$s_tag ),
                
    $e_offs $s_offs strlen$e_tag ) + );
            }
          }
        
          return 
    $result;
        }
        function 
    get_location_xml$ip ) {
          return 
    http_get"http://api.hostip.info/?ip=$ip);
        }
        
        function 
    parse_city$location ) {
          
    $contents get_tag_contents$location"Hostip" );
          
    $city trimget_tag_contents$contents"gml:name" ) );
        
          
    // If the city couldn't be found, it'll contain the word "private".
          //
          
    if( stristr$city"private" ) ) {
            
    $city "";
          }
        
          return 
    $city;
        }
        
        function 
    parse_country$location$default "BE" ) {
          
    $contents get_tag_contents$location"Hostip" );
          
    $country trimget_tag_contents$contents"countryAbbrev" ) );
        
          
    // If the country couldn't be found, default to $default.
          //
          
    if( stristr$country"xx" ) ) {
            
    $country $default;
          }
        
          return 
    $country;
        }

    /**
     * Main
     */
    define ("ROOT"$_SERVER['DOCUMENT_ROOT']);
    $filename =      base64_decode($_GET["file"]);
    $filepath ROOT.base64_decode($_GET["file"]);
    $id = (isset($_GET['id'])) ? $_GET['id'] : 0;

    $file_bits explode("."$filepath);
    $file_extension $file_bits[count($file_bits)-1];

    // Define file mime type
    switch( $file_extension ) {
        case 
    "gif"$ctype="image/gif"; break;
        case 
    "png"$ctype="image/png"; break;
        case 
    "jpeg":
        case 
    "jpg"$ctype="image/jpg"; break;
        default: 
    $ctype="application/force-download";
    }
      
    $fileData['url'] = $filename;
    $fileData['len'] = filesize($filepath);
    $fileData['ext'] = $file_extension;
    $fileData['ctype'] = $ctype;

    include(
    "webadmin/includes/config.php");
    include(
    "webadmin/includes/connect.php");
    /*
    // ADODB DATABASE CLASS
    require_once("includes/adodb/adodb.inc.php");
    $db = ADONewConnection('mysql');
    $db->debug = false;
    $db->Connect($server, $user, $pass, $dbnaam);
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    */

    // Detect the users location
    $ip $_SERVER['REMOTE_ADDR'];
    $locationXml get_location_xml($ip);
    if (
    $locationXml != "") {
        
    $location "'".parse_country($locationXml)."'";
    } else {
        
    $location NULL;
    }

    // Update the database with an impression
    //$result = $db->Execute("INSERT INTO banners_".$_SESSION['lang']."_stats (banner_id, ts_impress, localisation, ip) VALUES (".$id.", ".time().", ".$location.", '".$ip."' )");
    $result mysql_query("INSERT INTO banners_".$_SESSION['lang']."_stats (banner_id, ts_impress, localisation, ip) VALUES (".$id.", ".time().", ".$location.", '".$ip."' )");

    /*
    header("Content-type:  ".$fileData['ctype']."");
    header("Content-Length: ".$fileData['len']."");
    readfile($filepath);
    */
    ?>
    Webdevelopment : Skyrocket Concepts Inventis Web Architects
    Ain't got time for the future or the past.
    Live for the moment, make it last.

  2. #2
    The Omnipresent [ArcanE]'s Avatar
    Join Date
    Mar 2005
    Location
    Belgium
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think i found it, when requesting the script directly in a browser the script gets executed 2 times i suppose since when i use the script url as a src="" in an image it only executes 1 time.
    Webdevelopment : Skyrocket Concepts Inventis Web Architects
    Ain't got time for the future or the past.
    Live for the moment, make it last.


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
  •