从会话数组中提取两个单个变量 [英] Pulling two single variables from a Session Array

查看:56
本文介绍了从会话数组中提取两个单个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已创建并存储的会话.在另一页上,我想从此会话中提取两个变量.我想以欢迎方式呼应的变量之一,以及我想在查询中使用的另一个变量来更新mysql表.我只是不太了解正确的用语,因为我确实没有使用过会话,而其他人则创建了初始代码.会话名称确实给我带来了麻烦.

I have a session that is created and stored. On another page, I want to pull two variables from this session. One of the variables I want to echo as a welcome and the other I want to use in a query to update a mysql table. I just can't quite seem to figure out the correct wording as I have really not worked with sessions and someone else created the initial code. The session name is what is really giving me the trouble.

以下是用于命名会话的代码:

Here is the code for naming the session:

$directory = "http://$serverName/".$journalName['db'];
mysql_connect('server','user','pass');
mysql_select_db($journalName['db']);

ini_set('session.use_trans_sid', false);
ini_set('session.use_only_cookies', true);

session_name($journalName['db']);
session_set_cookie_params(6*60*60); // 6 hrs until login cookie expires
session_start();

它可能具有三个不同的会话名称.如果我打印数组(print_r($ _ SESSION);),则显示的内容如下:

It has the possibility of three different session names. If I do a print of the array (print_r($_SESSION);) here is what shows up:

Array ( [loggedin] => 1 [person] => 1 [account_id] => 1 [order_id] => [type] => individual [unlimited] => yes [status] => active [agreeterms] => no [bounced] => no [subscription_begin] => 0000-00-00 [subscription_end] => 0000-00-00 [contact_name] => Doe, Jane [email] => jane.doe@gmail.com [email_cc] => [institution] => IRA [net_addresses] => [department] => CELT [phone] => 123-456-9383 [address] => 303 S. Patterson Ave [city] => Butte [state] => ID [zip] => 12345 [country] => United States [tech_contact] => [tc_phone] => [tc_email] => [last_login] => 2014-12-15 13:20:24 [last_access] => 2012-03-28 13:45:23 [administrator] => yes [notes] => [last_reset] => 2011-11-19 13:36:59 [last_notified] => 2007-08-14 [combo] => no )

我想提取变量contact_name以便在页面顶部显示,我想提取变量email并使用它来运行和更新查询.这是我目前必须提取的contact_name:

I want to pull the variable contact_name for display at the top of the page and I want to pull the variable email and use it to run and update query. Here is what I currently have to pull the contact_name:

<?php echo "<h2>Account Owner or Contact Name:" .$_SESSION[["contact_name"]]. ",</h2>"; ?>

它根本不起作用.会议确实让我感到困惑.

It is not working at all. Sessions really have me flumoxed at the moment.

推荐答案

您是否可能打过错字?似乎$ _SESSION [["contact_name"]]应该是$ _SESSION ["contact_name"].没有多余的一对[]括号.

Is it possible that you just made a typo ? It seems $_SESSION[["contact_name"]] should be $_SESSION["contact_name"]. Without the extra pair of [] brackets.

还要添加

 session_start();

访问该页面,因为如果没有,则该会话将不可用

to the page, because if you don't the session will not be available

这篇关于从会话数组中提取两个单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆