php 在 Code Igniter 中启动会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9650933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:21:51  来源:igfitidea点击:

Starting Sessions in Code Igniter

phpcodeignitersessionsyntax-error

提问by CodeTalk

starting at the top of the view:

从视图顶部开始:

<?php ### CREATE SESSION **
$this->load->library('session'); $this->load->library('encrypt');

$newdata = array(
'session_id'  => random hash,
'ip_address'    => 'string - user IP address',
'user_agent'    => 'string - user agent data',
'last_activity' => timestamp
);

$session_id = $this->session->userdata('session_id');

?>

Getting this error:

收到此错误:

Parse error: syntax error, unexpected T_STRING, expecting ')'  on line 5

how do I fix this?

我该如何解决?

回答by F21

Looking at your new comments, to start a session all you need to do is:

查看您的新评论,要开始会话,您需要做的就是:

<?php
   //Start session
   $this->load->library('session');

   //Try retriving data:
   $session_id = $this->session->userdata('session_id');
   echo $session_id;