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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号