简体   繁体   中英

PHP in HTML HREF not working

I am opening "email.php" inside of another php file. "email.php" generates a random code to be nested into a hyperlink, but the randomly generated code is not being inserted. Instead, the literal string is being sent. The function randomCodeGenerator works and is in the util2.php file.

<?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. That bypasses the PHP processor, use the web server to process the file and then you will get the results. eg

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

instead of:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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