我需要一个帮助。我需要在锚标签中使用PHP.I在URL中动态设置id。我添加了下面的代码。
$message='<p>You recently requested to reset your password.You can reset password by following the link below.If you no longer need to rest your password ,you can ignore this message.</p></br><p><a href="http://localhost/spesh/#/resetPass?">Click here</a></p>';上述内容将去用户的电子邮件,用户将点击click here链接,网址应open.Here我需要设置id=2后,?.Please帮助我。
发布于 2016-03-23 14:38:01
如果您不使用任何类型的angular路由,则在不使用#标签的情况下处理您的url,以获取
$var = 2;
$message = "<a href='http://localhost/spesh/resetPass/?id=$var'>Click here</a>";警告:
如果任何人知道你的网站,他们可以尝试使用任何Id重置所有密码,所以请注意这一点,并在每次重置请求中使用token。像这样
http://localhost/spesh/resetPass/?id=$var&token=23l4klkffgdkoiowlkfwokew发布于 2016-03-23 14:55:50
我可以想象您是从某个数据库或会话中获取ID的。在这种情况下,以某种方式将ID放入一个变量(让我们称其为$userId),将其转义为HTML (以防止 (这是一个用于HTML注入的奇特名称)),并将其添加到href属性中:
$userId = htmlspecialchars(somehowGetUserId());
$message="<p>You recently requested to reset your password.You can reset password by following the link below.If you no longer need to rest your password ,you can ignore this message.</p></br><p><a href="http://localhost/spesh/#/resetPass?id=$userId">Click here</a></p>";其中,somehowGetUserId()是一个函数,我让您随心所欲地实现它。它的想法是“以某种方式”返回用户ID。
请注意,我还用双引号替换了您的单引号,以方便对内部变量进行插值。
请注意,这对服务器端$_GET不起作用,因为浏览器不会在#之后向服务器发送任何内容,如果想让PHP看到id=2,您需要将?id=$userId移到#之前。
发布于 2016-03-23 14:44:32
如果您的id在一个名为$id的变量中,那么:
$message='<p>You recently requested to reset your password.You can reset password by following the link below.If you no longer need to rest your password ,you can ignore this message.</p></br><p><a href="http://localhost/spesh/#/resetPass?id={$id}">Click here</a></p>';https://stackoverflow.com/questions/36171279
复制相似问题