473,777 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_SESSION $_POST

hi

i've got a basic user register form, action="POST". in my php code (on
the same page, i store the $_POST stuff to a $_SESSION if the user
screws a field up so they don't have to reenter all their info. But
i'm thinking, why should i use $_POST at all if i can just us the
$_SESSION array? or maybe even vice versa? or am i doing this all the
wrong way?

cheers
dave
Jul 17 '05 #1
15 3715
*** mammothman42 escribió/wrote (17 Sep 2004 20:04:16 -0700):
i've got a basic user register form, action="POST". in my php code (on
the same page, i store the $_POST stuff to a $_SESSION if the user
screws a field up so they don't have to reenter all their info. But
i'm thinking, why should i use $_POST at all if i can just us the
$_SESSION array?


If you can store the $_POST stuff into a $_SESSION without using $_POST...
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #2
mammothman42 wrote:
hi

i've got a basic user register form, action="POST". in my php code (on
the same page, i store the $_POST stuff to a $_SESSION if the user
screws a field up so they don't have to reenter all their info. But
i'm thinking, why should i use $_POST at all if i can just us the
$_SESSION array? or maybe even vice versa? or am i doing this all the
wrong way?

cheers
dave


This is actually a very good question. I would like to see more answers
from the group regarding this. I would personally want to see speed
benchmark comparisons on what is faster: lots of session data and less
arrays, or very little session data with lots of arrays.

Jul 17 '05 #3
Alvaro G. Vicario wrote:
*** mammothman42 escribió/wrote (17 Sep 2004 20:04:16 -0700):
i've got a basic user register form, action="POST". in my php code
(on the same page, i store the $_POST stuff to a $_SESSION if the
user screws a field up so they don't have to reenter all their info.
But i'm thinking, why should i use $_POST at all if i can just us the
$_SESSION array?


If you can store the $_POST stuff into a $_SESSION without using
$_POST...


<form method="SESSION "> ... ;-)

--
Markus
Jul 17 '05 #4
Markus Ernst <derernst@NO#SP #AMgmx.ch> wrote:
Alvaro G. Vicario wrote:
*** mammothman42 escribi񮶲ot e (17 Sep 2004 20:04:16 -0700):
i've got a basic user register form, action="POST". in my php code
(on the same page, i store the $_POST stuff to a $_SESSION if the
user screws a field up so they don't have to reenter all their info.
But i'm thinking, why should i use $_POST at all if i can just us the
$_SESSION array?


If you can store the $_POST stuff into a $_SESSION without using
$_POST...


<form method="SESSION "> ... ;-)


<irony>
Yeah, and the most common way to hack a page is by using
<form method="SERVER" >
.... Everybody should know that.
</irony>
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #5
ahhh! fully confused! so should i be using SESSION variables or POST?
That is, how is this kinda thing usually done? i'm sure it's a fairly
common problem. should i submit the form as SESSION, or is this a
security flaw? it seems stupid using post, and then having to copy, one
by one, the variables to SESSION. doesn't seem "right".

cheers
dave

Jul 17 '05 #6
<ma**********@h otmail.com> wrote:
ahhh! fully confused! so should i be using SESSION variables or POST?
That is, how is this kinda thing usually done? i'm sure it's a fairly
common problem. should i submit the form as SESSION, or is this a
security flaw? it seems stupid using post, and then having to copy, one
by one, the variables to SESSION. doesn't seem "right".

cheers
dave


To get data from the user, you have 2.5 options:
1) GET: The variables are stored in the query string of the URL (the part
after the '?'). Usable with: Hyperlinks, Forms.
2) POST: The variables are sent in the body of the HTTP request. This is
the _only_ common way to transmit files. (You could use PUT for this, too,
but AFAIK it's not widely supported.) Usable with: Forms.
3) COOKIE: This is the "half option" in the 2.5, since you are likely to
set all the data you recieve from a cookie yourself in a PHP script. You
could use JavaScript to modify a cookie, too, but since this depends on the
client it's no real option. Usable with: Server side mechanisms only. (With
except of the mentioned method.)

The "BIG 7" aren't complete yet. Additionaly to the above, there are:
a) $_ENV: The complete environment which has been passed to PHP. These are
most likely not the same variables you get by typing 'env' on the console,
but specific information about the server and the current request. In most
cases, you won't need this, because all of the important information gets
parsed by PHP and is stuffed into $_SERVER.

b) $_SERVER: Contains a lot of useful data about the server software and
the request itself. If you are searching for information on the current
request, var_dump($_SERV ER) is almost certainly the best beginning.

c) $_FILES: If the raw POST input contained uploaded files, PHP will stuff
them into temporary files and stores all the known data about the file
(original filename, name of the temporary file, filesize and if submitted
the used mime-type [warning: this has not to be the real mime-type!]) in
this superglobal.

d) $_SESSION: All the data in this array is the result of exactly ONE
variable supplied by the visitor (with either of the above methods): It's
session id. According to this ID, PHP searches it's session data for a
match. If there is a file with session data for this session, $_SESSION
will be filled with the data in that file.
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #7
ma**********@ho tmail.com wrote:
ahhh! fully confused! so should i be using SESSION variables or POST?
Sorry for confusing you with a joke. For using forms it is essential to know
the ways data get transmitted from the form to the server. See the very
useful overwiew Simon Stienen gave you in his answer.
That is, how is this kinda thing usually done? i'm sure it's a fairly
common problem.
Not a problem, just common.
should i submit the form as SESSION, or is this a
security flaw?
No it was a joke. You have to use POST or GET.
it seems stupid using post, and then having to copy,
one by one, the variables to SESSION. doesn't seem "right".


If you want a shortcut to get all your postdata into the $_SESSION array:

// This puts the post data at the end of the $_SESSION array:
$_SESSION = $_SESSION + $_POST;

// As an alternative, this will overwrite already existing entries with the
same keys in the session data:
$_SESSION = array_merge($_S ESSION, $_POST);

But usually you will not want this, as you want to process the posted data
rather than store it into the session.

HTH
Markus
Jul 17 '05 #8
Markus Ernst <derernst@NO#SP #AMgmx.ch> wrote:
// This puts the post data at the end of the $_SESSION array:
$_SESSION = $_SESSION + $_POST;

// As an alternative, this will overwrite already existing entries with the
same keys in the session data:
$_SESSION = array_merge($_S ESSION, $_POST);

But usually you will not want this, as you want to process the posted data
rather than store it into the session.

HTH
Markus


This is a *VERY* bad idea. Imaging you use user based rights management...
Everyone could simply send a form with one of the fields:
<input name="admin" value="1"> // flag based user management
<input name="userid" value="1"> // user management by user id
// (auto_increment assumed, therefore 1, not 0)
<input name="user" value="admin"> // user management by user name
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #9
things making a bit of sense now.

simon, what exactly is a *very* bad idea? using merge? or using POST in
general? bit lost on that one sorry.

cheers
dave

Jul 17 '05 #10

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

Similar topics

2
6857
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting everything to PHP5. I have session variables in all of my web application. Until PHP5 I was using session variables like: if ($_SESSION == 'Bar') { $value = 5; } $_SESSION is of course set on some other script. But this now
9
6798
by: Quinonez | last post by:
if i set a $_SESSION=$_POST in every page of a multiple page form how then would i call it on a later page of the same session? and also how is distigushed between pages ? should it be set up differently on each page, ive read of $_SESSION=$_POST but i cant seem to figure out how to call it back at the end of the form
2
935
by: Quinonez | last post by:
i set up a multipage form about a month ago using Sessions everything worked well and i moved forward with working on other pages i just checked the form to make sure it is all working properly and its giving me an error: Warning: Invalid argument supplied for foreach() in /home/mastersc/public_html/testthis.php on line 24 this is the code:
2
1918
by: Tom | last post by:
I put together a code that checks for 2 post variables then stores them in a multi-dim $_SESSION array, something like this: If ( isset($_POST && isset($_POST) ) { $_SESSION = $_POST; $_SESSION = $_POST; } The problem was that $_SESSION was being overwritten with
14
5881
by: Sandman | last post by:
Is there any particular reason I should still use $_POST? Also, I'm reading mixed things about sessions. php.net says you can propagate session IDs either via cookies or session IDs: http://www.php.net/manual/en/ref.session.php#session.idpassing OK cool. However, PHP in a nutshell makes no mention of this. Paul just says hey, use session_start() and you're on your way:
1
2566
by: Jankie | last post by:
I was reading one of the past thread supported by Pbmods.And as always contributing with excellence,he recommended this code for session management foreach($_POST as $key => $val) $_SESSION = $val; This translates all POST variables into the Session one.
2
2654
by: kimi | last post by:
Hi ppl, I am new to PHP. I would need some information on the following: 1. a) I wanted to know from where the data is extracted and stroed in the global assocoative arrays ( specifically what will be the contents of $_Session ?) b) Is there any way by which i can get to know all the keys of the arrays ( specifically what are the Keys of $_Session ?)
8
3369
by: SpiritBreaker | last post by:
I am having problems getting the $_SESSION to set, the $_SESSION will work fine when its first gets the value, however, when I go to another page, the $_SESSION then loses its value. So if any one can take a look at my code and see if there is any problems, that would be good. Thanks Here is my code <?php if (!isset($_SESSION)) session_start();
4
1441
by: jodleren | last post by:
Hi! // get user to edit if( ($_POST=="btn_selusr")||($_POST!="") ) { echo "x:".$_SESSION; $username=stripslashes($_POST); echo "y:".$_SESSION; }
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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
10122
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...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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
7471
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
6722
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();...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.