2016-12-02 1 views
0

추적 픽셀에서 작업하고 있는데, 요청자의 IP와 다른 정보를 HTML 파일에 기록 할 예정이지만 html 파일은 생성되지 않으며 생성하면 그대로 유지됩니다. 빈.PHP로 파일에 작성하기

<?php 

    // Create an image, 1x1 pixel in size 
    $im=imagecreate(1,1); 

    // Set the background colour 
    $white=imagecolorallocate($im,255,255,255); 

    // Allocate the background colour 
    imagesetpixel($im,1,1,$white); 

    // Set the image type 
    header("content-type:image/jpg"); 

    // Create a JPEG file from the image 
    imagejpeg($im); 

    // Free memory associated with the image 
    imagedestroy($im); 

    // Server variables 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $referer = $_SERVER['HTTP_REFERER']; 
    $useragent = $_SERVER['HTTP_USER_AGENT']; 
    $browser = get_browser(null, true); 
    $fecha = date("Y-m-d;h:i:s"); 
    if (isset($_GET['type'])) { 
    $type = $_GET['type']; 
    } 
    $f = fopen("list.html", "a"); 

    fwrite ($f, 
    'IP: [<b><font color="#660000">'.$ip.'</font></b>] 
    Referer: [<b><font color="#9900FF">'.$referer.'</font></b>] 
    User Agent: [<b><font color="#996600">'.$useragent.'</font></b>] 
    Browser: [<b><font color="#996600">'.$browser.'</font></b>] 
    Date: [<b><font color="#FF6633">'.$fecha.'</font></b>]<br> '); 
    if (isset($type) { 
    fwrite ($f, 'Type: [<b><font color="#660000">'.$type.'</font></b>]' 
    fclose($f); 
?> 
+2

당신이()'성공했는지 '하면 fopen 있습니까? 어쩌면 파일에 쓸 수있는 권한이 없을 수도 있습니다. – Barmar

+0

BTW,'fopen + fwrite + fclose'를 단지'file_put_contents()'로 간소화 할 수 있습니다. 파일에 추가 할 수있는'FILE_APPEND' 옵션이 있습니다. – Barmar

답변

0

당신은 스크립트의 끝 부분에 오류가, 그것은해야합니다 :

if (isset($type)) { 
    fwrite ($f, 'Type: [<b><font color="#660000">'.$type.'</font></b>]'); 
    fclose($f); 
} 
?> 

그것을 수정하고 스크립트 작업