php为什么用$_SESSION会出错?解决思路
php为什么用$_SESSION会出错?
//session1.php:
//session1.php
session_start();
echo "欢迎:第一页
";
$_SESSION['myword']="我是张三";
$_SESSION["myage"]="18";
$_SESSION["mysex"]="男";
echo "Cookie中myword值是:".$_SESSION['myword']."
";
echo "下一页";
?>
//session2.php
//session2.php
session_start();
echo "欢迎:第二页
";
echo "姓名:".$_SESSION['myword']."
";
echo "年龄:".$_SESSION["myage"]."
";
echo "性别:".$_SESSION["mysex"]."
";
echo "下一页";
?>
打开session1.php,输出
------------------------------------
欢迎:第一页
Cookie中myword值是:我是张三
下一页
------------------------------------
点击“下一页”打开session2.php输出
------------------------------------
欢迎:第二页
Notice: Undefined index: myword in R:\Program Files\AppServ\www\session\session2.php on line 5
姓名:
Notice: Undefined index: myage in R:\Program Files\AppServ\www\session\session2.php on line 6
年龄:
Notice: Undefined index: mysex in R:\Program Files\AppServ\www\session\session2.php on line 7
性别:
下一页
------------------------------------
是不是配置的问题? 我的php.ini的session配置如下:
session.save_handler = files
session.save_path = "R:/Program Files/AppServ/php5/session_tmp"
; session.save_path = "N;MODE;/path"
session.save_path = "R:/Program Files/AppServ/php5/session_tmp"
(有三个session.save_path)
session.cookie_domain = Cookies
(其他的就不一一列出了)
------解决方案--------------------
session.cookie_domain =
修改为这样或者注释掉,然后重启服务器
我估计这种情况是没读取到cookie PHPSESSID导致的,你可以用print_r($_COOKIE) 来看看有没有PHPSESSID
------解决方案--------------------
见#1楼,session.cookie_domain不要乱设置,该怎么设置自己搜.你本地测试绑定域名做什么。
------解决方案--------------------
发个session问题总结:
对于PHP的session功能,始终找不到合适的答案,尤其是一些错误,还有一些没有错误的结果,最可怕的就是后者,一直为许多的初学者为难。就连有些老手,有时都被搞得莫名其妙。本文,将这些问题,做一个简单的汇总,以便大家查阅。
1.
错误提示
Warning: Cannot send session cookie - headers already sent
Warning: Cannot send session cache limiter - headers already sent
分析及解决办法
这一类问题,的原因是你在程序中使用session_start()时,之前已经有实际的html内容输出了。或许你说,我没有啊,我只不过是echo或print一条消息了。很抱歉,你的echo或print语句所产生的输出,就是实际的html内容输出。解决此类问题的办法是,将你的session_start()调到程序的第一行。
2.
错误提示
Warning: open(F:/689phpsessiondatasess_66a39376b873f4daecf239891edc98b5, O_RDWR) failed
分析及解决方法
出现这样的错误语句一般是因为你的php.ini中关于session.save_path一项没有设置好,解决的方法是将session.save_path和session.cookie_path 设置置为
session_save_path = c: emp
session.cookie_path = c: emp
然后在c:目录下建立一个temp目录,即可
3.
错误提示
Warning: Trying to destroy uninitialized session in
分析及解决方法
出类这样的提示,一般情况都是你直接调session_destroy()函数造成的。很多的朋友认为session_destroy()函数可以独立的运行,其实不然。解决的方法是在你调session_destroy()函数之前,要用session_start()开启session的功能。
4.问题:怎么获得当前session的id值呢?
最简单的方法是:
echo SID;
你会发现的。
5.问题:我的程序,在调用header函数之前没有任何的输出,虽然我include了一个config.php文件,但在config.php文件中也没有任何的输出,为什么session还是会报出与问题1同样的错误呢,是不是因为我在header之前用了session_start()的缘故呢?
答:或许你确实认真的检查了你的php程序,在引用header()之前确实也没有任何的输出,并且在你的include文件中也没有任何的输出!但是你是否用光标键在?>这个PHP代码结束语句后移动检查呢?那么你会发现在?>这个后面,有一个空行或几个空格,你删除了这几个空行或空格,那么问题就解决了。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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 is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
