我一直在网站上工作,并有以下代码......
<html>
<?php
session_start();
//if not logged redirect
if(!$_SESSION['logged']){
header("location:restricted.php");
}
else
//else continue and display the rest of the page
{
//html page content here
?>
Run Code Online (Sandbox Code Playgroud)
...显然,这样做是检查会话变量'logged'是否已设置,如果不是,用户将被重定向到restricted.php,否则将显示其余代码(此页面).这是在服务器上工作正常,但我刚刚使用另一个主机(显然是服务器),如果没有设置会话,用户只是有一个空白页面(标题为此页面,不受限制.php ).有人知道为什么会这样吗?非常非常感谢...
完成错误:
Warning (2): Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/trunk/dafe/cake/basics.php:355) [CORE/cake/libs/controller/controller.php, line 743]
Run Code Online (Sandbox Code Playgroud)
据我尝试重定向,我可以告诉它.我知道它是由空格引起的,但我无法在任何地方找到它,这个错误往往在哪里?
编辑:忘了提,这个问题只发生在我的Mac上,我在Windows上的合作伙伴没有这个问题,重定向适合他.
可能重复:
PHP已发送的标头
我的问题是我有一个带有函数的类,我得到了;
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/inc/class.php:105) in /home/user/public_html/inc/facebook/login.php on line 21
Run Code Online (Sandbox Code Playgroud)
当我正在使用它的页面重定向用户头(); 标签.这堂课是;
class mysql {
private $user;
private $pass;
private $db;
public function __construct($user1, $pass1, $db1) {
$this->user = $user1;
$this->pass = $pass1;
$this->db = $db1;
$this->connect();
}
public function connect() {
$this->connection = mysql_connect('localhost', $this->user, $this->pass);
$select = mysql_select_db($this->db, $this->connection);
}
public function query($x) {
return mysql_query($x);
}
public function fetch($x) {
return mysql_fetch_array($x);
}
public function …Run Code Online (Sandbox Code Playgroud) 我正在为我的学校做一个项目而且我写了这个页面,但由于某种原因,我最后得到2个警告,关于已经在132行发送的标题信息但是在132行我只有php标签
我真的很感激,如果我能得到一些帮助,我在1小时内编写了这段代码但是在过去2小时内试图解决这个问题...终于累了,决定问它
这是我的代码
<html>
<body>
<form method="POST">
Browse By Author's name starting with :<select name="author">
<option value="">--Select--</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="G">G</option>
<option value="H">H</option>
<option value="I">I</option>
<option value="J">J</option>
<option value="K">K</option>
<option value="L">L</option>
<option value="M">M</option>
<option value="N">N</option>
<option value="O">O</option>
<option value="P">P</option>
<option value="Q">Q</option>
<option value="R">R</option>
<option value="S">S</option>
<option value="T">T</option>
<option value="U">U</option>
<option value="V">V</option>
<option value="W">W</option>
<option value="X">X</option>
<option value="Y">Y</option>
<option value="Z">Z</option>
</select><br><br>
Browse by Title start with :<select name="title">
<option value="">--Select--</option>
<option …Run Code Online (Sandbox Code Playgroud) 我正在使用这个PHP脚本将文件INSERT(上传)到我的Google云端硬盘,它的完美:
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$drive = new Google_Client();
$drive->setClientId('XXX');
$drive->setClientSecret('YYY');
$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$drive->setScopes(array('https://www.googleapis.com/auth/drive'));
$gdrive = new Google_DriveService($drive);
$drive->setAccessToken(file_get_contents('token.json'));
$doc = new Google_DriveFile();
$doc->setTitle('Test');
$doc->setDescription('Test Document');
$doc->setMimeType('text/plain');
$content = file_get_contents('test.txt');
$output = $gdrive->files->insert($doc, array(
'data' => $content,
'mimeType' => 'text/plain',
));
print_r($output);
Run Code Online (Sandbox Code Playgroud)
现在我想更新(不上传)我现有的Google云端硬盘文件,我正在使用此脚本:
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$drive = new Google_Client();
$drive->setClientId('XXX');
$drive->setClientSecret('YYY');
$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$drive->setScopes(array('https://www.googleapis.com/auth/drive'));
$gdrive = new Google_DriveService($drive);
$drive->setAccessToken(file_get_contents('token.json'));
$fileId = "ZZZ";
$doc = $gdrive->files->get($fileId);
$doc->setTitle('Test'); // HERE I GET THE ERROR "CALL TO A MEMBER …Run Code Online (Sandbox Code Playgroud) 在我的内容执行后,我正在尝试进行PHP重定向,但是我无法让代码执行.
如果我加载它,它会重定向页面,但不会向数据库插入任何内容.如果我注释掉标题重定向行,它会将数据输入我的数据库.
如何让PHP运行并执行,然后重定向页面?
<?php require("gplus.php"); ?>
<?php require("database.php");?>
<?php if(isset($personMarkup)): ?>
<?php
$checkuser = "SELECT gid FROM user WHERE gid = '$id'";
$updateuser = "UPDATE user SET name = '$name', pic = '$img' WHERE gid = '$id'";
$adduser = "INSERT INTO user (gid, name, pic) VALUES ('$id','$name','$img')";
$checkuserrlt = mysqli_query($con, $checkuser);
if(mysqli_num_rows($checkuserrlt) > 0) {
$result = mysqli_query($con, $updateuser) or die(mysqli_error());
} else {
$result = mysqli_query($con, $adduser) or die(mysqli_error());
}
?>
<?php endif ?>
<?
mysqli_close($con);
?>
<?php
header( …Run Code Online (Sandbox Code Playgroud) 我收到以下错误:
警告:无法修改标题信息 - 已在第4行的/home/content/89/11421189/html/notfound.php中发送的标题(在/home/content/89/11421189/html/notfound.php:2处开始输出)
在我的文件'notfound.php'中,它使用以下代码:
<!DOCTYPE html>
<?php//Line 2
ob_start();
header('Location:http://www.website.com/index.php?page=404.php', true, 302);
exit;
?>
<head>
</head>
<html>
</html>
Run Code Online (Sandbox Code Playgroud)
请注意,PHP标记之前或之后没有空格.无论我将它移动到哪里(即使它都在同一条线上),该行是错误的罪魁祸首.我在这做错了什么?
[编辑]注意:如果我将PHP移动到DOCTYPE标记之前,导航到此文件会给出错误403:禁止.位置很好,因为我可以将其复制/粘贴到地址栏中而不会出现问题.你能通过header()传递GET参数吗?
我知道这个问题已被多次询问,但是,我似乎无法找到与我的情况相关的解决方案,因为它们主要处理wordpress.
这是我的邮件表格:
<?php
$to = "email@gmail.com" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Contact Submission From domain.com";
$fields = array();
$fields{"name"} = "name";
$fields{"title"} = "title";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"prefer_phone"} = "pref_phone";
$fields{"prefer_email"} = "pref_email";
$fields{"message"} = "message";
$fields{"referral"} = "referral";
$body = "Here is their submitted message:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n\n",$b,$_REQUEST[$a]); }
if($from == '') {print "You have not entered an email, please …Run Code Online (Sandbox Code Playgroud) <table>
<tr>
<td width="30"></td>
<td><img src="Images/logo.jpg" width="100" height="100" />
<td><td><h2> Kunal Structures (India) Pvt. Ltd.</h2></td>
</tr>
</table>
<?php
if(!isset($_SESSION['user_id']))
{
header("location:http://127.0.0.1/New%20folder/KSIPL1.10/KSIPL/index.php");
}
else
{
$now = time(); // checking the time now when home page starts
if($now > $_SESSION['expire'])
{
header("location: http://127.0.0.1/KSIPL1.10/KSIPL/index.php");
echo "Session Expired !"." <a href='http://127.0.0.1/New%20folder/KSIPL1.10/KSIPL/index.php'>"." <h1> ".
"Login again"." </h1>"."</a>";
session_destroy();
}
else
{
$qry = mysql_query("SELECT * FROM user_main WHERE user_id=".$_SESSION['user_id']."");
$loguser=mysql_fetch_assoc($qry);
?>
<table class="headerinfo" align="right">
<tr>
<td>You are <span style="color:#40B3BA;"><?php echo $loguser['user_name']; ?></span>,</td>
<td><a style="color:#f5f5f5; text-decoration:none;" …Run Code Online (Sandbox Code Playgroud) 不可否认,自从我进入php世界以来已经有一段时间了,但我不确定为什么我在json_encode字符串的开头有3个空格.
" [{"id":"1","display_name":"Bob"}]"
Run Code Online (Sandbox Code Playgroud)
这是我有的PHP:
$stmt = $conn->prepare("SELECT * FROM users");
$queryResult = array();
if ($stmt->execute()) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$queryResult[] = $row;
}
echo json_encode($queryResult);
}
Run Code Online (Sandbox Code Playgroud)
当我回声时,print_r($stmt->fetch(PDO::FETCH_ASSOC)) 我得到以下内容:
Array
(
[id] => 1
[display_name] => Twitch Dock John
)
Run Code Online (Sandbox Code Playgroud)
那里还有3个空间..我做错了什么(期待传入的脸部时刻)?
php ×10
html ×3
redirect ×2
cakephp ×1
contact-form ×1
google-api ×1
header ×1
http-headers ×1
mysql ×1