0

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
5
  • Can you view the source? Do the other PHP blocks show up there? It seems it may not be getting executed at all for some reason. Commented Sep 14, 2017 at 19:10
  • Possible duplicate of How to add php tags inside attribute value? Commented Sep 14, 2017 at 19:12
  • @chris85 The 'email.php' file is in the same directory as the file accessing it. I am using the 'file_get_contents()' function to open the contents of the 'email.php' file into a variable called '$body'. I am then using 'mail/mail.class.php' library to send the email. Commented Sep 14, 2017 at 19:23
  • @Don'tPanic Yeah I tried printing out other PHP things and it seems like nothing at all is working. Commented Sep 14, 2017 at 19:32
  • 1
    @chris85 That was the problem! I was doing it the first way and nothing was working, it must have been printing out in plain text as you said, which is why I was getting the literal string as the URL in my email. I altered the 'file_get_contents()' to take the full URL path as it's argument and it is working beautifully. Thank you! Commented Sep 14, 2017 at 19:34

2 Answers 2

0

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. e.g.

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

instead of:

file_get_contents('/local/yourscript.php');
Sign up to request clarification or add additional context in comments.

3 Comments

is this answer for the above question?
@Just_Do_It Yes, it is. (although the file_get_contents isn't in the actual body of the question it was determined in the comments that was being used)
Sorry I missed that part.
0

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;?'>

4 Comments

This would still function the same.
Unfortunately this does nothing. I copied and pasted the way you had it, tried moving the single quotes, and added double quotes to the outside of the single quotes and nothing....
@cparks10 I tried on my local server and it is working fine, perhaps update your local server setting so in case you are using wamp then In your wamp config try to disable short open tag
@Just_Do_It This would give the exact same result the OP already has.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.