简体   繁体   English

HTML HREF中的PHP无法正常工作

[英]PHP in HTML HREF not working

I am opening "email.php" inside of another php file. 我正在另一个PHP文件中打开“ email.php”。 "email.php" generates a random code to be nested into a hyperlink, but the randomly generated code is not being inserted. “ email.php”生成随机代码以嵌套到超链接中,但是不会插入随机生成的代码。 Instead, the literal string is being sent. 而是发送文字字符串。 The function randomCodeGenerator works and is in the util2.php file. 函数randomCodeGenerator可以使用,位于util2.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>

When I click the link sent to my email, the hyperlink looks like this: 当我单击发送到我的电子邮件的链接时,超链接如下所示:

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

try to alter the way you are adding the code, something like: 尝试更改添加代码的方式,例如:

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

and finally ; 最后;

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

The file_get_contents just pulls the contents of the file and stores it to a variable. file_get_contents只是提取文件的内容并将其存储到变量中。 That bypasses the PHP processor, use the web server to process the file and then you will get the results. 这绕过了PHP处理器,使用Web服务器来处理文件,然后您将获得结果。 eg 例如

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

instead of: 代替:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM