【问题标题】:localhost does not load php [duplicate]localhost不加载php [重复]
【发布时间】:2017-05-23 19:14:53
【问题描述】:

我正在尝试使用 xampp 在 localhost 上加载我的起始页 (php)。只要我将文件保存为 html 文档(另存为 start.html),它就会显示出来,但是一旦我将其保存为 php 文件(为了执行 $_SESSION['id'] 它就无法加载文件(基本上是无限加载过程,但没有出现错误。这是我的代码。非常感谢任何帮助。谢谢

<?php
session_start();?>
<html>
  <head>
    <title>
      I am a login project
    </title>
    <meta charset="utf-8">
    <link rel="stylesheet" href='style.css' type="text/css">
  </head>
  <body>
    <form method="post" action="login.php">
      <input type="text" placeholder="uid" name="Username">
      <input type="password" placeholder="Password" name="pwd">
      <button type="submit" name="submit">LOGIN</button>
    </form>
    <br>
    <?php
    if(isset($_SESSION['id'])){
      echo $_SESSION['id'];
    }
  ?>

      <form method="post" action="signup.php">
        <input type="text" placeholder="first" name="first">
        <input type="text" placeholder="last" name="last">
        <input type="text" placeholder="uid" name="Username">
        <input type="password" placeholder="Password" name="pwd">
        <button type="submit" name="submit">SIGN_UP</button>
      </form>
      <br>
      <form method="post" action="logout.php">
        <button type="submit" name='logout'>LOGOUT</button>
      </form>
  </body>
</html>

【问题讨论】:

  • 尝试空白 index.php 页面并运行 &lt;?php phpinfo(); 以确保 php 配置正确。您在正确的目录中吧?
  • &lt;?php 之前真的有空格吗?试试error_reporting(E_ALL); ini_set('display_errors', '1');
  • 应该配置正确。当我用 start.html 文件调用我的 signup.php 时,它可以工作并执行 signup.php。

标签: php login xampp localhost


【解决方案1】:

会话开始应该发生在任何输出之前。在您的开始 php 标记之前有一个空格

【讨论】:

  • 这是一个粘贴错误 Maarten。实际上没有空间但是谢谢
猜你喜欢
  • 1970-01-01
  • 2017-12-08
  • 2023-02-24
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-16
相关资源
最近更新 更多