473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

2 ways

hi all,

Having a session variable test .

Is there a difference between:
$test = "string";
or
$_session['test'] = "string";

kind regards
Stijn
Jul 17 '05 #1
3 1897
Yep first of all $_session doesn't exist

$_SESSION does though, so lets not forget about case sensitivity.
For portablity sake ALWAYS make sure you use
$_SESSION['test']="string";
Especially if you're not sure what version of PHP the host is running,
and/or what there php.ini reads like.
Also if register globals is on and there is a $_POST['test'] or a
$_GET['test'] you could get a conflicting variable that will be a HUGE
pain in the ass to track down.
Always best to test as far up the pipe as you can and then explicitly
assign.
I do it one of two ways, depending on what exactly I need.
I call this extremely explicit

if($_POST['test']){
$test = $_POST['test'];
$_SESSION['test']=$test;
}elseif($_GET['test']){
$test = $_GET['test'];
$_SESSION['test']=$test;
}elseif($_SESSION['test']){
$test = $test;
$_SESSION['test']=$test;
}

Or the sloppy way

extract($_SESSION);

If register globals (I think thats it) is turned on $_SESSION['test']
will automagically update, otherwise $_SESSION['test']=$test; is the
only way to go.

Someone please correct me, on the register globals comment, if I'm
wrong, but I know it's something.

Anyways more details can be had here
http://us2.php.net/manual/en/reserve...iables.session

"Stijn Goris" <me*****@hotmail.com> wrote in message news:<3f*********************@reader3.news.skynet. be>...
hi all,

Having a session variable test .

Is there a difference between:
$test = "string";
or
$_session['test'] = "string";

kind regards
Stijn

Jul 17 '05 #2
Uhm, this looks like assignment to me. A test would be conditional statment
like if.

if ( $_SESSION['test'] == 'bigfatbooger') {
do::someshit('bathroom');
}

= ( Assignment )
== ( test for equality )

There is also tests for existance, TRUE/FALSE tests.

if ($_SESSION['test']) {
cook::food('pizza');
} else {
pig::out('pork rinds');
}

Make sense?

Also, watch your case, no such monster as $_session, its $_SESSION.

"Stijn Goris" <me*****@hotmail.com> wrote in message
news:3f*********************@reader3.news.skynet.b e...
hi all,

Having a session variable test .

Is there a difference between:
$test = "string";
or
$_session['test'] = "string";

kind regards
Stijn

Jul 17 '05 #3
I think what he means is, does $_SESSION automagically keep track of
it's member variables and update accordingly.
The answer is, yes/no/maybe sometimes, it depends on the php version
and it's config.
The point I'm trying to make is this... Make sure assignment is ALWAYS
pointing to exactly what you want to assign.

Assuming $_SESSION['test'] ==1

$test = $_SESSION['test'];
$test ++;

Will produce one of two results.
Either $test will now == 2 and $_SESSION['test'] ==2
Or $test ==2 and $_SESSION['test'] ==1

It would be best, to have done this instead

$_SESSION['test'] ++;

This way we now know for sure it == 2

By the way, just ignore my first post, it was WAY too early in the
morning and I was kinda sleepy when I wrote it.
"Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<zBbnb.41390$Tr4.85919@attbi_s03>...
Uhm, this looks like assignment to me. A test would be conditional statment
like if.

if ( $_SESSION['test'] == 'bigfatbooger') {
do::someshit('bathroom');
}

= ( Assignment )
== ( test for equality )

There is also tests for existance, TRUE/FALSE tests.

if ($_SESSION['test']) {
cook::food('pizza');
} else {
pig::out('pork rinds');
}

Make sense?

Also, watch your case, no such monster as $_session, its $_SESSION.

"Stijn Goris" <me*****@hotmail.com> wrote in message
news:3f*********************@reader3.news.skynet.b e...
hi all,

Having a session variable test .

Is there a difference between:
$test = "string";
or
$_session['test'] = "string";

kind regards
Stijn

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Draken | last post by:
I have a menu of radio buttons with the name myform (thank you to Evertjan. for your help with my other problem, I have no idea where the error was but I worked through it from your advice) pretty...
22
by: Peter Ammon | last post by:
A friend was asked "How many ways are there to create an object in C++?" in an interview. Apparently, the "right" answer was eleven. Does anyone know how the interviewer arrived at that number? ...
4
by: Amir | last post by:
What's the difference between the two ways of opening a new window and writing to it? Let's say I prepare a code that goes into a new window and save it in a variable winHTML: var winHTML =...
2
by: big vinny | last post by:
Hi I've been writing some serializing functions to load/store classes into db tables. There appears to be 2 ways of doing it, 1) iterative, derived classes store their parent's data before...
8
by: Asha | last post by:
greetings, besides using objconn.State() to find out if a sql connection is close or open, is there any other way to accomplish this task? thanks in advance. anywhere is sql server or the machine...
9
by: storyGerald | last post by:
I knew some ways of swapping two ints without using a temporary variable. Just like: // Method 1: void swap1(int &a, int &b) { int temp = a; a = b; b = a; }
2
by: Chetan Raj | last post by:
Hi, What are the different ways in which a virtual function can be implemented by the C++ compiler? I know VTABLE and VPOINTER is only one of the way. What are the other ways? What are the pros...
1
by: Piper707 | last post by:
Hi, I'd like to know if there are any more ways of restricting an XML document to having only non-empty tags (containing Strings). I can think of 2 ways: 1) <xs:simpleType name="tagName">
2
by: Jen | last post by:
So I have the need to take UtcNow and change the Second to zero. Just wondering how many ways there are to do that?
0
by: geshan | last post by:
Lets see and compare the 4 ways (not tools) to develop/code your own PHP website or web application. The following are the ways you can code/develop your application (involving more Create Read...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.