还是我,刚才那个写的可能比较乱,大家没理解我意思。从新写一个,希望大家能帮我
以下是我的关键程序部分单一入口index.php:
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new index();
$Action->indexAction();
?>init.php
<?php
session_start();//这里是不是整个程序的session都启动了。
?>controllers/index.php
<?php
class index{
function indexAction(){
echo "接受到的session:".$_SESSION['test'];//只输出了接受到的session:
}
}
?>
test.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
$_SESSION['test'] = 'test';//模拟给session赋值
?>test2.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
echo $_SESSION['test'];//输出test。直接在页面中调用session正常。
?>
小弟的基本思路就是这样了
1)执行test.php,给$_SESSION['test']赋值
2)index.php中引用init.php,session启动
3)index.php引用controllers/index.php
4) index.php实例化一个对象index
5)index.php中调用index对象的方法indexAction()
发现能够调用成功方法,但是没有获取到$_SESSION['test']
于是新建页面test2.php测试$_SESSION['test']是否有值
在test2.php中$_SESSION['test']被获取到请问我现在如何才能在indexAction()方法中获取到$_SESSION['test']。谢谢大家了。
以下是我的关键程序部分单一入口index.php:
<?php
require_once("init.php");
require_once("controllers/index.php");
$Action = new index();
$Action->indexAction();
?>init.php
<?php
session_start();//这里是不是整个程序的session都启动了。
?>controllers/index.php
<?php
class index{
function indexAction(){
echo "接受到的session:".$_SESSION['test'];//只输出了接受到的session:
}
}
?>
test.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
$_SESSION['test'] = 'test';//模拟给session赋值
?>test2.php//此页面为测试页面。模拟给$_SESSION['test']赋值
<?php
session_start();
echo $_SESSION['test'];//输出test。直接在页面中调用session正常。
?>
小弟的基本思路就是这样了
1)执行test.php,给$_SESSION['test']赋值
2)index.php中引用init.php,session启动
3)index.php引用controllers/index.php
4) index.php实例化一个对象index
5)index.php中调用index对象的方法indexAction()
发现能够调用成功方法,但是没有获取到$_SESSION['test']
于是新建页面test2.php测试$_SESSION['test']是否有值
在test2.php中$_SESSION['test']被获取到请问我现在如何才能在indexAction()方法中获取到$_SESSION['test']。谢谢大家了。
http://topic.csdn.net/u/20100930/16/9b6f28ad-332f-4961-835b-b5f6956209b7.html
这贴的100分也给他。谢谢了。
<?php
class index{
public $str;
function indexAction($string){
$this->str=$string;
echo "接受到的session:".$this->str;
}
}
?>
$Action = new index();
$Action->indexAction($_SESSION('test'));
我现在要做个登陆,总不能把每一项要用的session都传参递过去啊根本的解决办法还是得在方法中能让session正常使用才行啊
你试下访问过test.php 再访问index.php
如果你的文件是utf8的 看下有没有报错 是不是多了 BOM头
ini_set('session.save_path', WEBSITE_ROOT.'/session');
init中session_start()前边有这句话,我给删了就好了
我关了浏览器从新开下试试。