php-general Digest 3 Mar 2008 03:09:46 -0000 Issue 5326

Topics (messages 270830 through 270840):

Re: Multiple sessions open at same time, is it possible?
        270830 by: Stut
        270831 by: Richard
        270833 by: Stut
        270834 by: Richard
        270835 by: Stut

Re: Anyone jump from Studio 5.5.x -> Zend Eclipse?
        270832 by: Ray Hauge

Re: Multiple sessions open at same time, is it possible? [ Solved, thankyou !]
        270836 by: Richard
        270837 by: Stut
        270838 by: Richard

Re: Making sure an include file works
        270839 by: Chris

Re: Importing and exporting from MySQL, escape slash problem
        270840 by: Richard Lynch

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On 2 Mar 2008, at 14:49, Richard wrote:
I'm quite new to sessions, an am trying to program a script which needs two sessions ...

I have a members area which uses 1 session, and when you click on disconnect it closes the session and the user returns to the login page.

I also am programming a shopping cart so members can choose what they would like to download that also uses a session.

All worked fine untill I realised that because they both use the same session, when I disconnect from the members area it also obviously deletes all elements from the download cart.

I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open.

Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ...

Just use one session. Put the data for each session into a separate array...

$_SESSION['members'] = array('lots', 'of', 'data');
$_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap');

To "disconnect" the user from one or other simply unset that variable...

unset($_SESSION['members']);
unset($_SESSION['cart']);

KISS.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Stut a écrit :
On 2 Mar 2008, at 14:49, Richard wrote:
I'm quite new to sessions, an am trying to program a script which needs two sessions ...

I have a members area which uses 1 session, and when you click on disconnect it closes the session and the user returns to the login page.

I also am programming a shopping cart so members can choose what they would like to download that also uses a session.

All worked fine untill I realised that because they both use the same session, when I disconnect from the members area it also obviously deletes all elements from the download cart.

I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open.

Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ...

Just use one session. Put the data for each session into a separate array...

$_SESSION['members'] = array('lots', 'of', 'data');
$_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap');

To "disconnect" the user from one or other simply unset that variable...

unset($_SESSION['members']);
unset($_SESSION['cart']);

KISS.

-Stut

Thankyou, instead of unsetting the whole session, I just unset de password, so the user has to login again and now it does not reset the cart anymore.

However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
    $_SESSION['password'] = array();
else { $_SESSION['last_time'] = time()
    }
...

Or is there a better way to do this?

Thanks again :)

--- End Message ---
--- Begin Message ---
On 2 Mar 2008, at 15:28, Richard wrote:
Stut a écrit :
On 2 Mar 2008, at 14:49, Richard wrote:
I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open.

Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ...

Just use one session. Put the data for each session into a separate array...

$_SESSION['members'] = array('lots', 'of', 'data');
$_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap');

To "disconnect" the user from one or other simply unset that variable...

unset($_SESSION['members']);
unset($_SESSION['cart']);

KISS.
However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
   $_SESSION['password'] = array();
else {    $_SESSION['last_time'] = time()
   }
...

Or is there a better way to do this?

There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Stut a écrit :
On 2 Mar 2008, at 15:28, Richard wrote:
Stut a écrit :
On 2 Mar 2008, at 14:49, Richard wrote:
I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open.

Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ...

Just use one session. Put the data for each session into a separate array...

$_SESSION['members'] = array('lots', 'of', 'data');
$_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap');

To "disconnect" the user from one or other simply unset that variable...

unset($_SESSION['members']);
unset($_SESSION['cart']);

KISS.
However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
   $_SESSION['password'] = array();
else {    $_SESSION['last_time'] = time()
   }
...

Or is there a better way to do this?

There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat.

-Stut

Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time...
--- End Message ---
--- Begin Message ---
On 2 Mar 2008, at 15:59, Richard wrote:
Stut a écrit :
On 2 Mar 2008, at 15:28, Richard wrote:
However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
  $_SESSION['password'] = array();
else {    $_SESSION['last_time'] = time()
  }
...

Or is there a better way to do this?

There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat.

Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time...


It's really not rocket science...

if ($_SESSION['expiry'] < time())
{
    $_SESSION['password'] = array();
}
else
{
    // Password expires in 30 minutes
    $_SESSION['expiry'] = time() + 1800;
}

Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Steve Finkelstein wrote:
Hi all,

I've tried googling around to find some blogs with decent information
on whether Zend Eclipse is mature enough to make the jump over from
5.5.x just yet.

Admittedly, I've dropped Zend Studio as of late and been writing all
of my code in TextMate -- but at the end of the day when a project is
complex enough, Zend Studio is much more powerful than TextMate with
all of its features and remote debugging capabilities.

Anyhow, I'm curious if it's worth it to check out Zend Eclipse yet.
We're a team of about 5-6 developers and I've been getting asked by a
few colleagues if I've tried it out yet since I'm usually the one to
try out the newer technologies.

I'd love to hear some feedback.

Thanks!

/sf


I've recently switched. On my machine (which hasn't been updated for a long time...) Eclipse runs a lot slower. I only have 1 GB of RAM. Zend Studio has been running faster for me after I turned off the SVN integration. I just use the CLI for SVN anyway.

Sometimes in Eclipse it'll slow down so much that I have to slow down my typing. Mostly that's in CSS files. I don't know if it's Eclipse in general, but Shift+Tab rarely works, and it drives me nuts. I've tried to mess with the key bindings to no avail. Debugging is a lot slower in Eclipse. Some of the default key bindings in Zend Studio are different in Zend Eclipse as well, but that was somewhat expected and hasn't bothered me too much.

I've been using the official Zend Eclipse now since the day it came out. Next week I'm going to switch back to regular Zend Studio. It was nicer on the RAM and for the most part "Just Worked"(TM).

That's my experience.  I'd be interested to hear other people's experiences.

--
Ray Hauge
www.primateapplications.com

--- End Message ---
--- Begin Message ---
Stut a écrit :
On 2 Mar 2008, at 15:59, Richard wrote:
Stut a écrit :
On 2 Mar 2008, at 15:28, Richard wrote:
However, is there a way to limit the session stay alive time for just one variable ?

If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads :

if ( time() - $_SESSION[last_time] > 1800) {
  $_SESSION['password'] = array();
else {    $_SESSION['last_time'] = time()
  }
...

Or is there a better way to do this?

There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat.

Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time...


It's really not rocket science...

if ($_SESSION['expiry'] < time())
{
    $_SESSION['password'] = array();
}
else
{
    // Password expires in 30 minutes
    $_SESSION['expiry'] = time() + 1800;
}

Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it.

-Stut

Oh right ! :)
Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] !
--- End Message ---
--- Begin Message ---
On 2 Mar 2008, at 16:32, Richard wrote:
Stut a écrit :
Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it.

Oh right ! :)
Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] !

Eh? What's in $_SESSION['cart']['item_number']? You might want to consider one of the following depending on what's in that array element...

unset($_SESSION['cart']['item_number']);

unset($_SESSION['cart'][array_search($itemtoremove, $_SESSION['cart'])]);

unset($_SESSION['cart']['item_number'][array_search($itemtoremove, $_SESSION['cart']['item_number'])]);

At the very least it would be better to use null rather than array(), but actually removing the item from the array would be my recommendation.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Stut a écrit :
On 2 Mar 2008, at 16:32, Richard wrote:
Stut a écrit :
Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it.

Oh right ! :)
Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] !

Eh? What's in $_SESSION['cart']['item_number']? You might want to consider one of the following depending on what's in that array element...

unset($_SESSION['cart']['item_number']);

unset($_SESSION['cart'][array_search($itemtoremove, $_SESSION['cart'])]);

unset($_SESSION['cart']['item_number'][array_search($itemtoremove, $_SESSION['cart']['item_number'])]);

At the very least it would be better to use null rather than array(), but actually removing the item from the array would be my recommendation.

-Stut

Sorry I went back to where I read that I should use =array(); and I miss read an instruction which was : http://fr3.php.net/unset

|
|Quote from http://fr.php.net/session_unset

"Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal."

So basically don't do:
unset($_SESSION)

Instead do:
$_SESSION = array();|


So no need for setting my session variables to array()...
|

--- End Message ---
--- Begin Message ---

have you considered installing a local copy of php (and suitable webserver)
so you can test it there?

I'd also suggest using a revision control system (subversion or git) and have pre-commit hooks to check the syntax.

It's a bit of work to set up but once it's done you'll notice a difference - just knowing how often you're changing things can be surprising.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
It's possible that there is an .htaccess file in phpMyAdmin that has
Magic Quotes on that is messing you up...

Other than that, it's specific to phpMyAdmin, so maybe ask those guys
what they did...

On Sat, March 1, 2008 7:38 pm, Dave M G wrote:
> PHP List, MySQL List
>
> In my PHP environment, I have "Magic Quotes" turned off, and I use the
> mysql_real_escape_string() function clean strings of SQL syntax before
> inserting them into my database.
>
> So the data stored in my database does not have escape characters in
> it.
> Particularly, double and single quotes don't have slashes in front of
> them.
>
> This seems to work fine so long as I'm reading data into and out of
> the
> database from within my scripts.
>
> However, when I backup and import databases - I use the phpMyAdmin
> interface - they have escape slashes in front of every double and
> single
> quote characters. I'm not sure if it's on the export or import where
> they get added in.
>
> I've looked through the phpMyAdmin online documentation, and I can't
> see
> any option to control the presence of escape slashes. It seems to me
> that if it adds them in when exporting, it should take them out when
> importing. Or vice versa, but in either case be consistent.
>
> I just want my database to be exactly as it is before any export or
> import options.
>
> I'm a little muddled as to where I'm making the mistake. Can anyone
> advice on the best practice for preserving my database as is when
> backing up and restoring?
>
> Thanks for any advice.
>
> --
> Dave M G
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


--- End Message ---

Reply via email to