此代码在 Xampp 中可以正常工作,但在我将其上传到服务器后却无法工作
<?php
ob_start();
session_start();
if(session_status()!=PHP_SESSION_ACTIVE) { session_start();}
if(!isset($_SESSION['username']) || !isset($_SESSION['password']))
{
header('location:login.php');
}
$connection=mysqli_query('localhost','username','password','dbname')
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
页面加载正常,但在页面顶部出现错误,并且由于它是管理页面,除非设置了 session ,否则不得打开。这是我现在收到的警告。
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home3/index.php:1) in /home3/index.php on line 3
Warning: Cannot modify header information - headers already sent by (output started at /home3/index.php:1) in /home3/index.php on line 7
最佳答案
使用下面的代码,并确保您的代码中 <?php
之前没有剩余任何空格。标签开始。
<?php session_start();
ob_start();
请注意, session 只能在页面上开始输出之前启动,并且相同的规则适用于 php 中的 header 函数。
关于php - session_start() 不起作用并发出警告,尽管它位于页面顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30638029/