0

I need to add two variables to my url to make it more secure. But I can't add php in my href.

this is the code:

<php
$token =1;
$email =2;
$body='
<body>
<p>Use the link below to reset your password.</p><br>
<a href="http://localhost/wwi/view/pw_reset.php?token=<?php echo $token?>&email=<?php echo $email?>">Click here</a>
</body>';

but the result I get now is:

http://localhost/wwi/view/pw_reset.php?token=echo$token&email=echo$email

instead of what I need which is:

http://localhost/wwi/view/pw_reset.php?token=1&email=2

It needs to be in the variable $body because this is used to send an email with phpmailer.

Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • It looks like you have missed out the semi collen at the end of the php echo statement. I have put the corrected code in the answer. – nXn Dec 19 '19 at 07:03
  • Does this answer your question? [How to properly create HTML links in PHP?](https://stackoverflow.com/questions/55366208/how-to-properly-create-html-links-in-php) – Dharman Dec 19 '19 at 08:42
  • @Dharman, it's self-promotion? :D OP doesn't ask `how to make it properly`, he faced an issue. Issue was in tags. – Aksen P Dec 19 '19 at 08:55

4 Answers4

1

Your code should like

<php should be <?php

Because you are already in php blog, then do not use again <?php..

$token =1;
$email =2;
$body='
<body>
<p>Use the link below to reset your password.</p><br>
<a href="http://localhost/wwi/view/pw_reset.php?token='.$token.'&email='.$email.'">Click here</a>
</body>';
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
0

You've forgot ? at the beginning in <php -> should be <?php

If you're creating a string then use concatenation:

$body= 'text'.$email.'text'.$token.'text';

<?php echo ?> could be used if prev <?php was closed by ?>. It happens often inside HTML document. In case of using it inside <?php ?> like <?php <?php ?> it will raise an error.

Aksen P
  • 4,564
  • 3
  • 14
  • 27
0

Hi You can use below code, it will works for you.

<?php

 $token =1;
 $email =2;
 $body='
 <body>
 <p>Use the link below to reset your password.</p><br>
 <a href="http://localhost/wwi/view/pw_reset.php?token='.$token.'&email='.$email.'" > Click here </a>
 </body>';
ChandraShekar
  • 386
  • 5
  • 12
-1

Try this

$token =1;
$email =2;
$body='
<body>
    <p>Use the link below to reset your password.</p><br>
    <a href="http://localhost/wwi/view/pw_reset.php?token='. $token'. '&email='. $email">Click here</a>
</body>';
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
nXn
  • 904
  • 6
  • 13