duandao8607 2018-03-21 05: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 05: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了