php无法保存cookies有关问题解决
php无法保存cookies问题解决
今天弄php程序,突然发现一个问题,就是cookies无法保存,且不发生任何错误,经过一番查找发现问题如下:
因为程序在写Cookies是用的是?@setcookie ( "url", "http://www.my400800.cn ", time()+3600*24, "/");
PHP 的 @、# 符号的意思
{
??? $result = 1/$n;
??? return $result;
}
echo @foo(0); // 函数中会产生除 0 错误,但加上 @ 后并不显示该错误。
echo "end"; // 输出 end
# 注释符号
同 // 一样,# 是单行注释符(多行注释符为 /* */)。
由于使用了@setcookie,即便在写入cookies是发生错误,也不会输出,造成了无法发现问题。最后把@setcookie改成 setcookie,程序输出如下错误信息:
Warning: Cannot modify header information - headers already sent by (output started at
经过上网一查,发现原来在进行setcookie设置前不能有任何输出内容,然后就去检查代码,也没有发现在setcookie之前输出了东西,在搜索了一下,发现了问题所在,具体内容如下:
?
今天在WordPress中文论坛逛了一圈。坛子里人气不高,不过还是有很多高手的。会编写插件和模版的高手和连编辑文件都不会的初学者混在一起,论坛就是这样,哈哈。
看到好几个帖子里提到同一个错误,比如这个帖子里提到的:"Warning: Cannot modify header information -
headers already sent by (output started at c:\program
files\easyphp1-8\www\wp-config.php:1) in c:\program
files\easyphp1-8\www\wp-login.php on line 9"
这是一个很典型的问题。WordPress的程序执行时会首先调用wp-config.php一类的配置文件,也会调用wp-db.php建立数据库连接
以备后用。这些文件只是做一些设置,并不输出html代码。设置完了后,程序本身开始执行了,有些程序会使用header命令设置一个HTTP头。由于
HTTP头必须在html代码输出之前设置好,否则html代码已经开始往客户端发送了,HTTP也就已经发送过了,没法追回来重新设置了。
WordPress CodeX里对这个问题作出了说明:《How do I solve the Headers already sent
warning
problem?》。文章指出:要确保各个文件――尤其是经常被编辑的wp-config.php文件――以结尾,前
后不能有其他字符。具体到上面的例子,很明显,提示信息说wp-config.php的第一行就开始了html输出,这有可能是第一行的本编辑了wp-config.php文件并保存成了UTF-8编码的文档,从而因为BOM的三个字符的输出造成了header命令执行出错
。
?
解决方法
WordPress
中文论坛没有提供全文搜索的功能,只能搜索标题,所以我用Google搜索了一下Cannot modify header information
site:wordpress.org.cn,好像碰到这个问题的人还真不少。目前大家用的WordPress主要是WordPress英文原版和几个
WordPress中文版。我的中文包又不包含wp-config-sample.php文件,自然不关我的事;WordPress原版用的ASCII
码,自然不包含BOM,也不会出这样的错误;xigang制作的WordPress中文版在WordPress中文论坛有下,我去下载了
WordPress 2.0.4和2.0.3这两个,检查了一下,没有问题;点点游的WordPress
2.0.4中文版里,wp-config-sample.php文件用的是GB2312编码和DOS行尾符,GOD!不过这样也好,如果有人用记事本修改
了这个文件,DOS行尾符不会造成编辑问题,GB2312编码不会造成BOM的问题,呼。
唉,如果你要用WordPress架Blog,还是扔掉记事本,装个UltraEdit或者EditPlus吧!
?
?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...
