我对session_start()有一些问题;
我知道在session_start()之前不应输出任何内容; 声明
但我无法在我的剧本中找到问题
index.php文件:
<?php session_start();
include('functions.php');
if(!is_logged_in(session_id())){
include('form.php');
}else{
?>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)
但我总是跟着错误:
警告:session_start()[function.session-start]:无法发送会话cookie - 已经在C:\ xampp\htdocs\fertige_scan中发送的输出(输出从C:\ xampp\htdocs\fertige_scan\index.php:1开始)第1行的\ index.php
我希望你能帮帮我 :)
我有一个CI应用程序,具有auth控制器和switchuser功能.基本上它只需要从URI获取ID,从ID获取一些用户数据,分配一些会话数据然后加载视图.
function switch_user(){
if(!$this->auth_lib->is_admin()){
$this->session->set_flashdata('status', 'You need to be an administrator to access this page.');
redirect('auth/login');
}
if($id = $this->uri->segment(3)):
$this->load->model('auth_model', 'auth');
$username = $this->auth->get_username($id)->account_name;
$this->session->set_userdata(array('at_id' => $id, 'username' => $username));
$this->session->set_flashdata('status','User switched.');
endif;
$this->load->model('clients_model', 'clients');
$data['users'] = $this->clients->get_at_clients();
$this->load->view('auth/switch', $data);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cp\application\controllers\auth.php:130)
Run Code Online (Sandbox Code Playgroud)
第130行是$ username = $ this-> auth-> get_username($ id) - > account_name;
这是模型功能:
function get_username($at_id){
$portal = $this->load->database('warehouse', TRUE);
$portal->select('account_name');
$portal->where('account_id', $at_id);
$portal->from('wh_account');
$query …Run Code Online (Sandbox Code Playgroud) echo http_response_code('400');
return "error";
Run Code Online (Sandbox Code Playgroud)
我有一个页面需要输出http状态
我设置http_response_code(400)并尝试使用邮递员发布。
它总是返回200。
为什么http_response_code不工作?
我最近更改了我的编辑器以保存int UTF-8.这开始随后爆发,不知道它意味着什么.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/sudancar/public_html/index.php:1) in /home/sudancar/public_html/index.php on line 1
Run Code Online (Sandbox Code Playgroud) 因此,功能类似session_start并且setcookie无法成功运行,报告:
无法修改标头信息 - 已发送的标头
但目标文件是这样的:
1 <?php
2 session_start();
Run Code Online (Sandbox Code Playgroud)
怎么解决?
书院
我发现了问题,utf-8格式文件在上传到服务器后变成utf-8 + BOM,所以我暂时通过再次将其保存为utf-8来解决问题.
但是,有很多其他文件存在同样的问题,我该如何批量解决问题呢?
我得到errormessage:警告:无法修改标头信息 - 已经发送的标头(输出从C:\ xampp\htdocs\json.php:1开始)
我知道这个错误消息会来,如果我写了一些东西,并希望稍后发送标题信息.但在这种情况下,我不写任何东西.这是我从第1行开始的代码.
<? header("Content-type: text/html; charset=utf-8");
require ("diplom/includes/php/datenbankfunktionen.php");
$sDB_Server = "localhost";
$sDB_User = "root";
$sDB_Password = "";
$sDB_Database = "JSON";
$sSql = "SELECT name, phone, mail as email, contactID AS id FROM contact;";
$aContacts = DB_GetSelectArray($sSql);
echo '{"DATA":'.json_encode($aContacts).',"SUCCESS":true,"ERRORS":[]}';
?>
Run Code Online (Sandbox Code Playgroud)
可以somone帮帮我吗?我使用XAMPP开发人员系统.
可能重复:
PHP已发送的标头
我有一个问题session_start(),并header('Location:')在注销PHP文件.
我正在使用html文件中的简单锚标记链接到注销文件.注销php文件是这样的:
<?php
session_start();
session_destroy();
header("Location: index.php");
?>
Run Code Online (Sandbox Code Playgroud)
要查看我使用的错误,
error_reporting(E_ALL);
ini_set('display_errors', '1');
Run Code Online (Sandbox Code Playgroud)
我收到一条警告"警告:session_start():无法发送会话缓存限制器 - 已经发送的标头"在第4行(在哪里session_start();)和警告:无法修改标头信息 - 已经在第6行发送的标头(在哪里header('Location')).
我已经看过其他有类似问题的人了.我确定之前没有空格session_start().在它之前没有输出任何东西.我试过只设置session_start()它还没有设置.我试过缓冲它ob_start().我尝试了重定向的相对和绝对路径,以确保.但没有任何效果.
我错过了什么吗?任何帮助深表感谢.
我知道这个标题与与某个问题相关的 1000 个其他帖子重复,如果有解决方案,我提前表示歉意。相信我,我浏览了大量有关该主题的帖子,并尝试了所有规定的解决方案,但没有运气。
我正在尝试通过第 1 页中的以下代码创建 SESSION 变量:
<?php
$conditionArray = array('Past', 'Past', 'Future', 'Future');
$typeArray = array('Gains', 'Gains', 'Losses', 'Losses');
shuffle($conditionArray);
shuffle($typeArray);
session_start();
$_SESSION['conditionArray'] = implode(',',$conditionArray);
$_SESSION['typeArray'] = implode(',',$typeArray);
var_dump($_SESSION);
?>
<html>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在 var_dump 显示以下内容:
array(2) { ["conditionArray"]=> string(23) "Future,Past,Past,Future" ["typeArray"]=> string(25) "Gains,Gains,Losses,Losses" }
Run Code Online (Sandbox Code Playgroud)
这很好。
在下一页上,我尝试通过以下代码检索变量:
<?php
session_start();
echo $_SESSION['typeArray'];
var_dump($_SESSION);
?>
<html>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它给了我:
array(0) { }
Run Code Online (Sandbox Code Playgroud)
我尝试查看 php 的错误日志文件,但没有看到任何相关内容。任何帮助将不胜感激!
我试图在我的网站上实现PHP联系表单,但我遇到了一些错误.你可以填写表格没有问题,电子邮件实际上通过,但不显示感谢页面,它显示一些PHP错误.
Deprecated: Function eregi() is deprecated in /home/travisbass/travismoore.co.uk/include/fgcontactform.php on line 548
Deprecated: Function split() is deprecated in /home/travisbass/travismoore.co.uk/include/class.phpmailer.php on line 470
Warning: Cannot modify header information - headers already sent by (output started at /home/travisbass/travismoore.co.uk/include/fgcontactform.php:548) in /home/travisbass/travismoore.co.uk/include/fgcontactform.php on line 143
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请与我们联系.
任何帮助它赞赏,谢谢
版本:
当 PhpUnit 运行以下测试时,我收到有关会话无法启动的错误。有谁知道这个问题以及如何解决它?
以下主题无法回答我的问题,或者建议的解决方案对我不起作用:
我尝试了第二个链接建议的解决方案:@session_start()但@runInSeparateProcess没有任何效果。也许我只是误解了我的问题,但我现在被困了一个星期。
protected function setUp(): void
{
@session_start();
parent::setUp();
}
/**
* @runInSeparateProcess
*/
public function testLoginFailure(): void
{
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('Login')->form();
$form['email']->setValue('bob@gmail.com');
$form['password']->setValue('123abcABC%');
$crawler = $client->submit($form);
$this->assertResponseIsSuccessful();
}
Run Code Online (Sandbox Code Playgroud)
<!-- Failed to start the session because headers have already been sent by "C:\Users\cimba\Documents\project\vendor\phpunit\phpunit\src\Util\Printer.php" at line 104. (500 Internal Server Error) -->
C:\Users\cimba\Documents\project\vendor\symfony\framework-bundle\Test\BrowserKitAssertionsTrait.php:142
C:\Users\cimba\Documents\project\vendor\symfony\framework-bundle\Test\BrowserKitAssertionsTrait.php:33
C:\Users\cimba\Documents\project\tests\InternalLoginTest.php:51 …Run Code Online (Sandbox Code Playgroud)