2013-05-17 82 views
0

我一直在試圖創建一個表單來創建HTML格式的票據,以便輕鬆組織和查看問題,但是每次我嘗試測試它時,它只會顯示變量爲$variable這裏要說的是,我使用,以試圖使這項工作的腳本:變量沒有被寫入

function ip(){if (!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}return $ip;} 
$ip = ip(); 

$date = date("Y-m-d h:i:s A"); 
$emailField = $_GET['Email']; 
$issue = $_GET['issue']; 
$ticketField = $_GET['Ticket']; 
$ip = $ip; 
$date = $date; 
$file = 'admin/logs.php'; 
$lines = file($file); 
$all_lines = implode('',$lines); 
$entry = str_replace('<script type="text/javascript" language="JavaScript">endtable()</script><script type="text/javascript" language="JavaScript">copyright()</script>',' <tr> 
    <td><div id="logleft"></div></td> 
    <td><div id="logmid"><center>$emailField</center></div></td> 
    <td><div id="logmid"><center>$ip</center></div></td> 
    <td><div id="logmid"><center>$issueField</center></div></td> 
    <td><div id="logmid"><center>$ticketField</center></div></td> 
    <td><div id="logright"></div></td> 
</tr> 
<script type="text/javascript" language="JavaScript">endtable()</script><script type="text/javascript" language="JavaScript">copyright()</script>',$all_lines); 
$fp = fopen($file,'w'); 
$fw = fwrite($fp,$entry); 
fclose($fp); 

我已經確定了表單動作是GET,而不是帖子,但沒有什麼工作,它仍然顯示變量$variable

+0

確保'admin'目錄有寫入權限運行Web服務器進程 – Orangepill

回答

0

試試這個:

function ip(){if (!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}return $ip;} 
    $ip = ip(); 

    $date = date("Y-m-d h:i:s A"); 
    $emailField = $_GET['Email']; 
    $issueField = $_GET['issue']; 
    $ticketField = $_GET['Ticket']; 
    $ip = $ip; 
    $date = $date; 
    $file = 'admin/logs.php'; 
    $lines = file($file); 
    $all_lines = implode('',$lines); 
    $entry = str_replace('<script type="text/javascript" language="JavaScript">endtable()</script><script type="text/javascript" language="JavaScript">copyright()</script>',' <tr> 
     <td><div id="logleft"></div></td> 
     <td><div id="logmid"><center>'.$emailField.'</center></div></td> 
     <td><div id="logmid"><center>'.$ip.'</center></div></td> 
     <td><div id="logmid"><center>'.$issueField.'</center></div></td> 
     <td><div id="logmid"><center>.'.$ticketField.'</center></div></td> 
     <td><div id="logright"></div></td> 
    </tr> 
    <script type="text/javascript" language="JavaScript">endtable()</script><script type="text/javascript" language="JavaScript">copyright()</script>',$all_lines); 
    $fp = fopen($file,'w'); 
    $fw = fwrite($fp,$entry); 
    fclose($fp); 
+0

這很好,謝謝! – user2331568

0

您是否在PHP中閱讀過文檔about strings?更改字符串中的引號:' - >「和」 - >'。或者你可以使用concatenation

P.S.使用file_get_contents讀取整個文件

P.P.S.使用file_put_contents寫入整個文件

P.P.P.S.並向我們​​展示您的目的原件。這段代碼看起來像是你做出了錯誤的決定。

+0

不是真的知道你在你的購買力平價都在說,不過以前的人已幫助過我的用戶,謝謝,雖然! – user2331568