473,666 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1917
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($_SESSI ON['test']){
$test = $test;
$_SESSION['test']=$test;
}

Or the sloppy way

extract($_SESSI ON);

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*****@hotmai l.com> wrote in message news:<3f******* **************@ reader3.news.sk ynet.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('b athroom');
}

= ( Assignment )
== ( test for equality )

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

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

Make sense?

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

"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************@r eader3.news.sky net.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 #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.413 90$Tr4.85919@at tbi_s03>...
Uhm, this looks like assignment to me. A test would be conditional statment
like if.

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

= ( Assignment )
== ( test for equality )

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

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

Make sense?

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

"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************@r eader3.news.sky net.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 #4

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

Similar topics

4
1709
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 much one of them HAS to be selected (it would be hard to avoid it) and my loop cycles through until if finds the checked button... as I have no way to tell how many items there will be in the array of menu items I cant put a static number in the...
22
7862
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? Is this fact well known (if true)?
4
2440
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 = "<HTML><HEAD><TITLE>Any title</TITLE><BODY>Any text</BODY></HEAD>"; Now, I have two ways to open a new window and write that code into the new
2
1657
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 storing themselves, including the pkey of their parents in their own tables. This results in each level of inheritence having a table solely for data specific to that inheritence level. 2) wholesale dump of class into one table. this means every...
8
1445
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 to tell this?
9
1442
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
1740
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 and cons of these different ways? Why is VTABLE and VPOINTER method, the most preffered method? Thanks, Chetan Raj
1
2171
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
16002
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
1867
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 Update Delete - CRUD) or a website (that has visitors and is more Web 2.0 - It does have CURD but thats not its core). The table below reveals the comparison: More at: http://geshan.blogspot.com/2008/11/4-ways-to-develop-your-php-website-or.html
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.