当我刷新php页面时,有没有办法避免重新处理表单?我想在刷新带有插入功能的php文件的链接时阻止重新发送表单.例如,我正在处理用户在每页顶部写的一系列笔记,以获得新笔记.除了明显创建一个带有头功能的单独的php文件之外还有另外一种方法吗?
可能重复:
PHP已发送的标头
我正在创建一个简单的登录页面,但我的$_SESSION变量不是在页面之间传输.我在session_start()每个页面的开头,文件夹写作session_write_close()等等都阅读了很多其他帖子,但没有一个有效.该session_write_close()不会有所作为不论有无所以我刚刚离开它.所有下面的代码的正常工作,因为我已经低于和高于例如在离开了代码$login_fail的来源.
目前我设置的$_SESSION变量如下面的代码所示:
if($login_fail == "")
{
$query = "SELECT first_name, last_name, email_address,password FROM user_info WHERE email_address = '$email_address' AND password = '$password'";
$result = mysql_query($query);
if(!$result) die ("Database access : " .mysql_error());
elseif (mysql_num_rows($result))
{
$row = mysql_fetch_row($result);
$token = "$email_address";
$token1 = "$password";
echo "token: $token, token1: $token1, row[1]: $row[1], row2: $row[2] </ br>";
if($token == $row[2] && $token1 == $row[3])
{
session_start();
$_SESSION['first_name'] = …Run Code Online (Sandbox Code Playgroud) 请帮助我:当我锁定LOGIN按钮时,显示错误,我无法解决这个问题.我是php新手.
警告:无法修改标题信息 - 已在第56行的/home/kanak/public_html/celltopc/login.php中发送的标题(在/home/kanak/public_html/celltopc/login.php:33中开始输出)
我的代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link href="css/usercss.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-image: url(images/LoginForm_bg.jpg);
background-repeat: repeat;
}
-->
</style></head>
<body>
<div class="shadow" id="login">
<div id="login-body">
<form action="login.php" method="post" name="loginform">
<strong>Username:</strong>
<input name="username" type="text" class="input" value="username" maxlength="10" />
<p><br />
<strong>Password:</strong>
<input name="password" type="password" class="input" value="password" />
<p><br />
<input type="submit" name="submit" value="Login" width="30" class="myButton">
</form>
<p> <br />
<?php
ob_start(); …Run Code Online (Sandbox Code Playgroud) 我试图在标头函数中传递URL中的变量.我知道index2.php?ID=<?=$objResult["ID"];?>如果它不在标题函数中,我可以这样做
.但是,如果我尝试在头函数中执行此操作,则整个脚本崩溃.我也试过这个:
header("Refresh: 5;url=index2.php?ID=".$objResult["ID"]."");
Run Code Online (Sandbox Code Playgroud)
但是这会产生以下错误:
警告:无法修改标题信息 - 已在第33行的/var/www/Mail/index.php中发送的标题(在/var/www/Mail/index.php:25处开始输出)
(第33行是标题行)
我的整个代码是这样的:
<?php
if($_POST)
{
mysql_connect('localhost','root','root');
mysql_select_db('NAW') or die (mysql_error());
$Naam = $_POST['naam'];
$Email = $_POST['email'];
$Soort = $_POST['soort'];
$sql = mysql_query("INSERT INTO Klant (Naam, Email, Soort) VALUES ('".$Naam."', '".$Email."', '".$Soort."')") or die (mysql_error());
if ($sql === false) {
die (mysql_error());
}
else {
echo ''.$Naam.' is in de database toegevoegd.<br><br>';
}
$strSQL = ("SELECT * FROM Klant WHERE Naam='".$Naam."'");
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = …Run Code Online (Sandbox Code Playgroud) 我的控制器中有以下代码:
class ContactsController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function index() {
$this->set('contacts', $this->Contact->find('all'));
}
public function view($id) {
if (!$id) {
throw new NotFoundException(__('Invalid contact'));
}
$contact = $this->Contact->findById($id);
if (!$contact) {
throw new NotFoundException(__('Invalid contact'));
}
$this->set('contact', $contact);
}
public function add() {
if ($this->request->is('post')) {
$this->Contact->create();
if ($this->Contact->save($this->request->data)) {
$this->Session->setFlash('Your contact has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your contact.');
}
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHP的Sessions,我session_start();在我的开头使用它,index.php但得到以下错误消息:
警告:session_start()[function.session-start]:无法发送会话cookie - 已经在/home/ideal906/public_html/index.php中发送的输出(输出从/home/ideal906/public_html/index.php:1开始)在第2行
警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在/home/ideal906/public_html/index.php中发送的标头(输出从/home/ideal906/public_html/index.php:1开始)在第2行
这很奇怪,这是我网站的第一行:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="author" content="Pierre Anken">
<meta name="description" content="Outil de création de menus équlibrés selon vos besoins">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="jquery.js"></script>
<script src="scripts.js"></script>
<link rel="stylesheet" href="style.css" />
<title>Composez vos menus</title>
</head>
<body>
<section id='sectionCentre'>
<div id='presentation'>
<h2>Ideal Menu</h2>
</div>
</section>
<section id='bandeauHautDoite'>
<nav>
<ul>
<a href='#' elementMenu='monCompte' id='monCompte'>Mon compte</a><br/>
<a href='#' elementMenu='mesMenus' id='mesMenus'>Mes menus</a><br/>
<a …Run Code Online (Sandbox Code Playgroud) 我正在做一个作业,我应该用 MIME 类型“text/plain”显示一些文本。
<!DOCTYPE html>
<head lang="sv">
<meta charset=utf-8" />
<title>A Title</title>
</head>
<body>
<?php
header("Content-Type: text/plain");
echo("Hello");
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我加载页面时,会显示“hello”。但问题是除了 PHP 代码之外的其他所有内容也都显示了。这意味着结果是打印出所有 HTML 代码以及我使用 echo 方法打印的文本的页面。
我真的不知道为什么我应该使用 MIME 类型“text/plain”显示文本,但作业是这么说的。而且我对 PHP 还很陌生,所以这个问题可能很简单。但至少我找不到其他人遇到同样的问题。
所以我想要的是只显示 echo 方法中的文本,并且它应该具有 MIME 类型“text/plain”。这可能吗?
我开发了一个页面,用户可以使用该页面搜索我的数据库中的各种数据,但不会显示任何内容.
没有错误或消息显示它只是刷新页面.
bind_param对我来说是新的,所以我觉得这可能是一个错误 - $stmt->bind_param('s', $name);
我已经与数据库进行了比较,所有表名和变量名都是正确的.
search.php中
<html>
<?php
include 'searchform.php';
include 'header.php';
if(isset($_POST['searchsubmit']))
{
$name=$_POST['name'];
if ($stmt = $connection->prepare ("SELECT * FROM users WHERE Username = '$name'"))
{
$stmt->bind_param('s', $name);
$stmt->execute();
$stmt->bind_result($personresult);
$stmt->fetch();
print_r($personresult);
}
else
{
echo "<p>Please enter a search query</p>";
}
}
else
{
echo "NOT SET!";
}
?>
</html>
Run Code Online (Sandbox Code Playgroud)
显示错误
Warning: session_start(): Cannot send session cookie - headers already sent
searchform.php:2 which is displayed underneath:
<br><br><br><br>
<?php
error_reporting(E_ALL);
ini_set('display_errors', -1);
include 'header.php';
include 'connection.php'; …Run Code Online (Sandbox Code Playgroud) 我知道这个问题可能会被标记为重复,但是我从任何重复的帖子中都找不到答案,因此我决定将其张贴在自己的位置。
我有一个带有会话的页面。在完成所有任务之后,有一个链接到此控制器的按钮称为Profileresult.php,但即使我没有代码,但令我惊讶的是我遇到了此错误。
这是错误。
遇到PHP错误
严重程度:警告
消息:session_start():无法发送会话缓存限制器-标头已发送(输出从/home3/oep2732/public_html/knowyourscore/application/controllers/Profileresult.php:1开始)
文件名:Session / Session.php
行号:140
回溯:
文件:/home3/oep2732/public_html/knowyourscore/index.php行:315功能:require_once
我创建了一个名为Profileresult.php的控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profileresult extends CI_Controller {
public function index()
{
}
}
?>
Run Code Online (Sandbox Code Playgroud) 你能帮我在我本地的宅基地/流浪机器上解决这个问题吗?
当我运行命令时:PHPUnit
我得到这个结果
PHPUnit 4.8.36 由 Sebastian Bergmann 和贡献者编写。
E
时间:1.97 秒,内存:6.00MBRun Code Online (Sandbox Code Playgroud)There was 1 error: 1) ExampleTest::testBasicExample无法修改标头信息 - 标头已发送(输出开始于 /home/vagrant/Code/Project/vendor/php unit/phpunit/src/Util/Printer.php:134)
Run Code Online (Sandbox Code Playgroud)/home/vagrant/Code/Project/bootstrap/app.php:4/home/vagrant/Code/Poptin/tests/TestCase.php:20
/home/vagrant/Code/Project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85 /home/vagrant/Code /Project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64
请帮忙!我什么都试过了!!!
测试用例文件
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
//protected $baseUrl = 'http://localhost';
protected $baseUrl = 'http://192.168.10.10';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return …Run Code Online (Sandbox Code Playgroud)