用户评论:

[#1]

Tugrul [2015-03-09 17:04:49]

Creating New Session

==========================

session_start();$_SESSION["newsession"]=$value;?>

Getting Session

==========================

session_start();$_SESSION["newsession"]=$value;echo$_SESSION["newsession"];?>

Updating Session

==========================

session_start();$_SESSION["newsession"]=$value;$_SESSION["newsession"]=$updatedvalue;?>

Deleting Session

==========================

session_start();$_SESSION["newsession"]=$value;

unset($_SESSION["newsession"]);?>

Reference: http://gencbilgin.net/php-session-kullanimi.html

[#2]

Aswad [2014-11-27 05:01:16]

My session variable dies when it switches on some other page and I can't get it's value on other pages.

$_SESSION["username"]=filter_input(INPUT_POST,"username");

and on the top of every page, I have started the session by using this statement

session_start();

Can anybody help me?  I can't use 1 hidden field in every page just to store the value of 1 attribute. What if I need many variables then using hidden fields for all of them will be a bad approach.

Thanks.

[#3]

Fred [2013-09-07 03:09:40]

Regarding array keys, from http://php.net/manual/en/language.types.array.php, "Strings containing valid integers will be cast to the integer type".

The manual on $_SESSION says "An associative array". So an associative array is expected literally...? It does no one any good if this bit of important info about accessing and storing session data remains buried in manual comments.

Session variables with a single number will not work, however "1a" will work, as will "a1" and even a just single letter, for example "a" will also work.

(Invalid)

1st page

session_start();$_SESSION["1"] ="LOGGED";?>

2nd page

session_start();

echo$_SESSION["1"];?>

---------------------------------------------------------------

(Valid)

1st page

session_start();$_SESSION["a"] ="LOGGED";?>

2nd page

session_start();

echo$_SESSION["a"];?>

---------------------------------------------------------------

(Valid)

1st page

session_start();$_SESSION["a1"] ="LOGGED";?>

2nd page

session_start();

echo$_SESSION["a1"];?>

---------------------------------------------------------------

Example from PHP.net manual on Session variables

$_SESSION[1][1] ='cake';// fails$_SESSION['v1'][2] ='cake';// works?>

Source: http://php.net/manual/en/language.types.array.php

[#4]

opajaap at opajaap dot nl [2013-08-31 11:51:39]

Be carefull with $_SESSION array elements when you have the same name as a normal global.

The following example leads to unpredictable behaviour of the $wppa array elements, some are updated by normal code, some not, it is totally unpredictable what happens.

<?phpglobal $wppa;$wppa= array('elm1'=>'value1','elm2'=>'value2', ....etc...);

if ( !session_id() ) @session_start();

if ( ! isset($_SESSION['wppa'])$_SESSION['wppa'] = array();

if ( ! isset($_SESSION['wppa']['album']) )$_SESSION['wppa']['album'] = array();$_SESSION['wppa']['album'][1234] =1;$wppa['elm1'] ='newvalue1';print_r($_SESSION);?>

This will most likely display Array ( [wppa] => Array ( [album] => Array ( [1234] => 1 ) [elm1] => 'newvalue1' [elm2] => 'value2' ... etc ...

But setting $wppa['elm1'] to another value or referring to it gives unpredictable results, maybe 'value1', or 'newvalue1'.

The most strange behaviour is that not all elements of $wppa[xx] show up as $_SESSION['wppa'][xx].

[#5]

Miller [2013-08-12 20:48:05]

I wrote a little page for controlling/manipulating the session. Obviously, never use this on a production server, but I use it on my localhost to assist me in checking and changing session values on the fly.

Again, it makes use of eval() and exposes the session, so never use this on a web server.

error_reporting(E_ALL);session_start();

if (isset($_POST['session'])) {$session= eval("return{$_POST['session']};");

if (is_array($session)) {$_SESSION=$session;header("Location:{$_SERVER['PHP_SELF']}?saved");

}

else {header("Location:{$_SERVER['PHP_SELF']}?error");

}

}$session=htmlentities(var_export($_SESSION,true));?>

html>

Session Variable Management

textarea { font: 12px Consolas, Monaco, monospace; padding: 2px; border: 1px solid #444444; width: 99%; }

.saved, .error { border: 1px solid #509151; background: #DDF0DD; padding: 2px; }

.error { border-color: #915050; background: #F0DDDD; }

Session Variable Management

The session was saved successfully.

The session variable did not parse correctly.

"><?php  echo $session;?>

[#6]

pike-php at kw dot nl [2011-02-07 06:00:29]

When accidently assigning a unset variable to $_SESSION, like

$_SESSION['foo'] = $bar

while $bar was not defined, I got the following error message:

"Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. "

The errormessage was quite unrelated and got me off-track. The real error was, $bar was not defined.

[#7]

Dave [2009-11-17 14:05:47]

If you deploy php code and cannot control whether register_globals is off, place this snippet in your code to prevent session injections:

[#8]

charlese at cvs dot com dot au [2009-07-04 18:47:26]

I was having troubles with session variables working in some environments and being seriously flaky in others. I was using $_SESSION as an array. It works properly when I used $_SESSION as pointers to arrays. As an example the following code works in some environments and not others.

if (isset($_SESSION['form_convert'])){$form_convert=$_SESSION['form_convert'];

}

}?>

The following works well.

}else{$form_convert= array();$_SESSION['form_convert']=$form_convert;

}?>

[#9]

bohwaz [2008-08-31 14:43:37]

Please note that if you have register_globals to On, global variables associated to $_SESSION variables are references, so this may lead to some weird situations.

session_start();$_SESSION['test'] =42;$test=43;

echo$_SESSION['test'];?>

Load the page, OK it displays 42, reload the page... it displays 43.

The solution is to do this after each time you do a session_start() :

{

foreach ($_SESSIONas$key=>$value)

{

if (isset($GLOBALS[$key]))

unset($GLOBALS[$key]);

}

}?>

[#10]

Steve Clay [2008-08-17 06:28:18]

Unlike a real PHP array, $_SESSION keys at the root level must be valid variable names.

$_SESSION[1][1] ='cake';// fails$_SESSION['v1'][1] ='cake';// works?>

I imagine this is an internal limitation having to do with the legacy function session_register(), where the registered global var must similarly have a valid name.

[#11]

jherry at netcourrier dot com [2008-08-01 16:16:05]

You may have trouble if you use '|' in the key:

$_SESSION["foo|bar"] = "fuzzy";

This does not work for me. I think it's because the serialisation of session object is using this char so the server reset your session when it cannot read it.

To make it work I replaced '|' by '_'.

php 原生session,$_SESSION相关推荐

  1. 大叔也说Xamarin~Android篇~原生登陆与WebView的网站如何共享Session

    回到目录 事情是这样的,我们最近开了一个APP,主要使用xamarin做了一个登陆,它与服务器API进行数据通讯,当用户名密码正确去,跳转到新的activity,并在webview控件中打开服务端的H ...

  2. [转]PHP用mysql数据库存储session

    From : http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/0226/4002.html 大部分使用php的人一旦应用到sessio ...

  3. PHP中session特点及用途,PHP特点之会话机制2——Session及其使用

    会话机制(Session)在 PHP 中用于保存并发访问中的一些数据.这使可以帮助创建更为人性化的程序,增加站点的吸引力. 一个访问者访问你的 web 网站将被分配一个唯一的 id, 就是所谓的会话 ...

  4. php原生session,利用Memcached在php下实现session机制 替换PHP的原生session支持

    方法文件 session实现文件:memcachedsession.php 实现原理(也是PHP内部session的实现原理): 1.先判断客户端有没有sessionid, a.没有就添加一个sess ...

  5. PHP Cookie和Session

    cookie cookle常用来识别用户,可以理解为浏览器留下的一种文件,cookie可以分为会话cookie和硬盘cookie两种,会话cookie生命周期短,浏览器关闭即销毁,硬盘cookie生命 ...

  6. 苹果原生二维码扫描器

    项目中一直用的ZBar的扫描,后来发现速度明显和微信差很多,然后就想着替换成原生的,自己动手弄了一个简陋的扫描器,支持相册扫描,手电筒等.大神勿喷. 项目连接:https://github.com/S ...

  7. 纯手写原生PHP网站管理后台系统 网站管理系统

    一.源码简介 一套纯手写原生的PHP网站管理后台,前端利用LayUI实现,实现PHP初学者专研学习使用,对于PHP学习的人,只有熟悉了原生的PHP开发,才适合利用其它框架搭建自己的网站平台.封城期间, ...

  8. iOS 原生二维码扫描和生成

    代码地址如下: http://www.demodashi.com/demo/12551.html 一.效果预览: 功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描 ...

  9. php 屏蔽微信分享,微信sdk实现禁止微信分享(使用原生php实现)

    在此之前我们已经学习过微信的sdk使用,但是之前实在easyWechat的php插件基础上实现的,具体可以参考:https://www.wj0511.com/site/detail.html?id=3 ...

最新文章

  1. 特征工程(一)countvectororizer
  2. MyBatisPlus中进行通用CRUD全局策略配置
  3. 【深入浅出MyBatis系列十一】缓存源码分析
  4. primefaces_懒惰的JSF Primefaces数据表分页–第2部分
  5. 递归问题(代码、分析、汇编)
  6. 【Java从入门到头秃专栏 7】语法篇(六) :Lambda表达式(->) 方法引用(::) stream流
  7. DEDECMS 关键字不能小于2个字节!
  8. .net 中使用Javacript弹出提示窗口方法总结
  9. js 调用微信浏览器内置方法,启动支付
  10. python字典实例简单代码_python编程入门九:字典实例代码
  11. 了解数据分析师,转行数据分析师,成为数据分析师
  12. PiaolinPlatformV3.0.0 - 调用手机或电脑摄像头进行拍摄(拍照模块上线)
  13. 你绝对能看懂的Kafka源代码分析-Kafka Producer设计分析
  14. 具有完全权限的管理员”的功能介绍
  15. How to customize the UI in IBM ITIM Solution
  16. [转载]STL之priority_queue
  17. 习题5-4 使用函数求素数和 (20 分)
  18. Streambox Ripper的问题
  19. 2008年软考初级程序员试题(下午题)
  20. 七、CSS背景(background简写)

热门文章

  1. 微软想做apple和google的的混合体
  2. 2021-2025年中国脱水泵行业市场供需与战略研究报告
  3. 文献阅读(73)AAAI2022-SAIL: Self Augmented Graph Contrastive Learning
  4. 银联unionpay取消订单与超时时间
  5. 记忆法——《认知天性》
  6. QString、int、char、QByteArray直接的相互转换
  7. JWT之token机制与双token详解
  8. C1.Win.C1GanttView.C1GanttView 甘特图使用经验:子任务
  9. 【项目】区块链+人工智能 ---PAI白皮书分析(二)
  10. Python办公自动化实践1:从多个excel表中提取数据并汇总到一个工作表页中,表格,抽取,sheet