我是Laravel和PHP新手。
登录成功后,页面重定向到索引
控制器代码如下:
Session::save();
Redirect::to('index')
index.php
代码如下:
include(URL('index/index_top'));
include(URL('index/top_banner'));
问题是:会话数据在index.php
中可用,但在index_top.php
中不可用。index.php
页面显示正常。
我的英语很差,希望你能明白我的意思。在这里,我发现sessionid在include()
之后改变了,为什么?如何保留会话id ?
附加:routes.php
如下:Route::group(['prefix' => 'index'], function()
{
Route::get('index_top','index'indexController@showIndexTop');
Route::get('top_banner','index'indexController@bannerShow');
...
}
top_banner.php
如下:<div class="top_banner">
<?php
if($resultcode == 0){
$i = 0;
foreach ($banner["body"] as $info) {
$i++;
if($i==1){
echo "<img src='";
echo( $info['adpic']);
echo "'style='width:1200px;height:145px'/>";
...
问题是你的include语句。而不是包含本地视图,这意味着PHP将在相同的上下文中被包含和执行,您将包含一个URL,这意味着将发送一个单独的请求并包含其执行的结果。此请求没有附加任何上下文信息,如cookie,这将有助于识别您的会话,,这就是为什么会话数据不可用。
代替include(URL('index/index_top'));
include(URL('index/top_banner'));
include('index/index_top.php'); //or whatever local path to index_top.php is
include('index/top_banner.php'); //or whatever local path to top_banner.php is