简体   繁体   English

PHP 带有打印或回显的 href 链接不起作用

[英]PHP a href link with print or echo don't work

I have question about a href link in php field.我对 php 字段中的 href 链接有疑问。 When I try to make a href link in php field by using echo or print, when i click the link it does not work the link.当我尝试使用 echo 或 print 在 php 字段中创建 href 链接时,当我单击该链接时,该链接不起作用。 Could you see the code briefly?你能简要地看一下代码吗? Thanks!谢谢!

 <?php if (isset($_SESSION['name1'])) { echo '<li class="dropdown">'; echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown">'; echo "Hi,"; echo $_SESSION['name1']; echo '<span class="caret"></span></a>'; echo '<ul id="logout-dp" class="dropdown-menu">'; echo '<li>'; echo '<div class="row">'; echo '<div class="col-md-12">'; echo '<div class="form-group">'; echo '<ul>'; echo '<li><div><a class="col" href="logout.php">Logout</a></div></li>'; echo '<li><div><a class="col" href="#">Account</a></div></li>'; echo '<li><div><a class="col" href="resetpassword.php">Reset password</a></div></li>'; echo '</ul>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</li>'; echo '</ul>'; echo '</li>'; } ?>

Your code is delimiting quotes which is not needed as you are using a different set of quotes to encapsulate the string already.您的代码正在分隔不需要的引号,因为您已经使用一组不同的引号来封装字符串。

Change:改变:

'<li><div><a class="col" href=\"logout.php\">Logout</a></div></li>';

to:到:

'<li><div><a class="col" href="logout.php">Logout</a></div></li>';

This should have stuck out if you inspected the source code you were outputting as then showing the following:如果您检查了您正在输出的源代码,然后显示以下内容,这应该会很明显:

<a class="col" href=\"logout.php\">Logout</a>

Which is clearly not a valid hyperlink.这显然不是有效的超链接。

Edit: Your code in the question has now changed to remove the \\" . Not sure if that was you or someone "correcting" the question.编辑:您在问题中的代码现在已更改为删除\\" 。不确定是您还是某人“纠正”了问题。

i modified your code because it was really difficult to follow with all those echo calls.我修改了您的代码,因为很难跟踪所有这些echo调用。

also made the logout and resetpass links point to the root of the domain, which is where i assume you have them.还使注销和重置通行链接指向域的根,我假设您拥有它们。 ex.前任。 domain.com/logout.php and domain.com/resetpassword.php domain.com/logout.php 和 domain.com/resetpassword.php

<?php
    if (isset($_SESSION['name1'])) {
        echo '<li class="dropdown">' .  
        '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . 
        "Hi," . 
        $_SESSION['name1'] .  
        '<span class="caret"></span></a>' . 
        '<ul id="logout-dp" class="dropdown-menu">' . 
         '<li>' . 
          '<div class="row">' . 
           '<div class="col-md-12">' . 
            '<div class="form-group">' . 
             '<ul>' . 
              '<li><div><a class="col" href="logout.php">Logout</a></div></li>' . 
              '<li><div><a class="col" href="#">Account</a></div></li>' . 
              '<li><div><a class="col" href="resetpassword.php">Reset password</a></div></li>' . 
             '</ul>' .                            
            '</div>' . 
           '</div>' . 
          '</div>' . 
         '</li>' .  
        '</ul>' .  
        '</li>';                        
    }

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

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