2017-09-14 44 views
0

我在另一個php文件中打開「email.php」。 「email.php」會生成一個嵌入超鏈接的隨機代碼,但隨機生成的代碼未被插入。相反,字符串正在發送。功能randomCodeGenerator的作品,並在util2.php文件。HTML HREF中的PHP不起作用

<?php 
    require_once "inc/util2.php"; 

    ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head></head> 
    <body> 
     <?php 
     $code = randomCodeGenerator(50); 
     ?> 
     <p style="color: black;font-weight: bold;text-align: center;font-family: &quot;Arial&quot;;">Hello! Thank you for your interest in Space Proposition! 
     For your account to become activated, please lease click the following link below to activate your email account:<br> 
     </p> 

     <a href="http://corsair.cs.iupui.edu:21221/upload/lab2/validateLab2.php?a=<?php echo $code;?>"> 
     <p style="font-weight: bold;text-align: center;font-family: Arial;">Click Me!</p> 
     </a> 

     <br /> 
     <p style="color: black;font-weight: bold;text-align: center;font-family: &quot;Arial&quot;;">Once again, thank you very much for your interest. We will 
     do our best to keep the website updated regulary as new discoveries are made!<br> 
     </p> 
    </body> 
</html> 

當我點擊發送給我的電子郵件中的鏈接,該超鏈接看起來是這樣的:

http://corsair.cs.iupui.edu:21221/upload/lab2/validateLab2.php?a=%3C?phpecho%20$code;?%3E 
+0

您可以查看源?其他PHP塊是否顯示在那裏?由於某種原因,它似乎並沒有得到執行。 –

+0

[如何在屬性值內添加php標籤?](https://stackoverflow.com/questions/14900370/how-to-add-php-tags-inside-attribute-value) – pvg

+0

@ chris85'email .php'文件與訪問它的文件位於同一個目錄中。我正在使用'file_get_contents()'函數將'email.php'文件的內容打開成一個名爲'$ body'的變量。然後我使用'mail/mail.class.php'庫發送郵件。 – cparks10

回答

0

file_get_contents只是拉取文件的內容並將其存儲到變量中。繞過PHP處理器,使用Web服務器來處理文件,然後你會得到結果。例如

file_get_contents('http://yourscript.php'); 

代替:

file_get_contents('/local/yourscript.php'); 
+0

對於上述問題,此答案是? –

+0

@Just_Do_It是的。 (雖然'file_get_contents'不在實際正在使用的註釋中確定的問題的正文) – chris85

+0

對不起,我錯過了那部分。 –

0

試圖改變你所添加的代碼的方式,喜歡的東西:

$code = randomCodeGenerator(50); 
$url = "http://corsair.cs.iupui.edu:21221/upload/lab2/validateLab2.php?a=".$code; 

,最後;

<a href='<?php echo $url;?'> 
+0

這仍然會起作用。 – chris85

+0

不幸的是,這沒有做什麼。我複製並粘貼你的方式,嘗試移動單引號,並將雙引號添加到單引號的外部,並且沒有任何內容.... – cparks10

+0

@ cparks10我在我的本地服務器上嘗試過,它工作正常,可能是更新您的本地服務器設置,以防萬一您正在使用wamp,那麼在您的wamp配置中嘗試禁用簡短的開放標籤 –