php-general Digest 24 Apr 2012 17:29:44 -0000 Issue 7787

Topics (messages 317655 through 317667):

session lost problem
        317655 by: bug zhu
        317656 by: Stuart Dallas
        317657 by: Stuart Dallas
        317658 by: Adam Richardson
        317659 by: bug zhu
        317660 by: marco.behnke.biz
        317661 by: bug zhu

Re: No error reporting on
        317662 by: Jim Giner

Hmm.. this is strange..
        317663 by: Karl-Arne Gjersøyen
        317664 by: Serge Fonville
        317665 by: Karl-Arne Gjersøyen
        317666 by: Karl-Arne Gjersøyen

NULL Problem
        317667 by: David Stoltz

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
hi all:

there are tow php files a.php and b.php,

content of a.php as follows:
<?php
session_start();
if (!isset($_GET['flag']))
{
header('Location: b.php');
}
else
{
var_dump($_SESSION);
}

content of  b.php as follows:
<?php
session_start();
session_commit();
$_SESSION['test'] = 'test';
session_commit();
header('Location: a.php?flag=1');

when i visit a.php, the dumped $_SESSION array is empty
but if i commented the first session_commit() in b.php and then visit
a.php, i cound see the $_SESSION array,which is not empty
i wish i have descibed  clear about my problem and someone could give me a
feedback~

-- 

thanks,
bugzhu

--- End Message ---
--- Begin Message ---
On 24 Apr 2012, at 05:58, bug zhu wrote:

> there are tow php files a.php and b.php,
> 
> content of a.php as follows:
> <?php
> session_start();
> if (!isset($_GET['flag']))
> {
> header('Location: b.php');
> }
> else
> {
> var_dump($_SESSION);
> }
> 
> content of  b.php as follows:
> <?php
> session_start();
> session_commit();
> $_SESSION['test'] = 'test';
> session_commit();
> header('Location: a.php?flag=1');
> 
> when i visit a.php, the dumped $_SESSION array is empty
> but if i commented the first session_commit() in b.php and then visit
> a.php, i cound see the $_SESSION array,which is not empty
> i wish i have descibed  clear about my problem and someone could give me a
> feedback~


I'm really not clear on what you're trying to do here, but the behaviour you're 
describing is as designed. When you call session_commit() you are saving and 
closing the session, so nothing done to $_SESSION after that point will be 
saved, even if you call session_commit() again.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
Please don't top-post, and please include the list when replying.

On 24 Apr 2012, at 06:35, bug zhu wrote:
> 2012/4/24 Stuart Dallas <stu...@3ft9.com>
>> On 24 Apr 2012, at 05:58, bug zhu wrote:
>> 
>> > there are tow php files a.php and b.php,
>> >
>> > content of a.php as follows:
>> > <?php
>> > session_start();
>> > if (!isset($_GET['flag']))
>> > {
>> > header('Location: b.php');
>> > }
>> > else
>> > {
>> > var_dump($_SESSION);
>> > }
>> >
>> > content of  b.php as follows:
>> > <?php
>> > session_start();
>> > session_commit();
>> > $_SESSION['test'] = 'test';
>> > session_commit();
>> > header('Location: a.php?flag=1');
>> >
>> > when i visit a.php, the dumped $_SESSION array is empty
>> > but if i commented the first session_commit() in b.php and then visit
>> > a.php, i cound see the $_SESSION array,which is not empty
>> > i wish i have descibed  clear about my problem and someone could give me a
>> > feedback~
>> 
>> 
>> I'm really not clear on what you're trying to do here, but the behaviour 
>> you're describing is as designed. When you call session_commit() you are 
>> saving and closing the session, so nothing done to $_SESSION after that 
>> point will be saved, even if you call session_commit() again.
> 
> but in a single file without redirect, code as follows
> <?php
> session_start();
> session_commit();
> $_SESSION['test'] = 'test';
> session_commit();
> var_dump($_SESSION);
> 
> could dump the $_SESSION array.

Yes, because $_SESSION is not special in any way other than that it's used by 
the session system; it's no more than a superglobal array. So within one 
request that array contains whatever you put into it, but that doesn't mean it 
is stored in whatever session storage mechanism you're using (files by 
default). When you redirect to another URL that's a whole new request so the 
contents of $_SESSION have to be loaded from the session storage.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On Tue, Apr 24, 2012 at 12:58 AM, bug zhu <bugw...@gmail.com> wrote:
> there are tow php files a.php and b.php,
>
> content of a.php as follows:
> <?php
> session_start();
> if (!isset($_GET['flag']))
> {
> header('Location: b.php');
> }
> else
> {
> var_dump($_SESSION);
> }
>
> content of  b.php as follows:
> <?php
> session_start();
> session_commit();
> $_SESSION['test'] = 'test';
> session_commit();
> header('Location: a.php?flag=1');
>
> when i visit a.php, the dumped $_SESSION array is empty
> but if i commented the first session_commit() in b.php and then visit
> a.php, i cound see the $_SESSION array,which is not empty
> i wish i have descibed  clear about my problem and someone could give me a
> feedback~

Hi,

So, you:
1) Visit page a.php (I'm assuming without the flag)
2) Are forwarded to page b.php, which you're expecting to store a
session variable 'test'.
3) Then forwarded back to page a.php.

You're likely expecting that you're return visit to page a.php should
reveal the 'test' variable.

The issue is that you're calling session_commit(), which is actually
an alias for session_write_close(). This function actually stops the
current session. So, when you hit the line $_SESSION['test'] = 'test',
your session has already terminated.

Try removing the session_commit() calls (or at least permanently
remove the first call.) You only want to call session_commit() when
you're done accessing/updating $_SESSION variables.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
thank you for your explanation,
when i write to $_SESSION after session_commit(),$_SESSION is just a
regular array

2012/4/24 Stuart Dallas <stu...@3ft9.com>

> Please don't top-post, and please include the list when replying.
>
> On 24 Apr 2012, at 06:35, bug zhu wrote:
> > 2012/4/24 Stuart Dallas <stu...@3ft9.com>
> >> On 24 Apr 2012, at 05:58, bug zhu wrote:
> >>
> >> > there are tow php files a.php and b.php,
> >> >
> >> > content of a.php as follows:
> >> > <?php
> >> > session_start();
> >> > if (!isset($_GET['flag']))
> >> > {
> >> > header('Location: b.php');
> >> > }
> >> > else
> >> > {
> >> > var_dump($_SESSION);
> >> > }
> >> >
> >> > content of  b.php as follows:
> >> > <?php
> >> > session_start();
> >> > session_commit();
> >> > $_SESSION['test'] = 'test';
> >> > session_commit();
> >> > header('Location: a.php?flag=1');
> >> >
> >> > when i visit a.php, the dumped $_SESSION array is empty
> >> > but if i commented the first session_commit() in b.php and then visit
> >> > a.php, i cound see the $_SESSION array,which is not empty
> >> > i wish i have descibed  clear about my problem and someone could give
> me a
> >> > feedback~
> >>
> >>
> >> I'm really not clear on what you're trying to do here, but the
> behaviour you're describing is as designed. When you call session_commit()
> you are saving and closing the session, so nothing done to $_SESSION after
> that point will be saved, even if you call session_commit() again.
> >
> > but in a single file without redirect, code as follows
> > <?php
> > session_start();
> > session_commit();
> > $_SESSION['test'] = 'test';
> > session_commit();
> > var_dump($_SESSION);
> >
> > could dump the $_SESSION array.
>
> Yes, because $_SESSION is not special in any way other than that it's used
> by the session system; it's no more than a superglobal array. So within one
> request that array contains whatever you put into it, but that doesn't mean
> it is stored in whatever session storage mechanism you're using (files by
> default). When you redirect to another URL that's a whole new request so
> the contents of $_SESSION have to be loaded from the session storage.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>



-- 

thanks,
bugzhu

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

bug zhu <bugw...@gmail.com> hat am 24. April 2012 um 08:28 geschrieben:

> thank you for your explanation,
> when i write to $_SESSION after session_commit(),$_SESSION is just a
> regular array

Yes. Actually session_commit does not "terminate" the session as mentioned
earlier but is closes it for writing. You cann still read session values.

The benefit of using session_commit is that the server saved associated
session file is no longer locked, so that parallel requests can both access
the values.

The approach ist as follows:
Call session_commit() as early in you code (after session_open) as possible
to avoid locking. So first do all the writing to the $_SESSION array, then
do write close (or commit). After that you can still read all session
relevant information.

If you want to write afterwards to your $_SESSIOn array you simply have to
call session_start to re-open the write context. Afterwards you can commit
it again to remove the lock.

But be careful! session_start and session_commit perform write operations
on your harddisk or whatever storage you use. Many calls to start and
commit will result in losing performance.

Regards,
Marco

--- End Message ---
--- Begin Message ---
2012/4/24 ma...@behnke.biz <ma...@behnke.biz>

>
>
> bug zhu <bugw...@gmail.com> hat am 24. April 2012 um 08:28 geschrieben:
>
> > thank you for your explanation,
> > when i write to $_SESSION after session_commit(),$_SESSION is just a
> > regular array
>
> Yes. Actually session_commit does not "terminate" the session as mentioned
> earlier but is closes it for writing. You cann still read session values.
>
> The benefit of using session_commit is that the server saved associated
> session file is no longer locked, so that parallel requests can both access
> the values.
>
> The approach ist as follows:
> Call session_commit() as early in you code (after session_open) as possible
> to avoid locking. So first do all the writing to the $_SESSION array, then
> do write close (or commit). After that you can still read all session
> relevant information.
>
> If you want to write afterwards to your $_SESSIOn array you simply have to
> call session_start to re-open the write context. Afterwards you can commit
> it again to remove the lock.
>
> But be careful! session_start and session_commit perform write operations
> on your harddisk or whatever storage you use. Many calls to start and
> commit will result in losing performance.
>
> Regards,
> Marco
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
got it,
very appreciate you explanation:-)

-- 

thanks,
bugzhu

--- End Message ---
--- Begin Message ---
Sounds like a very good reason to me?  It's a development tool.  Add it now, 
remove it later.
"Dotan Cohen" <dotanco...@gmail.com> wrote in message 
news:cakdxfkn+6mn9chuqdwevx5ap0km-rkls0q+carbf5hktvuo...@mail.gmail.com...
On Mon, Apr 23, 2012 at 16:53, Jim Lucas <li...@cmsws.com> wrote:
>> Possibly, thanks. I actually don't have access to that!
>>
>
> That line should be placed in your script. not the php.ini file
>

Yes, I'm working on a functions file that is include()ed by the main
script. I'm not supposed to touch the main script without a very good
reason.


-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com 



--- End Message ---
--- Begin Message ---
Hello.
I have a upload form in a html file and a corresponding PHP file that
shall take care of the information.
But I am doing something newbie error here..

What am I doing wrong? (The text is norwegian, but you still see and
understand the PHP code)

bildegalleri.html
---------------------
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="utf-8">
<title>Opplasting til Fotogalleri</title>
<link rel="stylesheet" href="standard.css" media="screen">
</head>
<body>
<h1>Opplasting til Fotogalleri</h1>
<form action="bildegalleri.php" method="post" enctype="multipart/form-data">
        <fieldset>
                <legend>Velg bilde for opplasting</legend>
                <label for="filbane">Filbane</label><br>
                <input type="file" id="filbane" name="filbane">
                <input type="submit" name="last_opp_fil" value="Last opp 
bildet">
        </fieldset>
</form>
</body>
</html>

bildegalleri.php
---------------------
<?php
if(!isset($_POST['last_opp_fil'])){
        header('Location: bildegalleri.html');
}
elseif(empty($_FILES['filbane'])){
        header('Location: bildegalleri.html');
} else {
?>
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="utf-8">
<title>Bildegalleri</title>
</head>
<body>
<h1>Bildegalleri</h1>
<?php
echo "OK";
}
?>
</body>
</html>

When I run this script, I always get "Ok". Even when the input file
field is empty.. Can someone tell me what I am doing wroing in this?

Thanks for you time and effort to help me out.

Karl

--- End Message ---
--- Begin Message ---
Hi,

Instead of just checking if the variable is not set, additionally
check if it is empty

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

Convince Google!!
They need to add GAL support on Android (star to agree)
http://code.google.com/p/android/issues/detail?id=4602


2012/4/24 Karl-Arne Gjersøyen <karlar...@gmail.com>:
> Hello.
> I have a upload form in a html file and a corresponding PHP file that
> shall take care of the information.
> But I am doing something newbie error here..
>
> What am I doing wrong? (The text is norwegian, but you still see and
> understand the PHP code)
>
> bildegalleri.html
> ---------------------
> <!DOCTYPE html>
> <html lang="no">
> <head>
> <meta charset="utf-8">
> <title>Opplasting til Fotogalleri</title>
> <link rel="stylesheet" href="standard.css" media="screen">
> </head>
> <body>
> <h1>Opplasting til Fotogalleri</h1>
> <form action="bildegalleri.php" method="post" enctype="multipart/form-data">
>        <fieldset>
>                <legend>Velg bilde for opplasting</legend>
>                <label for="filbane">Filbane</label><br>
>                <input type="file" id="filbane" name="filbane">
>                <input type="submit" name="last_opp_fil" value="Last opp 
> bildet">
>        </fieldset>
> </form>
> </body>
> </html>
>
> bildegalleri.php
> ---------------------
> <?php
> if(!isset($_POST['last_opp_fil'])){
>        header('Location: bildegalleri.html');
> }
> elseif(empty($_FILES['filbane'])){
>        header('Location: bildegalleri.html');
> } else {
> ?>
> <!DOCTYPE html>
> <html lang="no">
> <head>
> <meta charset="utf-8">
> <title>Bildegalleri</title>
> </head>
> <body>
> <h1>Bildegalleri</h1>
> <?php
> echo "OK";
> }
> ?>
> </body>
> </html>
>
> When I run this script, I always get "Ok". Even when the input file
> field is empty.. Can someone tell me what I am doing wroing in this?
>
> Thanks for you time and effort to help me out.
>
> Karl
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Here I try to check if the input file is empty or not. But still it
did not work. I receive OK even when the input file field is empty..

<?php
if(!isset($_POST['last_opp_fil'])){
        header('Location: bildegalleri.html');
} else {
        $bildefil = $_FILES['filbane'];
        if(empty($bildefil)){
                header('Location: bildegalleri.html');
        } else {
?>
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="utf-8">
<title>Bildegalleri</title>
</head>
<body>
<h1>Bildegalleri</h1>
<?php
        echo "OK";
        }
}
?>
</body>
</html>

Den 16:48 24. april 2012 skrev Serge Fonville
<serge.fonvi...@gmail.com> følgende:
> Hi,
>
> Instead of just checking if the variable is not set, additionally
> check if it is empty
>
> Kind regards/met vriendelijke groet,
>
> Serge Fonville
>
> http://www.sergefonville.nl
>
> Convince Google!!
> They need to add GAL support on Android (star to agree)
> http://code.google.com/p/android/issues/detail?id=4602
>
>
> 2012/4/24 Karl-Arne Gjersøyen <karlar...@gmail.com>:
>> Hello.
>> I have a upload form in a html file and a corresponding PHP file that
>> shall take care of the information.
>> But I am doing something newbie error here..
>>
>> What am I doing wrong? (The text is norwegian, but you still see and
>> understand the PHP code)
>>
>> bildegalleri.html
>> ---------------------
>> <!DOCTYPE html>
>> <html lang="no">
>> <head>
>> <meta charset="utf-8">
>> <title>Opplasting til Fotogalleri</title>
>> <link rel="stylesheet" href="standard.css" media="screen">
>> </head>
>> <body>
>> <h1>Opplasting til Fotogalleri</h1>
>> <form action="bildegalleri.php" method="post" enctype="multipart/form-data">
>>        <fieldset>
>>                <legend>Velg bilde for opplasting</legend>
>>                <label for="filbane">Filbane</label><br>
>>                <input type="file" id="filbane" name="filbane">
>>                <input type="submit" name="last_opp_fil" value="Last opp 
>> bildet">
>>        </fieldset>
>> </form>
>> </body>
>> </html>
>>
>> bildegalleri.php
>> ---------------------
>> <?php
>> if(!isset($_POST['last_opp_fil'])){
>>        header('Location: bildegalleri.html');
>> }
>> elseif(empty($_FILES['filbane'])){
>>        header('Location: bildegalleri.html');
>> } else {
>> ?>
>> <!DOCTYPE html>
>> <html lang="no">
>> <head>
>> <meta charset="utf-8">
>> <title>Bildegalleri</title>
>> </head>
>> <body>
>> <h1>Bildegalleri</h1>
>> <?php
>> echo "OK";
>> }
>> ?>
>> </body>
>> </html>
>>
>> When I run this script, I always get "Ok". Even when the input file
>> field is empty.. Can someone tell me what I am doing wroing in this?
>>
>> Thanks for you time and effort to help me out.
>>
>> Karl
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

--- End Message ---
--- Begin Message ---
Thank you very much Tolga!



if(empty($_FILES['filbane']['name']))


24.04.2012 17:54 tarihinde, Karl-Arne Gjersøyen yazdı:

> Here I try to check if the input file is empty or not. But still it
> did not work. I receive OK even when the input file field is empty..
>
> <?php
> if(!isset($_POST['last_opp_fil'])){
>        header('Location: bildegalleri.html');
> } else {
>        $bildefil = $_FILES['filbane'];
>        if(empty($bildefil)){
>                header('Location: bildegalleri.html');
>        } else {
> ?>
> <!DOCTYPE html>
> <html lang="no">
> <head>
> <meta charset="utf-8">
> <title>Bildegalleri</title>
> </head>
> <body>
> <h1>Bildegalleri</h1>
> <?php
>        echo "OK";
>        }
> }
> ?>
> </body>
> </html>
>
> Den 16:48 24. april 2012 skrev Serge Fonville
> <serge.fonvi...@gmail.com>  følgende:
>>
>> Hi,
>>
>> Instead of just checking if the variable is not set, additionally
>> check if it is empty
>>
>> Kind regards/met vriendelijke groet,
>>
>> Serge Fonville
>>
>> http://www.sergefonville.nl
>>
>> Convince Google!!
>> They need to add GAL support on Android (star to agree)
>> http://code.google.com/p/android/issues/detail?id=4602
>>
>>
>> 2012/4/24 Karl-Arne Gjersøyen<karlar...@gmail.com>:
>>>
>>> Hello.
>>> I have a upload form in a html file and a corresponding PHP file that
>>> shall take care of the information.
>>> But I am doing something newbie error here..
>>>
>>> What am I doing wrong? (The text is norwegian, but you still see and
>>> understand the PHP code)
>>>
>>> bildegalleri.html
>>> ---------------------
>>> <!DOCTYPE html>
>>> <html lang="no">
>>> <head>
>>> <meta charset="utf-8">
>>> <title>Opplasting til Fotogalleri</title>
>>> <link rel="stylesheet" href="standard.css" media="screen">
>>> </head>
>>> <body>
>>> <h1>Opplasting til Fotogalleri</h1>
>>> <form action="bildegalleri.php" method="post" enctype="multipart/form-data">
>>>        <fieldset>
>>>                <legend>Velg bilde for opplasting</legend>
>>>                <label for="filbane">Filbane</label><br>
>>>                <input type="file" id="filbane" name="filbane">
>>>                <input type="submit" name="last_opp_fil" value="Last opp 
>>> bildet">
>>>        </fieldset>
>>> </form>
>>> </body>
>>> </html>
>>>
>>> bildegalleri.php
>>> ---------------------
>>> <?php
>>> if(!isset($_POST['last_opp_fil'])){
>>>        header('Location: bildegalleri.html');
>>> }
>>> elseif(empty($_FILES['filbane'])){
>>>        header('Location: bildegalleri.html');
>>> } else {
>>> ?>
>>> <!DOCTYPE html>
>>> <html lang="no">
>>> <head>
>>> <meta charset="utf-8">
>>> <title>Bildegalleri</title>
>>> </head>
>>> <body>
>>> <h1>Bildegalleri</h1>
>>> <?php
>>> echo "OK";
>>> }
>>> ?>
>>> </body>
>>> </html>
>>>
>>> When I run this script, I always get "Ok". Even when the input file
>>> field is empty.. Can someone tell me what I am doing wroing in this?
>>>
>>> Thanks for you time and effort to help me out.
>>>
>>> Karl
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>



-- 
Hjemmeside: http://www.karl-arne.name/

--- End Message ---
--- Begin Message ---
Here's my code (using MSSQL):

$conn = new COM ("ADODB.Connection")or die("Cannot start ADO");
$conn->open($connStr); 
$query = "SELECT * FROM TABLE WHERE id = ".$id;
$rs = $conn->execute($query);

This code works fine, and I retrieve the values like this:

$tmp1 = $rs->fields("column1");
$tmp2 = $rs->fields("column2");
Etc...


Here's the problem - I'm trying to get a date column that I know is
NULL, but I can't seem to get my code right:

$tmp = $rs->fields("followup_on");
if(is_null($tmp)){
        $followup = "";
}else{
        $followup = $rs->fields("followup_on");
}

//this results in: Catchable fatal error: Object of class variant could
not be converted to string
//When I try to ECHO the $followup results (and I know the database
value is NULL)


So confused - any advice?

--- End Message ---

Reply via email to