PHP session_start函数和CLI [英] PHP session_start function and CLI
问题描述
PHP CLI中使用的函数session_start打印下一条警告: session_start():无法发送会话cookie-已发送的标头(输出始于/home/robi/p/test.php:1)在/home/robi/p/test.php的第2行上
为什么?
Function session_start used in PHP CLI print the next warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/robi/p/test.php:1) in /home/robi/p/test.php on line 2
why?
我想将所有客户端条目记录到变量中,并检查到通过比较用户的上次进入时间和当前进入时间,看看我是否从特定的远程地址得到了伪造品!
I want to log all the client entries in a variable and check this out to see if i get forgery from a specific remote address by comparing the time user last entry and current entry time! Am I doing it wrong?
这是我的代码吗?
<?php
session_start();
$client_entry = time();
$_SESSION["entries"][] = $client_entry;
$entries = $_SESSION["entries"];
$check_out = array_filter(
$entries,
function($value) use($client_entry) {
return ($value >= ($client_entry + (1 * 0.6)));
}
);
推荐答案
您的问题是,除此之外,这毫无意义要在CLI中使用会话,该输出已经在 session_start();
之前开始。
Your problem is, apart from that it makes no sense to use sessions in CLI, that output has already started prior to session_start();
.
您的代码,您的代码直接以 session_start();
开头,我相信您在<?php
之前有一些字符。确保<?php
位于文件的第一行(因此文件上方也没有空行),并且没有任何内容(例如空格)
As I see in your code, you code begins directly with session_start();
, I believe you have some characters before <?php
. Make sure <?php
is on the very first line of your file (so also no empty lines above it), and that there is nothing (such as a white space) in front of it.
这应该可以解决您遇到的这个问题。
This should fix this problem you are having.
这篇关于PHP session_start函数和CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!