这个问题原先提问过一次,但是没有回答,只好再次提问一次了。
用户登录的时候SESSION是写入了,值也赋值了。但是跳转到控制面板的时候,却全部都是空的。另外希望回答者不要说session之前不能有输出,echo输出,html输出之类的。因为session_start();我是放在了第一行的,
就在<?php的后面,因为这样会导致网页瘫痪,导致css和div控制不了,所以加了ob_start()。
涉及到的文件
index.php
cp.php----------------
index.php 文件执行流程:判断是否是已经登录的管理员,如果已经登陆了,那么跳转到cp.php控制面板,无任何提示的跳转,否则→判断是否有$_POST,如果有,就执行查询,进行登录验证,如果验证成功就跳转到cp.php控制面板,然后销毁$_POST,如果登录失败,也销毁$_POST,并且重新跳转到index.php。假如没有登录,并且也没有$_POST,那么引入登录表单。
index.php文件源码如下:<?php
ob_start();
session_start();
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval(trim($_SESSION[adminID]));
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id > 0){
$url='cp.php';
echo jump($url);
exit;
}
ob_end_clean();
if($_POST){
$psw=trim($_POST['psw']);
$name=trim($_POST['name']);
if($psw=='' || $name==''){
$msg='请将表单填写完整';
$url='index.php';
unset($_POST);
exit;
}
$psw=md5($psw);
$SQL="SELECT * FROM `zhidao_admin` WHERE `name` LIKE '$name' AND `psw` LIKE '$psw' LIMIT 0 , 1 ;";
$obj=new sDB();
$r=$obj->select($SQL);
if($r!=false){
$_SESSION[adminID]=$r[id];
$_SESSION[adminName]=addslashes($r[name]);
$_SESSION[adminTime]=time();
if($_SESSION[adminID] && $_SESSION[adminName]){
//$msg='登录成功!';
$url='cp.php';
}else{
$msg='出现错误';
$url='index.php';
}
}else{
$msg='登录失败!';
$url='index.php';
}
print_r($_SESSION);
include $dir.tpl.'alert.htm';
unset($_POST);
exit;
}
include $tpl.'login.htm';
?>
cp.php文件源码如下”
<?php
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval($_SESSION[adminID]);
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id < 1){
$msg='请先登录';
$url='index.php';
echo jump_quick($url,$msg);
exit;
}
include $tpl.'cp.htm';
?>其中的jump_quick();是返回js警告加跳转的代码。
后来因为我看到有人说注册了SESSION不要立即跳转,否则无法成功,所以新建了一个alert.htm文件作为模板放在了木板文件夹里面,文件全部内容如下“<!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></title>
</head><body>
<!--<?php
print <<<EOT
-->
<script language="javascript" type="text/javascript">
var url="${url}";
var msg="${msg}";
window.onload=function(){
if(msg!=''){
alert(msg);
}
if(url!=''){
window.location.href=url;
}else{
window.close();
}
}
</script>
<!--
EOT;
?>-->
</body>
</html>
大家帮我看下,我找了几天了,还是没有把这个问题解决掉。
而十分奇怪的是,前几天用这个还是正常的。
突然间就不能用了。IE临时文件我每次都清,还是没有用。
在网络上面看到有关PHP BOM的方面的,如何才可以解决?
这些文件包括站点内的所有文件编码都是utf-8
用户登录的时候SESSION是写入了,值也赋值了。但是跳转到控制面板的时候,却全部都是空的。另外希望回答者不要说session之前不能有输出,echo输出,html输出之类的。因为session_start();我是放在了第一行的,
就在<?php的后面,因为这样会导致网页瘫痪,导致css和div控制不了,所以加了ob_start()。
涉及到的文件
index.php
cp.php----------------
index.php 文件执行流程:判断是否是已经登录的管理员,如果已经登陆了,那么跳转到cp.php控制面板,无任何提示的跳转,否则→判断是否有$_POST,如果有,就执行查询,进行登录验证,如果验证成功就跳转到cp.php控制面板,然后销毁$_POST,如果登录失败,也销毁$_POST,并且重新跳转到index.php。假如没有登录,并且也没有$_POST,那么引入登录表单。
index.php文件源码如下:<?php
ob_start();
session_start();
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval(trim($_SESSION[adminID]));
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id > 0){
$url='cp.php';
echo jump($url);
exit;
}
ob_end_clean();
if($_POST){
$psw=trim($_POST['psw']);
$name=trim($_POST['name']);
if($psw=='' || $name==''){
$msg='请将表单填写完整';
$url='index.php';
unset($_POST);
exit;
}
$psw=md5($psw);
$SQL="SELECT * FROM `zhidao_admin` WHERE `name` LIKE '$name' AND `psw` LIKE '$psw' LIMIT 0 , 1 ;";
$obj=new sDB();
$r=$obj->select($SQL);
if($r!=false){
$_SESSION[adminID]=$r[id];
$_SESSION[adminName]=addslashes($r[name]);
$_SESSION[adminTime]=time();
if($_SESSION[adminID] && $_SESSION[adminName]){
//$msg='登录成功!';
$url='cp.php';
}else{
$msg='出现错误';
$url='index.php';
}
}else{
$msg='登录失败!';
$url='index.php';
}
print_r($_SESSION);
include $dir.tpl.'alert.htm';
unset($_POST);
exit;
}
include $tpl.'login.htm';
?>
cp.php文件源码如下”
<?php
$dir='../';
require $dir.'global.php';
$tpl=$dir.tpl.'admin/';
if($_SESSION[adminID]){
$a_id=intval($_SESSION[adminID]);
$a_name=trim($_SESSION[adminName]);
}else{
$a_id=0;
$a_name=null;
}
if($a_id < 1){
$msg='请先登录';
$url='index.php';
echo jump_quick($url,$msg);
exit;
}
include $tpl.'cp.htm';
?>其中的jump_quick();是返回js警告加跳转的代码。
后来因为我看到有人说注册了SESSION不要立即跳转,否则无法成功,所以新建了一个alert.htm文件作为模板放在了木板文件夹里面,文件全部内容如下“<!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></title>
</head><body>
<!--<?php
print <<<EOT
-->
<script language="javascript" type="text/javascript">
var url="${url}";
var msg="${msg}";
window.onload=function(){
if(msg!=''){
alert(msg);
}
if(url!=''){
window.location.href=url;
}else{
window.close();
}
}
</script>
<!--
EOT;
?>-->
</body>
</html>
大家帮我看下,我找了几天了,还是没有把这个问题解决掉。
而十分奇怪的是,前几天用这个还是正常的。
突然间就不能用了。IE临时文件我每次都清,还是没有用。
在网络上面看到有关PHP BOM的方面的,如何才可以解决?
这些文件包括站点内的所有文件编码都是utf-8
解决方案 »
- 如何第一条新闻显示摘要,后面的只显示标题
- PHP新手求助。谢谢啦。
- 多个数据库同时查询求和的问题?
- 提问分好像不少了
- 我等了10分钟。为什么SESSION就是不失效?!!!!疯了啊。。。SAVE ME PLEASE!!!
- 请各位达人帮忙看一下我这个程序哪里出了问题?
- 谁能给我讲讲unpack()的用法?
- 请问我用PHP为什么不能访问局域网中的SQL Server
- 哈哈,看看偶的不用查数据库的全文检索功能
- 谁能提供最好的安装方法:php4.2.2 for win32 在Windows 2000 的 IIS服务器上???
- 求正则 匹配【www.aa.com/index.php/news/read/1353/新闻标题】 如何写正则?
- 源码看不懂,请教。谢谢!
require ('data/config.php');
require ('class/mysql.php');
require ('class/func.php');
require ('class/session.php');
!defined('tpl') && define('tpl','templates/'.$tpl.'/');
define('XF_R','/'.basename(dirname(__FILE__)));
date_default_timezone_set('PRC');
//将当前的时区设置为 中国时区
//ini_set('display_errors', 1);
ini_set('display_errors', 0);
//error_reporting(E_ALL);
error_reporting(0);
$DB=new DB($host,$root,$psw,$db);
$DB->conn();
?>加了之后网页的显示无法控制了,瘫痪了。使用了ob_start();和ob_end_clean();后,那么$obj=new sDB(); 每次要用的时候都要重新写一次,非常不方便。应该是和ob_start();有关。
如果是就很可能是bom头的问题,ultraedit的话另存为的时候,编码选项框不是有个utf-8无bom头的选项么?