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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题