pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Sessions and serializing (was: Checking data inserted
5+ messages / 2 participants
[nested] [flat]

* Re: Sessions and serializing (was: Checking data inserted
@ 2004-05-19 21:15  Lynna Landstreet <lynna@gallery44.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Lynna Landstreet @ 2004-05-19 21:15 UTC (permalink / raw)
  To: pgsql-php

Hmmm, so my entire idea for how to do this appears to have been unsound.
Well, better to find that out sooner than later! Thanks to everyone who
replied.

But I have a few questions:

on 5/12/04 7:36 PM, Chris at chris@interspire.com wrote:

> You could serialize up the data in sessions and then use that data
> before adding it to the database.
> See http://www.php.net/serialize and http://www.php.net/unserialize and
> http://www.php.net/session

OK, so if I understand this correctly, the serialize function can take
something like a big associative array containing all the data I want to be
able to write into the database and condense it into a single object that
can be passed via a hidden form field or something to that effect, correct?
Or the data can be put into the session array using $_SESSION, and then
passed by using a $session_id in the page URL?

But according to one of the user comments in the manual I have to use
addslashes() and stripslashes() if I want to be able to put the data into
the database after unserializing it - is that right?

Also, what about character encoding? My database and my web pages are utf-8
because of the presence of special characters in some of the artists and
names and image and exhibition titles (it's a Canadian gallery, so there are
a lot of French artists). Will serializing the array containing the data
affect that in any way?

Sorry if I'm being a pest - the whole session thing is new to me and I want
to make sure I understand it correctly.

Thanks,

Lynna

-- 
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Sessions and serializing (was: Checking data inserted
@ 2004-05-20 02:46  Chris <chris@interspire.com>
  parent: Lynna Landstreet <lynna@gallery44.org>
  0 siblings, 2 replies; 5+ messages in thread

From: Chris @ 2004-05-20 02:46 UTC (permalink / raw)
  To: 'Lynna Landstreet' <lynna@gallery44.org>; pgsql-php

Hi Lynna,

on 5/12/04 7:36 PM, Chris at chris@interspire.com wrote:

> You could serialize up the data in sessions and then use that data 
> before adding it to the database. See http://www.php.net/serialize and

> http://www.php.net/unserialize and http://www.php.net/session

> OK, so if I understand this correctly, the serialize function can take
something like a big associative array containing all the data I want to
be able to write into the database and condense it into a single object
that can be passed via a hidden form field or something to that effect,
correct? Or the data can be put into the session array using $_SESSION,
and then passed by using a $session_id in the page URL?


You won't need to use unserialize and serialize per page if you're going
to use sessions - you only need those if you're going to pass the values
in a URL or in a hidden form field.

For sessions, you can simply
$my_array = array('1','2','3','4','5');
$_SESSION['blah'] = $my_array;

sort of thing..

> But according to one of the user comments in the manual I have to use
> addslashes() and stripslashes() if I want to be able to put the data
into the database after unserializing it - is that right?

Yep. So you'll need to do
$value = addslashes(serialize($real_value));

and use $value in your query...

Then when you fetch out

$real_value = unserialize(stripslashes($value));

Done =)

> Also, what about character encoding? My database and my web pages are
utf-8 because of the presence of special characters in some of the
artists and names and image and exhibition titles (it's a Canadian
gallery, so there are a lot of French artists). Will serializing the
array containing the data affect that in any way?

Not as far as I know, it should handle that fine.

> Sorry if I'm being a pest - the whole session thing is new to me and I
want to make sure I understand it correctly.

Ask as many questions as you need to, we've all been at the start before
=)




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Sessions and serializing (was: Checking data inserted
@ 2004-05-20 18:55  Lynna Landstreet <lynna@gallery44.org>
  parent: Chris <chris@interspire.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Lynna Landstreet @ 2004-05-20 18:55 UTC (permalink / raw)
  To: pgsql-php

on 5/19/04 10:46 PM, Chris at chris@interspire.com wrote:

> You won't need to use unserialize and serialize per page if you're going
> to use sessions - you only need those if you're going to pass the values
> in a URL or in a hidden form field.
> 
> For sessions, you can simply
> $my_array = array('1','2','3','4','5');
> $_SESSION['blah'] = $my_array;
> 
> sort of thing..

OK. So if I'm just saving things into the $_SESSION array, I don't need to
use serialize?

I've been reading through a whole bunch of session tutorials on DevShed,
PHPBuilder, etc. (although rather annoyingly nearly all of them are based on
PHP 4.0 and a lot of things seem to have changed with 4.2), and I think I'm
*starting* to get a grip on this, although some aspects are still a bit
confusing.

Most of the tutorials say that you can either pass session ids through the
URL or through cookies, and that using cookies is better for security
reasons. I'm OK with cookies because only a limited number of people will be
using the admin system I'm setting up and I can tell them they have to have
cookies enabled. It's not a part of the site that will be accessible to the
general public. And from the sounds of it the cookie is set automatically
without my having to do it with setcookie - right?

But the thing that's confusing me now is that apparently in 4.2,
--enable-trans-id is on by default, and that makes it automatically put the
session ID in the URLs of relative links, unless I've misunderstood what it
does? If passing the SID via URL is supposed to be bad from a security
standpoint, is there some way I can make it not do this? Bearing in mind
that I'm on a shared host so I can't mess with their overall PHP
configuration? Or am I worrying about this too much?



>> But according to one of the user comments in the manual I have to use
>> addslashes() and stripslashes() if I want to be able to put the data
> into the database after unserializing it - is that right?
> 
> Yep. So you'll need to do
> $value = addslashes(serialize($real_value));
> 
> and use $value in your query...
> 
> Then when you fetch out
> 
> $real_value = unserialize(stripslashes($value));
> 
> Done =)

And that's only if I'm putting the session itself into a form field or
database, right? 

If I extract the values from the $_SESSION array at the end of the update
process and insert them into the database then, having just used cookies to
store it in the meantime, then it doesn't need this? Or does it?


> Ask as many questions as you need to, we've all been at the start before
> =)

Thanks. Hopefully sooner or later I'll actually be at the point where I can
start answering other people's questions instead. :-)


Lynna

-- 
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Sessions and serializing (was: Checking data inserted
@ 2004-05-20 18:57  Lynna Landstreet <lynna@gallery44.org>
  parent: Chris <chris@interspire.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Lynna Landstreet @ 2004-05-20 18:57 UTC (permalink / raw)
  To: pgsql-php

Oh, and one more question I forgot. If session_start and/or adding variables
to $_SESSION does result in setting a cookie automatically, does that mean
it has to be done at the beginning of the script, before any output, like
with setcookie?


Lynna

-- 
Resource Centre Database Coordinator
Gallery 44
www.gallery44.org




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Sessions and serializing (was: Checking data inserted
@ 2004-05-21 06:34  Chris <chris@interspire.com>
  parent: Lynna Landstreet <lynna@gallery44.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Chris @ 2004-05-21 06:34 UTC (permalink / raw)
  To: 'Lynna Landstreet' <lynna@gallery44.org>; pgsql-php

Hey Lynna,

> Oh, and one more question I forgot. If session_start and/or adding
variables to $_SESSION does result in setting a cookie automatically,
does that mean it has to be done at the beginning of the script, before
any output, like with setcookie?

Yes - you need to do a session_start() before any output gets sent. See
http://www.php.net/session_start for a bit more info about it..

>> You won't need to use unserialize and serialize per page if you're 
>> going to use sessions - you only need those if you're going to pass 
>> the values in a URL or in a hidden form field.
>> 
>> For sessions, you can simply
>> $my_array = array('1','2','3','4','5');
>> $_SESSION['blah'] = $my_array;
>> 
>> sort of thing..

>OK. So if I'm just saving things into the $_SESSION array, I don't need
to use serialize?

Correct.

>Most of the tutorials say that you can either pass session ids through
the URL or through cookies, and that using cookies is better for
security reasons. I'm OK with cookies because only a limited number of
people will be using the admin system I'm setting up and I can tell them
they have to have cookies enabled. It's not a part of the site that will
be accessible to the general public. And from the sounds of it the
cookie is set automatically without my having to do it with setcookie -
right?

Yep. Everything gets stored on the server in the session_save_path
directory (you can set this yourself in your scripts - see
http://www.php.net/session_save_path :)


>But the thing that's confusing me now is that apparently in 4.2,
--enable-trans-id is on by default, and that makes it automatically put
the session ID in the URLs of relative links, unless I've misunderstood
what it does? If passing the SID via URL is supposed to be bad from a
security standpoint, is there some way I can make it not do this?
Bearing in mind that I'm on a shared host so I can't mess with their
overall PHP configuration? Or am I worrying about this too much?

If it's a worry you can turn it off - http://www.php.net/ini_set - look
for session.use_trans_sid . Since it's a PHP_INI_SYSTEM|PHP_PER_DIR you
can change it in a .htaccess file ...


>>> But according to one of the user comments in the manual I have to
use
>>> addslashes() and stripslashes() if I want to be able to put the data
>> into the database after unserializing it - is that right?

>> Yep. So you'll need to do
>> $value = addslashes(serialize($real_value));
>> and use $value in your query...
>> Then when you fetch out 
>> $real_value = unserialize(stripslashes($value));

>And that's only if I'm putting the session itself into a form field or
database, right? 

Yep.

>If I extract the values from the $_SESSION array at the end of the
update process and insert them into the database then, having just used
cookies to store it in the meantime, then it doesn't need this? Or does
it?

It depends :)

eg dob could be stored as an array - 
$dob = array('dd' => '01', 'mm' => '01', 'yy' => '1970');

then you'll need to serialize it before saving it..

If you want the values saved separately, then no you won't (eg q1 = 'y',
q2 = 'blah' etc etc).

HTH.

Chris.




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2004-05-21 06:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-19 21:15 Re: Sessions and serializing (was: Checking data inserted Lynna Landstreet <lynna@gallery44.org>
2004-05-20 02:46 ` Chris <chris@interspire.com>
2004-05-20 18:55   ` Lynna Landstreet <lynna@gallery44.org>
2004-05-21 06:34     ` Chris <chris@interspire.com>
2004-05-20 18:57   ` Lynna Landstreet <lynna@gallery44.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox