duandao8607 2018-03-21 13:10
浏览 288
已采纳

PHP文件的URL无法正常工作

I'm trying to learn HTML and PHP so trying to build a login form with some links.

The bebsite opens OK, however the link to sign up seems to be going nowhere.

My index file as follows:

<?php
 include ('../app/header.php');
 ?>
    <section class="main-container">
      <div class="main-wrapper">
        <h2>Home</h2>
      </div>
     </section>
 <?php
   include ('../app/footer.php');
 ?>

And my header php as follows:

<!DOCTYPE html>
<html lang="en" dir="ltr">
 <head>
  <meta charset="utf-8">
  <title>Welcome</title>
   <link rel="stylesheet" type="text/css" href="/css/styles.css">
 </head>
 <body>
<header>
  <nav>
    <div class="main-wrapper">
      <ul>
        <li><a href="/index.php">Home</a></li>
      </ul>
      <div class="nav-login">
        <form>
          <input type="text" name="uid" placeholder="Username\e-mail">
          <input type="password" name="pwd" placeholder="password">
          <button type="submit" name="submit">Login</button>
        </form>
        <a href="../app/signup.php">Sign up</a>
      </div>
    </div>
  </nav>
</header>

The issue is that href link to signup php takes me nowhere. However if I copy the files into public directory and change the path in the link it then works fine.

Also, after clicking signup link, my URL shows localhost\app\signup.php.

Im using xammp.

Could someone advise as to why the link does not work as expected?

Thanks

UPDATED:

My directory is as follows:

C:\xampp\htdocs\basicwebsite\public\index.php

and all PHP files are here:

C:\xampp\htdocs\basicwebsite\app

  • 写回答

3条回答 默认 最新

  • douze2890241475 2018-03-21 13:22
    关注

    For what I understood so far these are your folders:

    // site
       // app
          signup.php
       // public
          index.php
    

    Your http server is using the public folder as doc root, therefore accessing http://localhost/index.php is the same as public/index.php.

    If you link to ../app/signup.php your browser will attempt to access http://localhost/../app/signup.php, since you can't request files outside your doc root it will not find your file.

    That's not exclusive to php, apache or even xampp but is true for all http servers.

    For it to work, all your system's entry points (like index and signup) must be made public for the browsers.

    Moving your file to public/signup.php and updating the link will work.

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

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献