dongyan1974 2013-08-22 14:18
浏览 22
已采纳

php中的路径无法正常工作

I have a navigation bar I include in my pages, which worked fine as long as all the php files were in the same dir. Once I moved them into folders the navigation bar would only allow one link to be clicked then once in a lower dir the pathing to files were incorrect.

Dir structure:

php-->

  • navpanel.php

  • search.php

  • user folder

    • checkusername.php

    • etc php files

  • database folder

    • createdatabase.php

js-->

  • js files

php code im using which is included in the other files.

<?php
$path = $_SERVER["DOCUMENT_ROOT"];
echo $path;
if ($_SESSION['admin'] == 1){
    echo '
        <body>          
            <ul id="menu">
                <li><a href="search.php">Search</a></li>
                <li><a href="#"></span> User</a>
                    <ul>
                        <li><a href="user/createuser.php">Create User</a></li>
                        <li><a href="user/edituser.php">Edit User</a></li>
                        <li><a href="user/deleteuser.php">Delete User</a></li>
                        <li><a href="user/usergroup.php">User Groups</a></li>
                    </ul>
                </li>
                <li><a href="#">Databases</a>
                    <ul>
                        <li><a href="database/createdatabase.php">Create Database</a></li>
                        <li><a href="database/editdatabase">Edit Database</a></li>
                        <li><a href="database/deletedatabase">Delete Database</a></li>
                        <li><a href="database/databasegroup">Database Groups</a></li>
                    </ul>
                </li>
                <li><a href="../connect/logout.php">Log Out</a></li>
            </ul>         
        </body>';
}
else {
    echo '
        <body>

            <ul id="menu">
                <li><a href="search.php">Search</a></li>
                <li><a href="connect/logout.php">Log Out</a></li>
            </ul>

        </body>
    ';
}
  • 写回答

3条回答 默认 最新

  • dsk920417 2013-08-22 14:21
    关注

    The problem is in the HTML output. If you want the links to be relative from the root (http://www.example.com/), then you should use /user/createuser.php, /user/edituser.php, etc.

    Although unrelated to your links, you are referencing the session variable $_SESSION['admin'] without calling session_start(); at the top of your script. Session variables return null if you don't call session_start();.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作