我正在开展一个项目,我需要在其他人的网络服务器上运行我的程序.这是一个非常简单的登录页面,我遇到了问题.如果我通过WAMP通过本地主机运行程序,该程序可以正常工作.我遇到的问题是重定向部分无法正常工作它验证用户并启动会话但是当它到达重定向时没有任何反应.
我要么在做我的语法错误,我认为这种做法极不可能,因为它通过我的本地主机正常工作.或者我认为服务器没有该功能(不确定是否可以选择服务器支持哪些模块,尽管我确信它是可行的).
我不知道它是否重要,但他们正在使用"cpanel",这是我可以访问文件的地方,所有在同一目录中,所以如果有人可以告诉我我哪里出错或建议替代重定向通过"标题" 任何帮助将不胜感激.我环顾四周,但似乎"标题"是标准的工作马.
继承我的代码:
if( (!empty($_POST['username'])) && (!empty($_POST['password'])) )
{
// username and password sent from Form
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$sql="SELECT UserName FROM User WHERE UserName='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
echo "we made if to the if";
session_start();
session_register("myusername");
$_SESSION['login_user']=$myusername;
echo "right b4 the re-direct";
header("location: UI.php");
exit;
}
else
echo "Your user name/password was not correct pleast TRY …Run Code Online (Sandbox Code Playgroud) 有没有办法通过phpquery :: newDocument运行这个html标记后修复显示不正确的字符?在使用phpquery创建新文档后,原始文档中的-Classics和现代Woman之间会出现双引号.
//Original document is UTF-8 encoded
$raw_html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><p>Mr. Smith of Bangkok celebrated the “Classics with modern Woman”.</p></body></html>';
print($raw_html);
$aNew_document = phpQuery::newDocument($raw_html);
print($aNew_document);
Run Code Online (Sandbox Code Playgroud)
原始输出:曼谷史密斯先生庆祝"与现代女性的经典".
新文件输出:曼谷史密斯先生与现代女性一起庆祝"经典".
我在我的PHP脚本(PHP 5.6,Apache 2.2)中间歇性地遇到了这个问题:
警告:无法修改标头信息 - 已在第55行的/path/to/index.php中发送的标头
这个警告没有我在其他问题中看过的"发送者"部分,所以我在犯罪header()和setcookie()调用之前添加了这段代码:
if (headers_sent($filename, $linenum)){
echo("Output buffer: #" . ob_get_contents() . "#");
echo "Headers already sent in $filename on line $linenum: ";
print_r(headers_list());
}
Run Code Online (Sandbox Code Playgroud)
这是问题发生时我得到的输出:
Output buffer: ##
Headers already sent in on line 0:
Array (
[0] => X-Powered-By: PHP/5.6.23
[1] => Content-type: text/html; charset=UTF-8
)
Run Code Online (Sandbox Code Playgroud)
(旁注:我在php.ini中将output_buffering设置为4096字节,所以这两个标题中的63个字符是否应该被缓存并等待更多,而不是过早发送?)
第一次启动包含Web服务器的Docker容器时出现此问题.之后,当我第一次访问我的网站(可能是一两个小时),当我打电话并登录用户或重定向到登录页面时,它只会(但不总是)发生.header()setcookie()
我已阅读并重读了一般"已发送标题"错误的答案,并且尽我所能,我已排除了这些可能的原因:
print,echo等等.在我调用setcookie()或header()auto_prepend_file php.ini设置gzip流编码 - …我正在寻找可能触发以下PHP警告的事情:
PHP警告:无法修改标头信息 - 已在第0行的"未知"中发送的标头
我看到(不仅仅是在这个网站上)来自没有经验的PHP程序员关于臭名昭着的"标题已经发送...输出开始于"错误的很多问题,并且许多人建议使用输出缓冲作为解决方案.
根据我的经验,我从未发现错误不是由程序逻辑中的缺陷引起的.是否存在输出缓冲实际上是正确解决方案的情况?
如果没有阅读完整的问题,请不要将其标记为重复.
我知道这已经多次讨论了.
但这是不同的情况.
我正在对php方法进行简单的ajax调用,如下所示:
public function updateAbout()
{
log_message('debug', "updateAbout is called", false);
log_message('debug',$this->input->post('fname'), false);
log_message('debug', "updateAbout success", false);
}
Run Code Online (Sandbox Code Playgroud)
在这个方法中,我只是试图获取由ajax调用传递的数据.
但我没有得到ajax调用发布的数据而是获得2个错误:
Severity: Warning --> session_start(): Cannot send session cache limiter - headers already sent ...\..\\libraries\Session\Session.php 143
Severity: Warning --> Cannot modify header information - headers already sent ..\..\libraries\Session\Session.php 171
Run Code Online (Sandbox Code Playgroud)
注意:
我没有使用session_start(); 我项目中的任何地方.
此错误指向session_start()方法,该方法位于Codeigniter库的Session.php文件中.它没有指向我的代码中的任何地方,所以我不确定在哪里寻找问题.
我已经在互联网上查了答案,但似乎没有人能解决这个问题.
有人可以解释我为什么会收到此错误,我该如何防止这种情况?
谢谢.
编辑: 根据其他答案中的建议,我已经检查并删除了所有代码中的空格.
这是我的javascript代码,其中进行了ajx调用.
$("#btnupdateAbout").click(function(){
$fname=$("#updatefname").val();
$lname=$("#updatelname").val();
$country=$("#updatecountry").val();
$locality=$("#updatelocality").val();
if($('#optradioMale').is(':checked')) { $gender="Male"; }
else{$gender="Female";}
$.ajax({
url:"http://localhost/Voyager/ProfileControls/updateAbout",
data:{'fname':$fname,'lname':$lname,'country':$country,'locality':$locality,'gender':$gender},
method:"POST",
contentType:false,
cache:false,
processData:false,
success:function(){
}
}); …Run Code Online (Sandbox Code Playgroud) 可能重复:
PHP已发送的标头
你好,当我去网站说它
Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/content/49/5712349/html/c/admin/admin.php:17) in /home/content/49/5712349/html/c/admin/admin.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at /home/content/49/5712349/html/c/admin/admin.php:17) in /home/content/49/5712349/html/c/admin/admin.php on line 41
Run Code Online (Sandbox Code Playgroud)
我看到了其他问题,没有人回答我.
这是代码非常感谢.
<?php
if (isset($_SESSION['mattyc-admin'])){
header ('Location: admin/home.php');
}
if (!isset($_GET['me'])){
header ('Location: http://www.stat-me.com/mattyc');
}
if ($_GET['me'] != 'mattyc'){
header ('Location: http://www.stat-me.com/mattyc');
}
?>
<?php
if ($_POST['name'] != "" && $_POST['password'] !="") {
//require "../../scripts/connect_to_mysql.php";
$name = …Run Code Online (Sandbox Code Playgroud) 这里有Session_start()的问题:
警告:在session_start()[function.session启动]:无法发送会话缓存限制器-已经发送了头(输出开始在C:\ XAMPP\htdocs中\网页\ home.php:4)在C:\ XAMPP\htdocs中\图第2行的\ home-chart.php
在第2行的home-chart.php中我写了这样的代码:
session_start();
.
.
.
echo ' username: '.$_SESSION['user_name'];
Run Code Online (Sandbox Code Playgroud)
虽然有了这个警告我可以得到结果$_SESSION['user_name']但是当我试图清除这部分代码时:
session_start();
Run Code Online (Sandbox Code Playgroud)
我在屏幕上看不到任何结果.那么,你的解决方案是什么?
<?php
@session_start();
require_once '../class/chart.class.php';
$chart = new chart();
?>
<html>
<head>
<link href='../css/home-chart.css' rel='stylesheet' type='text/css' />
</head>
<body>
<div class='float_left' style="margin-bottom:20px;">
<div class='float_left' style='line-height: 9.41px; font-size: x-small;'>0<br /></div> <div class='float_left' style="background-image: url('../image/web/chart.png'); width: 367px; height: 226px; " >
<!-- 1 --><div class='float_left float_left column' style='margin-left:2px;'>
<?php echo $chart->mysql_fetch($chart->daycal(-3)); ?>
</div>
<!-- 2 --><div class='float_left …Run Code Online (Sandbox Code Playgroud) TL; DR使用Nginx/PHP-FPM在Linux机器上获取错误,指出"由于标头已经发送,无法启动会话.".Apache本地计算机设置上未发生错误
所以在我的本地机器上我运行Symfony2应用程序.没有错误弹出.但是当我部署到我们的Linux服务器时,当我在Controller类中调用某个Action时,我遇到了这个错误
Failed to start the session because headers have already been sent.
Run Code Online (Sandbox Code Playgroud)
在我已经调用的索引操作中
$session = $this->getRequest()->getSession();
Run Code Online (Sandbox Code Playgroud)
在同一控制器类中的另一个动作中,我再次调用它.我尝试时会弹出错误
$session->set('foo', $bar);
Run Code Online (Sandbox Code Playgroud)
在我的Twig中,我通过一个表单和一个带有形成属性的按钮来调用动作
<form id='blahblah'>
.... some fields here .....
<button type='submit' formaction='{{path('2ndAction')}}'></a>
</form>
Run Code Online (Sandbox Code Playgroud)
所以在我的本地机器上运行Apache一切运行正常.Linux服务器正在使用Nginx和php-fpm,由于某种原因它崩溃了.我检查了phpInfo(),会话自动启动设置为关闭.不确定这是否是Nginx/php-fpm问题,但我认为这可能是相关信息.
这是Controller声明,indexAction()和我的2ndAction()
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use CBSi\Utils\HTTPUtils\CURLUtil;
class StartController extends Controller
{
/**
* @var CurlUtil $curlUtil
*/
private $curlUtil;
/**
* @var AccessControl $accessControl
*/
private $accessControl;
/*placeholder for request object*/
private $requestHolder;
/**
* @Route("/path/for/action/one", name="start") …Run Code Online (Sandbox Code Playgroud) 我使用bluehost作为我的webhost,我遇到了一些问题.下面的代码是我的困惑点.
<?php
include '../init.php';
error_reporting(0);
?>
<div class='container'>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/bootstrap/css/responsive.css">
<link rel="stylesheet" type="text/css" href="/bootstrap/css/responsive.min.css">
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="SignIn.css">
<title>SoundBooth - Sign in</title>
<link rel="icon" href="../Images/Logo.png" type="image/x-icon"/>
</head>
<body background="../Images/BGMain.png">
<div class='signinLabel'>Sign in</div>
<div class='bg'></div>
<div class='user'>Username</div>
<div class='pass'>Password</div>
<form action="index.php" method='POST'>
<input name='Username' autocomplete="off"class='usr' type="text" style='height:34px;'/>
<input name='Password' autocomplete="off"class='pas'type="password" style='height:34px;'/>
<input type='submit' class='submit' value='Log in' ></input>
</form>
<a class='forgotPass' href="#">(Forgot password)</a>
<div class='no-account-label'>Don't have …Run Code Online (Sandbox Code Playgroud)