OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 21 Oct 2004 21:28:52 -0000 Issue 3066

php-general-digest-helplists.php.net
Date: Thu Oct 21 2004 - 16:28:52 CDT


php-general Digest 21 Oct 2004 21:28:52 -0000 Issue 3066

Topics (messages 199961 through 200035):

Re: Validation problem with array.
        199961 by: Andre Dubuc
        199964 by: Stuart Felenstein
        199965 by: Graham Cossey
        199966 by: Stuart Felenstein
        199968 by: Graham Cossey
        199969 by: Stuart Felenstein
        199971 by: Graham Cossey
        199992 by: Brent Baisley

php sessions question
        199962 by: Reinhart Viane
        199988 by: raditha dissanayake
        200034 by: Pete

Sessions question
        199963 by: Reinhart Viane
        199967 by: Mike Smith
        199970 by: Reinhart Viane
        199979 by: Greg Donald
        199986 by: Reinhart Viane
        199987 by: Greg Donald
        199989 by: Mike Smith
        199990 by: raditha dissanayake
        199995 by: Greg Donald
        200027 by: Curt Zirzow

URL variables, and the $_GET[xxx] function...
        199972 by: Tristan.Pretty.risk.sungard.com
        199976 by: Greg Donald
        199978 by: R'twick Niceorgaw

Strange Array Error
        199973 by: Shaun
        199974 by: Greg Donald
        199977 by: Chris Dowell
        199980 by: Graham Cossey
        199981 by: Brent Baisley
        199982 by: Chris Dowell
        199985 by: Graham Cossey
        199996 by: Robby Russell
        199998 by: M Saleh EG

Re: Mac OS X and Editor
        199975 by: Philip Thompson
        199983 by: Michael Sims

Passing the Array as Parameter to either the function or object/class???
        199984 by: Scott Fletcher
        199991 by: Greg Donald
        199993 by: Robby Russell
        199997 by: Scott Fletcher

Re: A better way to do this in php???
        199994 by: Brent Baisley

Simple Time Question
        199999 by: Ben Miller
        200000 by: Daniel Purdy
        200001 by: bbonkosk.tampabay.rr.com
        200002 by: M Saleh EG
        200004 by: Robby Russell
        200007 by: Ford, Mike
        200010 by: Robert Cummings
        200014 by: Robert Cummings
        200016 by: Ford, Mike
        200032 by: Marek Kilimajer

Re: remote file existance when protected by a .htaccess
        200003 by: Mag
        200005 by: Matt M.
        200006 by: Matt M.

Best practices for php application
        200008 by: abrea
        200009 by: Jay Blanchard
        200012 by: Robby Russell
        200015 by: Brent Baisley

Re-compiling PHP
        200011 by: Mike R
        200013 by: John Nichel
        200017 by: Mike R
        200018 by: Robby Russell
        200019 by: John Nichel
        200020 by: Mike R
        200022 by: Mike R
        200023 by: Matthew Sims
        200024 by: John Nichel
        200025 by: Greg Donald
        200026 by: Mike R
        200028 by: Robby Russell
        200029 by: Greg Donald

Trying to Integrate PHP 4.3.4 w/ JDK 1.5.0
        200021 by: Andrew Hauger

I cannot move files
        200030 by: Giacomo Cantilli
        200031 by: John Nichel
        200033 by: Marek Kilimajer

Question: Validation on select boxes and lists.
        200035 by: Stuart Felenstein

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Hi Stuart,

I haven't followed your thread too closely, but I did see something that might
be the cause of your problems:

[snip]

> Let me show you how I set it all up. Remember it's a
> multi page form:
> So the form elements are: skills[], skys[], slus[]
> Then on the next page I have to still pass the session
> variables, and so:
>
> $_SESSION['skills'] = $_POST['skill'];
> $_SESSION['skys'] = $_POST['sky'];
> $_SESSION['slus'] = $_POST['slu'];
>
> Now the transcation script:
>
> $skills = $_SESSION['skills'];
> $skys = $_SESSION['skys'];
> $slus = $_SESSION['slus'];
>
> foreach($_SESSION['skills'] as $key => $skill)
                ^^ ^^

[snip]

It's my understanding that where I've put ^^ should be enclosed by braces,
otherwise you'll get some starnge behaviour.

I'm puzzled why you reverted to $_SESSION['skills'] when the line above you've
set $skills = $_SESSION['skills']??

HTH,
Andre

attached mail follows:


You mean why do i have $_SESSION['skills'] in the
foreach ?

Stuart
--- Andre Dubuc <aajdubucwebhart.net> wrote:

> Hi Stuart,
>
> I haven't followed your thread too closely, but I
> did see something that might
> be the cause of your problems:
>
> [snip]
>
> > Let me show you how I set it all up. Remember it's
> a
> > multi page form:
> > So the form elements are: skills[], skys[], slus[]
> > Then on the next page I have to still pass the
> session
> > variables, and so:
> >
> > $_SESSION['skills'] = $_POST['skill'];
> > $_SESSION['skys'] = $_POST['sky'];
> > $_SESSION['slus'] = $_POST['slu'];
> >
> > Now the transcation script:
> >
> > $skills = $_SESSION['skills'];
> > $skys = $_SESSION['skys'];
> > $slus = $_SESSION['slus'];
> >
> > foreach($_SESSION['skills'] as $key => $skill)
> ^^ ^^
>

> I'm puzzled why you reverted to $_SESSION['skills']
> when the line above you've
> set $skills = $_SESSION['skills']??
>
> HTH,
> Andre
>

attached mail follows:


See inline:

[snip]
>
> Now the transcation script:
>
> $skills = $_SESSION['skills'];
> $skys = $_SESSION['skys'];
> $slus = $_SESSION['slus'];
>
> foreach($_SESSION['skills'] as $key => $skill)
          ^^^^^^^^^^^^^^^^^^^
         ($skills as $key => $skill)
> {
    if ($skill != '') // Has this skill been entered?
    {
      // You may also want to check for sky & slu entries

> $query = "INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, $LID, '$skill',
> {$_SESSION['skys'][$key]},{$_SESSION['slus'][$key]})";
   ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
   $skys[$key] $slus[$key]

> //$result = mysql_query($query);
> $res6 = run_query($query);
> echo $query;
  ^^^^^^^^^^^
  What does this output?

    }// end if ($skill != '')

> }
>
> I understand that in the insert statement I need not
> repeat $_SESSION.
> The rest though is fuzzy.
> It was working, now I'm getting some really odd
> behaviour, in that, unless i fill in every field in
> the form, I get a mysql syntax error.

HTH
Graham

attached mail follows:


Graham, I'm going to make those changes. Not sure if
that was creating some crazy behaviour. See inline:

--- Graham Cossey <grahamcossey.plus.com> wrote:

................
> > {
> if ($skill != '') // Has this skill been
> entered?

I don't know if I care if it's been entered. My main
concern would be to make sure that if a $skill was
entered, then a matching $skys and $slus
should be:
skills[0]-baker skys[0]-7 slus[0]-2002

but wouldn't want
skill[0]-baker skys[1]-7 slus[2]-2002

In other words I need to figure out how to check that
each "line" is complete. But~ right now, it is
matching all the values/inputs correctly. If someone
just chose a slus, seems the database won't take it.

> {
> // You may also want to check for sky & slu
> entries

Not sure why I would want too:

> > //$result = mysql_query($query);
> > $res6 = run_query($query);
> > echo $query;
> ^^^^^^^^^^^
> What does this output?

It outputs the insert and values string.
And it seems to print the iteration:

INSERT INTO LurkProfiles_Skicerts (SkicertID,
ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
39, 'aaaaa', 2,1)INSERT INTO LurkProfiles_Skicerts
(SkicertID, ProfileID, SkilCerts, NumYear, Lused)
VALUES (null, 39, 'bbbbb', 3,2)INSERT INTO
LurkProfiles_Skicerts (SkicertID, ProfileID,
SkilCerts, NumYear, Lused) VALUES (null, 39, 'ccccc',
4,3)INSERT INTO LurkProfiles_Skicerts (SkicertID,
ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
39, 'ddddd', 5,4)INSERT INTO LurkProfiles_Skicerts
(SkicertID, ProfileID, SkilCerts, NumYear, Lused)
VALUES (null, 39, 'eeeee', 6,5)your insertions were
successful

> }// end if ($skill != '')

This probably makes sense to add , perhaps that is why
if I don't use all the elements for input I get a
syntax error.

Stuart

attached mail follows:


See inline:

[snip]
> ................
> > > {
> > if ($skill != '') // Has this skill been
> > entered?
>
> I don't know if I care if it's been entered. My main
> concern would be to make sure that if a $skill was
> entered, then a matching $skys and $slus
> should be:
> skills[0]-baker skys[0]-7 slus[0]-2002
>
> but wouldn't want
> skill[0]-baker skys[1]-7 slus[2]-2002
>

So, you want to avoid all of the following:
  skill[0] 'baker' skys[0] '7' slus[0] ''
  skill[1] 'baker' skys[1] '' slus[1] '2002'
  skill[2] '' skys[2] '7' slus[2] '2002'
  skill[3] '' skys[3] '' slus[3] ''

You'll need to amend the if within the foreach loop to check for these.

if ($skill != '' && $skys[$key] != '' && $slus[$key] != '')

> In other words I need to figure out how to check that
> each "line" is complete. But~ right now, it is
> matching all the values/inputs correctly. If someone
> just chose a slus, seems the database won't take it.

But is this due to the sql statement being rejected as opposed to being
caught by your validation?

>
> > {
> > // You may also want to check for sky & slu
> > entries
>
> Not sure why I would want too:

You would want to because of the paragraph above about "My main concern..."

>
> > > //$result = mysql_query($query);
> > > $res6 = run_query($query);
> > > echo $query;
> > ^^^^^^^^^^^
> > What does this output?
>
> It outputs the insert and values string.
> And it seems to print the iteration:
>
> INSERT INTO LurkProfiles_Skicerts (SkicertID,
> ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
> 39, 'aaaaa', 2,1)INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, 39, 'bbbbb', 3,2)INSERT INTO
> LurkProfiles_Skicerts (SkicertID, ProfileID,
> SkilCerts, NumYear, Lused) VALUES (null, 39, 'ccccc',
> 4,3)INSERT INTO LurkProfiles_Skicerts (SkicertID,
> ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
> 39, 'ddddd', 5,4)INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, 39, 'eeeee', 6,5)your insertions were
> successful

This is OK, it's just a formatting thing, try changing your echo to:

echo "Query $key = $query <br>";

This should give you:

Query 0 = INSERT INTO LurkProfiles_Skicerts (SkicertID,ProfileID, SkilCerts,
NumYear, Lused) VALUES (null,39, 'aaaaa', 2,1)
Query 1 = INSERT INTO LurkProfiles_Skicerts (SkicertID, ProfileID,
SkilCerts, NumYear, Lused) VALUES (null,9, 'bbbbb', 3,2)
Query 2 = INSERT INTO LurkProfiles_Skicerts (SkicertID, ProfileID,
SkilCerts, NumYear, Lused) VALUES (null, 9, 'ccccc', 4,3)
Query 3 = INSERT INTO LurkProfiles_Skicerts (SkicertID, ProfileID,
SkilCerts, NumYear, Lused) VALUES (null,39, 'ddddd', 5,4)
Query 4 = INSERT INTO LurkProfiles_Skicerts (SkicertID, ProfileID,
SkilCerts, NumYear, Lused) VALUES (null, 9, 'eeeee', 6,5)

>
> > }// end if ($skill != '')
>
> This probably makes sense to add , perhaps that is why
> if I don't use all the elements for input I get a
> syntax error.

Possibly...

Graham

attached mail follows:


See inline:
--- Graham Cossey <grahamcossey.plus.com> wrote:

> > In other words I need to figure out how to check
> > that each "line" is complete. right now, it is
> > matching all the values/inputs correctly. If
> > someone just chose a slus, seems the database

> But is this due to the sql statement being rejected
> as opposed to being
> caught by your validation?

What validation :) . I haven't added that in yet,due
to figuring out why the insertions weren't taking.

> > > {
> > > // You may also want to check for sky &
> > > slu entries
> > > You would want to because of the paragraph above
> > > about "My main concern..."

Right now I have this [right below]: If I want to
check for skys and slus, I add another set of braces
with if($sky != '' ...
and below "end if ($sky != '')........

> foreach($skills as $key => $skill)
    {
    if ($skill != '' && $skys[$key] != '' &&
$slus[$key] != '')
    {
      
$query = "INSERT INTO LurkProfiles_Skicerts
(SkicertID, ProfileID, SkilCerts, NumYear, Lused)
VALUES (null, $LID, '$skill',
$skys[$key],$slus[$key])";
$res6 = run_query($query);
echo "Query $key = $query <br>";
        } end if ($skill != '')

}
Stuart

attached mail follows:


[snip]
> Right now I have this [right below]: If I want to
> check for skys and slus, I add another set of braces
> with if($sky != '' ...
> and below "end if ($sky != '')........
>
>
> > foreach($skills as $key => $skill)
> {
> if ($skill != '' && $skys[$key] != '' &&
> $slus[$key] != '')
> {
>
> $query = "INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, $LID, '$skill',
> $skys[$key],$slus[$key])";
> $res6 = run_query($query);
> echo "Query $key = $query <br>";
> } end if ($skill != '')
>
> }

That looks pretty much like what you want except for:

         } //end if ($skill != '')
        ^^
        Comment, this is just to help identify what the brace is closing.

Graham

attached mail follows:


Since your data on the client is linked, you should keep it linked on
submission by nesting an array with in the array.
Your client HTML should like something like this:
<input type="text" name="skills[0][skill]" value="" size="20">

<select name="skills[0][skys]" size="1">
<option ...>
</select>

<select name="skills[0][Lused]" size="1">
<option ...>
</select>

...
<input type="text" name="skills[1][skill]" value="" size="20">

<select name="skills[1][skys]" size="1">
<option ...>
</select>

<select name="skills[1][Lused]" size="1">
<option ...>
</select>

All the way up to skills[10][...], or however many you want. If
everything is filled out, you will then get a 10x3 array, just like a
spreadsheet.
Since empty fields won't get submitted, you will be missing parts of
your array. But that's easy to check for.

So for submission your are creating grid contain in one array variable
skills:
row skill skys Lused
1 C++ 3 10/1/2000
2 0 10/21/2004
3 ...

Now it's easy to process the grid and check for missing data.

$skills = $_POST['skills'];
//Process each row of the array $skills
//Each row may have up to three elements: skill, skys, Lused
foreach($skills as $skill) {
        //Check if a skill was entered by check for array element named 'skill'
        if(isset($skill['skill'])) {
                $query = 'INSERT INTO dbName (SkilCerts, NumYear, Lused)
                                VALUES ("'.$skill['skill'].'", '.$skill['skys'].',
'.$skill['Lused'].')';
        }
}

On Oct 21, 2004, at 6:55 AM, Stuart Felenstein wrote:

> Graham, I'm going to make those changes. Not sure if
> that was creating some crazy behaviour. See inline:
>
> --- Graham Cossey <grahamcossey.plus.com> wrote:
>
> ................
>>> {
>> if ($skill != '') // Has this skill been
>> entered?
>
> I don't know if I care if it's been entered. My main
> concern would be to make sure that if a $skill was
> entered, then a matching $skys and $slus
> should be:
> skills[0]-baker skys[0]-7 slus[0]-2002
>
> but wouldn't want
> skill[0]-baker skys[1]-7 slus[2]-2002
>
> In other words I need to figure out how to check that
> each "line" is complete. But~ right now, it is
> matching all the values/inputs correctly. If someone
> just chose a slus, seems the database won't take it.
>
>> {
>> // You may also want to check for sky & slu
>> entries
>
> Not sure why I would want too:
>
>>> //$result = mysql_query($query);
>>> $res6 = run_query($query);
>>> echo $query;
>> ^^^^^^^^^^^
>> What does this output?
>
> It outputs the insert and values string.
> And it seems to print the iteration:
>
> INSERT INTO LurkProfiles_Skicerts (SkicertID,
> ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
> 39, 'aaaaa', 2,1)INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, 39, 'bbbbb', 3,2)INSERT INTO
> LurkProfiles_Skicerts (SkicertID, ProfileID,
> SkilCerts, NumYear, Lused) VALUES (null, 39, 'ccccc',
> 4,3)INSERT INTO LurkProfiles_Skicerts (SkicertID,
> ProfileID, SkilCerts, NumYear, Lused) VALUES (null,
> 39, 'ddddd', 5,4)INSERT INTO LurkProfiles_Skicerts
> (SkicertID, ProfileID, SkilCerts, NumYear, Lused)
> VALUES (null, 39, 'eeeee', 6,5)your insertions were
> successful
>
>> }// end if ($skill != '')
>
> This probably makes sense to add , perhaps that is why
> if I don't use all the elements for input I get a
> syntax error.
>
> Stuart
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

attached mail follows:


in a page checkuser i do this after the user is logged in:
      PHP Code
      // Register some session variables!
              session_register('userid');
              $_SESSION['userid'] = $userid;
              session_register('first_name');
              $_SESSION['first_name'] = $first_name;
              session_register('last_name');
              $_SESSION['last_name'] = $last_name;
              session_register('email_address');
              $_SESSION['email_address'] = $email_address;
              session_register('user_level');
              $_SESSION['user_level'] = $user_level;

Now let's say user 1 logs in, his session is registered (with userid from
database is 5 and first_name is XXX)
Then another user logs in, again his session is registered (with userid from
database is 1 and first_name is YYY)

Now user 1 leaves the pages (closes the browser) and user 2 uploads a
document (with my own script).

When the document is succesfully uploaded i display this:
      PHP Code
      echo ($_SESSION['first_name']).", the document has been succesfully
added";
      echo ($_SESSION['userid']);

This results in the folowing output:
YYY, the document has been succesfully added
5

Meaning the $_SESSION['first_name'] is correct, but the $_SESSION['userid']
is the one of the user who logged out...

Now when using user_id in all places it seems to work correctly...

Is userid something that is defined by the server when making sessions?

If not, i don't have any clue what is going wrong...
Can someone help me on this? So i know what is wrong?

Thx in advance

Pout

attached mail follows:


Reinhart Viane wrote:

>in a page checkuser i do this after the user is logged in:
> PHP Code
> // Register some session variables!
> session_register('userid');
> $_SESSION['userid'] = $userid;
> session_register('first_name');
> $_SESSION['first_name'] = $first_name;
> session_register('last_name');
> $_SESSION['last_name'] = $last_name;
> session_register('email_address');
> $_SESSION['email_address'] = $email_address;
> session_register('user_level');
> $_SESSION['user_level'] = $user_level;
>
>
You should only save the userId in the session, everything else should
be retrieved from your database using that id.

>
>
>Now let's say user 1 logs in, his session is registered (with userid from
>database is 5 and first_name is XXX)
>Then another user logs in, again his session is registered (with userid from
>database is 1 and first_name is YYY)
>
>
>
Are both user's in the same computer? then there may be a question about
the old cookie being sent back to the server (if it's expiration time
has not been exceeded). If the users are not using the same computer the
chances are you have a bug in your code.

>Now user 1 leaves the pages (closes the browser) and user 2 uploads a
>document (with my own script).
>
>When the document is succesfully uploaded i display this:
> PHP Code
> echo ($_SESSION['first_name']).", the document has been succesfully
>added";
> echo ($_SESSION['userid']);
>
>
>
>This results in the folowing output:
>YYY, the document has been succesfully added
>5
>
>Meaning the $_SESSION['first_name'] is correct, but the $_SESSION['userid']
>is the one of the user who logged out...
>
>Now when using user_id in all places it seems to work correctly...
>
>Is userid something that is defined by the server when making sessions?
>
>
no.

>If not, i don't have any clue what is going wrong...
>Can someone help me on this? So i know what is wrong?
>
>

>Thx in advance
>
>Pout
>
>
>

--
Raditha Dissanayake.
------------------------------------------------------------------------
http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 128 KB | with progress bar.

attached mail follows:


In message <4177C422.7030606raditha.com>, raditha dissanayake
<jabberraditha.com> writes
>Reinhart Viane wrote:
>
>>in a page checkuser i do this after the user is logged in:
>> PHP Code
>> // Register some session variables!
>> session_register('userid');
>> $_SESSION['userid'] = $userid;
>> session_register('first_name');
>> $_SESSION['first_name'] = $first_name;
>> session_register('last_name');
>> $_SESSION['last_name'] = $last_name;
>> session_register('email_address');
>> $_SESSION['email_address'] = $email_address;
>> session_register('user_level');
>> $_SESSION['user_level'] = $user_level;
>>
>>
>You should only save the userId in the session, everything else should
>be retrieved from your database using that id.

I normally do as you have suggested here - but why do you suggest that
this method is better?

--
Pete Clark

attached mail follows:


Hey all, i'm new to this list so forgive me if i make any huge
mistakes.
I'm in a beginning stage of learning php and i hope you guys can help me
out with this question:

in a file named checkuser i do this when a users logs in:
PHP Code
// Register some session variables!
        session_register('userid');
        $_SESSION['userid'] = $userid;
        session_register('first_name');
        $_SESSION['first_name'] = $first_name;
        session_register('last_name');
        $_SESSION['last_name'] = $last_name;
        session_register('email_address');
        $_SESSION['email_address'] = $email_address;
        session_register('user_level');
        $_SESSION['user_level'] = $user_level;

Now let's say user 1 logs in, his session is registered (with userid
from database is 5 and first_name is XXX)
Then another user logs in, again his session is registered (with userid
from database is 1 and first_name is YYY)

Now user 1 leaves the pages (closes the browser) and user 2 uploads a
document (with my own script).

When the document is succesfully uploaded i display this:
PHP Code
echo ($_SESSION['first_name']).", the document has been succesfully
added";
echo ($_SESSION['userid']);

This results in the folowing output:
YYY, the document has been succesfully added
5

Meaning the $_SESSION['first_name'] is correct, but the
$_SESSION['userid'] is the one of the user who logged out...

Now when using user_id in all places it seems to work correctly...

Is userid something that is defined by the server when making sessions?

If not, i don't have any clue what is going wrong...
Can someone help me on this? So i know what is wrong?

Thx in advance

Reinhart Viane

attached mail follows:


On Thu, 21 Oct 2004 11:39:23 +0200, Reinhart Viane <rvdomos.be> wrote:
> Hey all, i'm new to this list so forgive me if i make any huge
> mistakes.
> I'm in a beginning stage of learning php and i hope you guys can help me
> out with this question:
>
> in a file named checkuser i do this when a users logs in:
> PHP Code
> // Register some session variables!
> session_register('userid');
> $_SESSION['userid'] = $userid;
> session_register('first_name');
> $_SESSION['first_name'] = $first_name;
> session_register('last_name');
> $_SESSION['last_name'] = $last_name;
> session_register('email_address');
> $_SESSION['email_address'] = $email_address;
> session_register('user_level');
> $_SESSION['user_level'] = $user_level;
>
> Now let's say user 1 logs in, his session is registered (with userid
> from database is 5 and first_name is XXX)
> Then another user logs in, again his session is registered (with userid
> from database is 1 and first_name is YYY)
>
> Now user 1 leaves the pages (closes the browser) and user 2 uploads a
> document (with my own script).
>
> When the document is succesfully uploaded i display this:
> PHP Code
> echo ($_SESSION['first_name']).", the document has been succesfully
> added";
> echo ($_SESSION['userid']);
>
> This results in the folowing output:
> YYY, the document has been succesfully added
> 5
>
> Meaning the $_SESSION['first_name'] is correct, but the
> $_SESSION['userid'] is the one of the user who logged out...
>
> Now when using user_id in all places it seems to work correctly...
>
> Is userid something that is defined by the server when making sessions?
>
> If not, i don't have any clue what is going wrong...
> Can someone help me on this? So i know what is wrong?
>
> Thx in advance
>
> Reinhart Viane
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Where does the value $userid come from is it the result of a query
i.e.
SELECT userid FROM users WHERE username='$_POST['username']' AND
passwd='$_POST['password']'

 or do you have a form (text/hidden) with that value?

You mention userid and user_id maybe a typo, but those would be different.
You can see all session variables (for testing) by adding:

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

attached mail follows:


Hey Mike,

After some intensive testing it seemed that $user_id did not solve the
isue

I hereby give the script to get the $user_id:

// check if the user info validates the db
($username and $password are the POST values of username and password
given in on a form)
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND
password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
        while($row = mysql_fetch_array($sql)){
        foreach( $row AS $key => $val ){
                $$key = stripslashes( $val );
        }
                // Register some session variables!
                session_register('user_id');
                $_SESSION['user_id'] = $user_id;
                session_register('first_name');
                $_SESSION['first_name'] = $first_name;
                session_register('last_name');
                $_SESSION['last_name'] = $last_name;
                session_register('email_address');
                $_SESSION['email_address'] = $email_address;
                session_register('user_level');
                $_SESSION['user_level'] = $user_level;
                
                mysql_query("UPDATE users SET last_login=now() WHERE
user_id='$user_id'");
                
                header("Location: main.php");

        }

Now this is my conclusion till now:

All other session items are correctly displayed, except the
$_SESSION['user_id']
I'm trying to find the way when this happens since it does not seem to
happen in a strict order
The method mentioned b4:
'>Now let's say user 1 logs in, his session is registered (with userid
> from database is 5 and first_name is XXX) Then another user logs in,
> again his session is registered (with userid from database is 1 and
> first_name is YYY)'

is not always faulty.
I've checked everything I know and the last thing I've done is putted:

session_start();

On the first line instead of after this:
<?
require('xx.inc.php');
connect_db();

Untill now all seems to be ok, but I'm not certain at all it is ok.
There can be hundreds of methods how several users log in, upload, log
out etc. so I can not test them all... :(

It seems that sometimes the $_SESSION['user_id'] of the several users
get mixed and this may not happen.

I don't know if this is a known bug or if there are cases which can
cause this...
If im not certain if this can be solved I will have to use another
method to keep the logged in users info (but what one? Don't want to use
cookies)

Thx in advance for any help.

Greetings,

Reinhart

-----Original Message-----
From: Mike Smith [mailto:mikeosmithgmail.com]
Sent: donderdag 21 oktober 2004 13:28
To: rvdomos.be
Cc: php-generallists.php.net
Subject: Re: [PHP] Sessions question

On Thu, 21 Oct 2004 11:39:23 +0200, Reinhart Viane <rvdomos.be> wrote:
> Hey all, i'm new to this list so forgive me if i make any huge
> mistakes. I'm in a beginning stage of learning php and i hope you guys

> can help me out with this question:
>
> in a file named checkuser i do this when a users logs in:
> PHP Code
> // Register some session variables!
> session_register('userid');
> $_SESSION['userid'] = $userid;
> session_register('first_name');
> $_SESSION['first_name'] = $first_name;
> session_register('last_name');
> $_SESSION['last_name'] = $last_name;
> session_register('email_address');
> $_SESSION['email_address'] = $email_address;
> session_register('user_level');
> $_SESSION['user_level'] = $user_level;
>
> Now let's say user 1 logs in, his session is registered (with userid
> from database is 5 and first_name is XXX) Then another user logs in,
> again his session is registered (with userid from database is 1 and
> first_name is YYY)
>
> Now user 1 leaves the pages (closes the browser) and user 2 uploads a
> document (with my own script).
>
> When the document is succesfully uploaded i display this:
> PHP Code
> echo ($_SESSION['first_name']).", the document has been succesfully
> added"; echo ($_SESSION['userid']);
>
> This results in the folowing output:
> YYY, the document has been succesfully added
> 5
>
> Meaning the $_SESSION['first_name'] is correct, but the
> $_SESSION['userid'] is the one of the user who logged out...
>
> Now when using user_id in all places it seems to work correctly...
>
> Is userid something that is defined by the server when making
> sessions?
>
> If not, i don't have any clue what is going wrong...
> Can someone help me on this? So i know what is wrong?
>
> Thx in advance
>
> Reinhart Viane
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Where does the value $userid come from is it the result of a query i.e.
SELECT userid FROM users WHERE username='$_POST['username']' AND
passwd='$_POST['password']'

 or do you have a form (text/hidden) with that value?

You mention userid and user_id maybe a typo, but those would be
different. You can see all session variables (for testing) by adding:

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


On Thu, 21 Oct 2004 14:43:45 +0200, Reinhart Viane <rvdomos.be> wrote:
> Hey Mike,
>
> After some intensive testing it seemed that $user_id did not solve the
> isue
>
> I hereby give the script to get the $user_id:
>
> // check if the user info validates the db
> ($username and $password are the POST values of username and password
> given in on a form)
> $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND
> password='$password' AND activated='1'");
> $login_check = mysql_num_rows($sql);
>
> if($login_check > 0){
> while($row = mysql_fetch_array($sql)){
> foreach( $row AS $key => $val ){

Your select * query above is probably pulling more than two fields, so
a $key and $val in the foreach() will only work with two of those
fields, the other fields will be unhandled. You might want to ditch
the foreach() loop and just use the while() loop by itself since you
can easily access all the fields from your query in the $row array.

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


Thanks Greg,

I'll try this, but I do not think this will solve the issue since at
first hand the session variables are correctly made.

The problem arrises (I think) whenever two or more users are logged in
and one closes the pages (so his session is killed I suppose).
Sometimes after that, the other users seem to get other values for the
user_id session variable.
Strange thing is the other session (like first_name or last_name)
variables of the user stay correct. Only the user_id session variable is
changed.

I don't know if this can be caused by the fact register_globals seem to
be 'on' on the server (btw PHP Version 4.2.3)

Thx for the advice, I hope I can sort it out soon

Greetz
Reinhart

-----Original Message-----
From: Greg Donald [mailto:destineygmail.com]
Sent: donderdag 21 oktober 2004 15:47
To: php-generallists.php.net
Subject: Re: [PHP] Sessions question

On Thu, 21 Oct 2004 14:43:45 +0200, Reinhart Viane <rvdomos.be> wrote:
> Hey Mike,
>
> After some intensive testing it seemed that $user_id did not solve the

> isue
>
> I hereby give the script to get the $user_id:
>
> // check if the user info validates the db
> ($username and $password are the POST values of username and password
> given in on a form) $sql = mysql_query("SELECT * FROM users WHERE
> username='$username' AND password='$password' AND activated='1'");
> $login_check = mysql_num_rows($sql);
>
> if($login_check > 0){
> while($row = mysql_fetch_array($sql)){
> foreach( $row AS $key => $val ){

Your select * query above is probably pulling more than two fields, so a
$key and $val in the foreach() will only work with two of those fields,
the other fields will be unhandled. You might want to ditch the
foreach() loop and just use the while() loop by itself since you can
easily access all the fields from your query in the $row array.

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


On Thu, 21 Oct 2004 16:06:37 +0200, Reinhart Viane <rvdomos.be> wrote:
> I don't know if this can be caused by the fact register_globals seem to
> be 'on' on the server (btw PHP Version 4.2.3)

You can override that setting if the web server is running apache and
AllowOverrides is set for your directory. You can make an .htaccess
file with this in it:

php_flag register_globals Off

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


On Thu, 21 Oct 2004 14:43:45 +0200, Reinhart Viane <rvdomos.be> wrote:
> Hey Mike,
>
> After some intensive testing it seemed that $user_id did not solve the
> isue
>
> I hereby give the script to get the $user_id:
>
> // check if the user info validates the db
> ($username and $password are the POST values of username and password
> given in on a form)
> $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND
> password='$password' AND activated='1'");
> $login_check = mysql_num_rows($sql);
>
> if($login_check > 0){
> while($row = mysql_fetch_array($sql)){
> foreach( $row AS $key => $val ){
> $$key = stripslashes( $val );
> }
> // Register some session variables!
> session_register('user_id');
> $_SESSION['user_id'] = $user_id;
> session_register('first_name');
> $_SESSION['first_name'] = $first_name;
> session_register('last_name');
> $_SESSION['last_name'] = $last_name;
> session_register('email_address');
> $_SESSION['email_address'] = $email_address;
> session_register('user_level');
> $_SESSION['user_level'] = $user_level;
>
> mysql_query("UPDATE users SET last_login=now() WHERE
> user_id='$user_id'");
>
> header("Location: main.php");
>
> }
>
> Now this is my conclusion till now:
>
> All other session items are correctly displayed, except the
> $_SESSION['user_id']
> I'm trying to find the way when this happens since it does not seem to
> happen in a strict order
> The method mentioned b4:
> '>Now let's say user 1 logs in, his session is registered (with userid
> > from database is 5 and first_name is XXX) Then another user logs in,
> > again his session is registered (with userid from database is 1 and
> > first_name is YYY)'
>
> is not always faulty.
> I've checked everything I know and the last thing I've done is putted:
>
> session_start();
>
> On the first line instead of after this:
> <?
> require('xx.inc.php');
> connect_db();
>
> Untill now all seems to be ok, but I'm not certain at all it is ok.
> There can be hundreds of methods how several users log in, upload, log
> out etc. so I can not test them all... :(
>
> It seems that sometimes the $_SESSION['user_id'] of the several users
> get mixed and this may not happen.
>
> I don't know if this is a known bug or if there are cases which can
> cause this...
> If im not certain if this can be solved I will have to use another
> method to keep the logged in users info (but what one? Don't want to use
> cookies)
>
> Thx in advance for any help.
>
> Greetings,
>
> Reinhart
>
>
>
> -----Original Message-----
> From: Mike Smith [mailto:mikeosmithgmail.com]
> Sent: donderdag 21 oktober 2004 13:28
> To: rvdomos.be
> Cc: php-generallists.php.net
> Subject: Re: [PHP] Sessions question
>
> On Thu, 21 Oct 2004 11:39:23 +0200, Reinhart Viane <rvdomos.be> wrote:
> > Hey all, i'm new to this list so forgive me if i make any huge
> > mistakes. I'm in a beginning stage of learning php and i hope you guys
>
> > can help me out with this question:
> >
> > in a file named checkuser i do this when a users logs in:
> > PHP Code
> > // Register some session variables!
> > session_register('userid');
> > $_SESSION['userid'] = $userid;
> > session_register('first_name');
> > $_SESSION['first_name'] = $first_name;
> > session_register('last_name');
> > $_SESSION['last_name'] = $last_name;
> > session_register('email_address');
> > $_SESSION['email_address'] = $email_address;
> > session_register('user_level');
> > $_SESSION['user_level'] = $user_level;
> >
> > Now let's say user 1 logs in, his session is registered (with userid
> > from database is 5 and first_name is XXX) Then another user logs in,
> > again his session is registered (with userid from database is 1 and
> > first_name is YYY)
> >
> > Now user 1 leaves the pages (closes the browser) and user 2 uploads a
> > document (with my own script).
> >
> > When the document is succesfully uploaded i display this:
> > PHP Code
> > echo ($_SESSION['first_name']).", the document has been succesfully
> > added"; echo ($_SESSION['userid']);
> >
> > This results in the folowing output:
> > YYY, the document has been succesfully added
> > 5
> >
> > Meaning the $_SESSION['first_name'] is correct, but the
> > $_SESSION['userid'] is the one of the user who logged out...
> >
> > Now when using user_id in all places it seems to work correctly...
> >
> > Is userid something that is defined by the server when making
> > sessions?
> >
> > If not, i don't have any clue what is going wrong...
> > Can someone help me on this? So i know what is wrong?
> >
> > Thx in advance
> >
> > Reinhart Viane
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> Where does the value $userid come from is it the result of a query i.e.
> SELECT userid FROM users WHERE username='$_POST['username']' AND
> passwd='$_POST['password']'
>
> or do you have a form (text/hidden) with that value?
>
> You mention userid and user_id maybe a typo, but those would be
> different. You can see all session variables (for testing) by adding:
>
> echo "<pre>\n";
> print_r($_SESSION);
> echo "</pre>\n";
>
> --
>
>
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

How about changing

> while($row = mysql_fetch_array($sql)){
> foreach( $row AS $key => $val ){
> $$key = stripslashes( $val );
> }

to

while($row = mysql_fetch_array($sql)){
$_SESSION['user_id']=$row[0]; //or whatever position user_id is in.
 }

When you execute your query does it only give you one result?

attached mail follows:


hi,
Please don't send multiple posts, I just replied to your previous
message thinking that it had not been answered, a little further down I
come across this. It's very confusing to everyone.

thanks

--
Raditha Dissanayake.
------------------------------------------------------------------------
http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 128 KB | with progress bar.

attached mail follows:


On Thu, 21 Oct 2004 10:14:47 -0400, Mike Smith <mikeosmithgmail.com> wrote:
> How about changing

How about learning to trim your posts? Thanks. :)

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


* Thus wrote Reinhart Viane:
> PHP Code
> // Register some session variables!
> session_register('userid');
> $_SESSION['userid'] = $userid;

Do not use session_register with $_SESSION.

http://php.net/session-register

Curt
--
Quoth the Raven, "Nevermore."

attached mail follows:


I'm moving hosts for a freelance site I do...

They have an events section, and it's sortable by date, name and category
etc...
To achieve this, I passed the search/sort variables via the URL...
However, I'm testing the new server, and those variables are not being
detected?

I've put this code at teh top of the code on events page '$sort_by =
$_GET[sort_by];' etc...
And while that sorts out the problem, I'm curious as to why I need to do
that, and if those changes will cause me probs elsewhere?

Perhaps a rookie Q, but I guess we all learn something every day eh?

Any thoughts?
Tris...

*********************************************************************
The information contained in this e-mail message is intended only for
the personal and confidential use of the recipient(s) named above.
If the reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are hereby
notified that you have received this document in error and that any
review, dissemination, distribution, or copying of this message is
strictly prohibited. If you have received this communication in error,
please notify us immediately by e-mail, and delete the original message.
***********************************************************************

attached mail follows:


On Thu, 21 Oct 2004 14:08:28 +0100, tristan.prettyrisk.sungard.com
<tristan.prettyrisk.sungard.com> wrote:
> I'm moving hosts for a freelance site I do...
>
> They have an events section, and it's sortable by date, name and category
> etc...
> To achieve this, I passed the search/sort variables via the URL...
> However, I'm testing the new server, and those variables are not being
> detected?
>
> I've put this code at teh top of the code on events page '$sort_by =
> $_GET[sort_by];' etc...
> And while that sorts out the problem, I'm curious as to why I need to do
> that, and if those changes will cause me probs elsewhere?
>
> Perhaps a rookie Q, but I guess we all learn something every day eh?
>
> Any thoughts?

I'm guessing you used to have register_globals on, and now you don't.

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


Hi Trisan,

Quoting Tristan.Prettyrisk.sungard.com:

> I've put this code at teh top of the code on events page '$sort_by =
> $_GET[sort_by];' etc...
> And while that sorts out the problem, I'm curious as to why I need to do
> that, and if those changes will cause me probs elsewhere?

Perhaps on your old server, register_globals was on and on the new server it is
off?
Here's a link for more info on it
http://us2.php.net/register_globals

-R'twick
--
This is a signature

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

attached mail follows:


Hi,

I have been trying for the past two hours to understand why I get an error
with the following code:

<?php
 $test_array[] = array();
 $i = 0;
 while($i < 7){
  $test_array[$i] += $i;
  echo '$day_total[$i] = '.$day_total[$i].'<br>';
 }
?>

Fatal error: Unsupported operand types in
/usr/home/expensesystem/public_html/test.php on line 5

I am trying to create a loop where $i is added to array element $i, and
can't find any information relating to this on google or php.net...

Thanks for your advice.

attached mail follows:


On Thu, 21 Oct 2004 14:28:26 +0100, Shaun <shaunthornburghhotmail.com> wrote:
> I have been trying for the past two hours to understand why I get an error
> with the following code:
>
> <?php
> $test_array[] = array();

$test_array = array();

> $i = 0;
> while($i < 7){
> $test_array[$i] += $i;

$test_array[$i] = $i++; // maybe what you want ?

> echo '$day_total[$i] = '.$day_total[$i].'<br>';
> }
> ?>
>
> Fatal error: Unsupported operand types in
> /usr/home/expensesystem/public_html/test.php on line 5
>
> I am trying to create a loop where $i is added to array element $i, and
> can't find any information relating to this on google or php.net...

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


Shaun

The problem is that you've assigned $test_array[] = array();

This means that the first element ($test_array[0]) is an array.

You're then trying to add $i to it, as in $test_array[$i] =
$test_array[$i] + 1;

in terms of types what you're doing is array = array + integer

Which doesn't make any sense.

If you change the first line to $test_array = array();

Then the individual elements will all be NULL, which evaluates to 0 in
an integer context, and you will get the result you expect.

Hope this helps

Cheers

Chris

Shaun wrote:

> Hi,
>
> I have been trying for the past two hours to understand why I get an error
> with the following code:
>
> <?php
> $test_array[] = array();
> $i = 0;
> while($i < 7){
> $test_array[$i] += $i;
> echo '$day_total[$i] = '.$day_total[$i].'<br>';
> }
> ?>
>
> Fatal error: Unsupported operand types in
> /usr/home/expensesystem/public_html/test.php on line 5
>
> I am trying to create a loop where $i is added to array element $i, and
> can't find any information relating to this on google or php.net...
>
> Thanks for your advice.
>

attached mail follows:


[snip]
>
> Hi,
>
> I have been trying for the past two hours to understand why I get
> an error
> with the following code:
>
> <?php
> $test_array[] = array();
> $i = 0;
> while($i < 7){
> $test_array[$i] += $i;
> echo '$day_total[$i] = '.$day_total[$i].'<br>';
> }
> ?>
>
> Fatal error: Unsupported operand types in
> /usr/home/expensesystem/public_html/test.php on line 5
>
> I am trying to create a loop where $i is added to array element $i, and
> can't find any information relating to this on google or php.net...
>
> Thanks for your advice.

Try this:
<?php
 $test_array[] = array();
 $i = 0;
 while($i < 7){
  $test_array[$i] = $i;
  echo '$test_array[$i] = '.$test_array[$i].'<br>';
  $i++;
 }
?>

PHP objected to the use of +=
You did NOT want to increment $i before doing the echo anyway, did you?

Graham

attached mail follows:


You are making the first element of the array $test_array and array
item. An array inside and array.
$test_array[] = array() is the same as $test_array[0] = array()

So what you are trying to do is add $i to an array. Kind of like trying
to figure out what happens when you add 1 to the color red.

Try one of these:
$test_array = array()
or
$test_array = array(0,0,0,0,0,0,0)

Basically, drop the brackets. You use brackets to reference and array
element, not the array itself.

On Oct 21, 2004, at 9:28 AM, Shaun wrote:

> Hi,
>
> I have been trying for the past two hours to understand why I get an
> error
> with the following code:
>
> <?php
> $test_array[] = array();
> $i = 0;
> while($i < 7){
> $test_array[$i] += $i;
> echo '$day_total[$i] = '.$day_total[$i].'<br>';
> }
> ?>
>
> Fatal error: Unsupported operand types in
> /usr/home/expensesystem/public_html/test.php on line 5
>
> I am trying to create a loop where $i is added to array element $i, and
> can't find any information relating to this on google or php.net...
>
> Thanks for your advice.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

attached mail follows:


That is, expected results, *apart* from the infinite loop you'll have
due to not incrementing $i

Cheers

Chris

Chris Dowell wrote:

> Shaun
>
> The problem is that you've assigned $test_array[] = array();
>
> This means that the first element ($test_array[0]) is an array.
>
> You're then trying to add $i to it, as in $test_array[$i] =
> $test_array[$i] + 1;
>
> in terms of types what you're doing is array = array + integer
>
> Which doesn't make any sense.
>
> If you change the first line to $test_array = array();
>
> Then the individual elements will all be NULL, which evaluates to 0 in
> an integer context, and you will get the result you expect.
>
> Hope this helps
>
> Cheers
>
> Chris
>
> Shaun wrote:
>
>> Hi,
>>
>> I have been trying for the past two hours to understand why I get an
>> error with the following code:
>>
>> <?php
>> $test_array[] = array();
>> $i = 0;
>> while($i < 7){
>> $test_array[$i] += $i;
>> echo '$day_total[$i] = '.$day_total[$i].'<br>';
>> }
>> ?>
>>
>> Fatal error: Unsupported operand types in
>> /usr/home/expensesystem/public_html/test.php on line 5
>>
>> I am trying to create a loop where $i is added to array element $i,
>> and can't find any information relating to this on google or php.net...
>>
>> Thanks for your advice.
>
>

attached mail follows:


Oh #*!
Thanks Greg, I always get that one wrong !

$test_array = array();

:)

> -----Original Message-----
> From: Graham Cossey [mailto:grahamcossey.plus.com]
> Sent: 21 October 2004 14:48
> To: Shaun; php-generallists.php.net
> Subject: RE: [PHP] Strange Array Error
>
>
> [snip]
> >
> > Hi,
> >
> > I have been trying for the past two hours to understand why I get
> > an error
> > with the following code:
> >
> > <?php
> > $test_array[] = array();
> > $i = 0;
> > while($i < 7){
> > $test_array[$i] += $i;
> > echo '$day_total[$i] = '.$day_total[$i].'<br>';
> > }
> > ?>
> >
> > Fatal error: Unsupported operand types in
> > /usr/home/expensesystem/public_html/test.php on line 5
> >
> > I am trying to create a loop where $i is added to array element $i, and
> > can't find any information relating to this on google or php.net...
> >
> > Thanks for your advice.
>
> Try this:
> <?php
> $test_array[] = array();
> $i = 0;
> while($i < 7){
> $test_array[$i] = $i;
> echo '$test_array[$i] = '.$test_array[$i].'<br>';
> $i++;
> }
> ?>
>
> PHP objected to the use of +=
> You did NOT want to increment $i before doing the echo anyway, did you?
>
> Graham
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


On Thu, 2004-10-21 at 15:04 +0100, Graham Cossey wrote:
> Oh #*!
> Thanks Greg, I always get that one wrong !
>
> $test_array = array();
>
> :)

a few less lines version:

$test_array = array();

for ($i=0; $i<7; $i++)
    $test_array[$i] = $i;

print_r($test_array);

hth,

-Robby

--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robbyplanetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
****************************************/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQBBd8gZ0QaQZBaqXgwRAls3AJ42ibkRbJRRGeKydSlgo/ebjqNFVgCfUEyd
GKFiVSpEbPPSroUorxVTUd8=
=W5hF
-----END PGP SIGNATURE-----

attached mail follows:


On Thu, 21 Oct 2004 14:28:26 +0100, Shaun <shaunthornburghhotmail.com> wrote:
> Hi,
>
> I have been trying for the past two hours to understand why I get an error
> with the following code:
>
> <?php
> $test_array[] = array();
   //Change it to $test_array=array();
   /*Your statement adds an array to the current+1 position of the
array since you've put the [] after the variable the PHP interpreter
initializes it as an array type of variable so it takes that action*/

> $i = 0;
> while($i < 7){
> $test_array[$i] += $i;
> echo '$day_total[$i] = '.$day_total[$i].'<br>';
    // Change the single quotes to double quotes
    // i.e. echo "{$day_total[$i]}={$day_total[$i]}<br />";
    // Add ++$i; here
> }
> ?>

Notes: -Always use double quotes if you want to concatanate vars with strings.
          -Whe ur using arrays in ur strings that is to be
concatenated delimit the array by { and }.
          -Take a look at sprintf function to better format strings in
case ur familiar with C coding style.
          -Sometimes googling might not help nor PHP.net. So, the PHP
manual is ur friend. e.g you could go to Array section in PHP manual
and find out what's up :)

>
> Fatal error: Unsupported operand types in
> /usr/home/expensesystem/public_html/test.php on line 5
>
> I am trying to create a loop where $i is added to array element $i, and
> can't find any information relating to this on google or php.net...
>
> Thanks for your advice.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Hope that helps.
--
M.Saleh.E.G
97150-4779817

attached mail follows:


On Oct 20, 2004, at 3:57 PM, Michael Sims wrote:

> Jonel Rienton wrote:
>> Hi guys, I just like to ask those using Macs here as to what editor
>> and/or IDE they are using for writing PHP codes.
>
> I don't personally use Mac OS X, but let me throw in a recommendation
> for jEdit
> (www.jedit.org). It's Java based, hence cross-platform, and extremely
> powerful. I
> use it on Windows and couldn't live without it. I have installed it
> on my friend's
> iMac long enough to see that it works, but not long enough to know of
> any
> platform-specific issues and/or gotchas.

I use Xcode to do all my coding.

Just a side-comment: in general, OS X users enjoy/use Cocoa-based
applications over Java-based. Cocoa provides the "OS X Experience" with
the native aqua interface and other cool features that Java cannot
always supply. (Not intending to start a discussion... just informing
those non-Mac users.)

~P

attached mail follows:


Philip Thompson wrote:
>> I don't personally use Mac OS X, but let me throw in a
>> recommendation for jEdit (www.jedit.org). It's Java based, hence
[...]
> Just a side-comment: in general, OS X users enjoy/use Cocoa-based
> applications over Java-based. Cocoa provides the "OS X Experience"
> with the native aqua interface and other cool features that Java
> cannot always supply. (Not intending to start a discussion... just
> informing those non-Mac users.)

It's also been my experience that Windows users prefer pure Win32-based applications
over Java-based ones as well. However, IMHO jEdit is so flexible and powerful, and
so completely out-classes every other *free* Windows based IDE I have used, that I'm
willing to put up with whatever headaches using a Java based program imposes (which
isn't much if you have a reasonably fast machine). And it is possible on Windows to
configure jEdit so that it's look and feel is very much native Win32. I'm not sure
if this is possible on OS X or not, but I'd be surprised if it weren't.

Also, this may not be an advantage for the average joe, but for me the
cross-platform capability that Java brings is a major advantage. I'm a Windows user
now, but eventually I plan to switch to OS X (once I have the cash). I like the
fact that I can use my favorite IDE, including all the plugins/customizations/macros
that I've built up over the last year or so, on OS X or Linux with a minimum of
hassle.

As usual, this is all IMHO and YMMV... :)

attached mail follows:


Hi!

    I wanted to know is can it be done by passing the array as a parameter
to the function?

    I also wanted to know is is it possible to pass around the array in the
object-orientated feature like object/class stuffs?

Thanks,
 Scott

attached mail follows:


On Thu, 21 Oct 2004 09:57:07 -0400, Scott Fletcher <scottabcoa.com> wrote:
> I wanted to know is can it be done by passing the array as a parameter
> to the function?

Yes. By reference and by value.

> I also wanted to know is is it possible to pass around the array in the
> object-orientated feature like object/class stuffs?

Yes. By reference and by value.

Some people have issues with theoretical posts like this one. Showing
an honest attempt with some broken code usually gets help the
quickest.

--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

attached mail follows:


On Thu, 2004-10-21 at 09:57 -0400, Scott Fletcher wrote:
> Hi!
>
> I wanted to know is can it be done by passing the array as a parameter
> to the function?
>
> I also wanted to know is is it possible to pass around the array in the
> object-orientated feature like object/class stuffs?
>

yes and yes.

ie:

function foo($bar)
{
  print_r($bar);
}

$myarray = array(1,2,3,4);

foo($myarray);

ouputs:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

cheers,

Robby

--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robbyplanetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
****************************************/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQBBd8ci0QaQZBaqXgwRAsxmAKC8GTrF5dXw/0de1Vtq6fNrNoVKDACgjLQm
BD+g88IGaBJW+zAP+lGaZMo=
=rbjx
-----END PGP SIGNATURE-----

attached mail follows:


Thanks.... I wasn't sure if that would work but now I know it does. It is
nice to know..

Scott

attached mail follows:


Here's a one liner that gives the minutes since midnight:
floor( (time()-mktime(0,0,0, date( 'm' ), date( 'd' ), date( 'Y'
)))/60);

Both time() and mktime() return the seconds since epoch. Time is based
on current time, and the mktime parameters base it on midnight. A
simple subtraction gives you the seconds since midnight. Divide by 60
to get minutes and use floor() to drop any extra "seconds".

On Oct 20, 2004, at 6:45 PM, bclemimaginative-enterprises.com wrote:

> I need to find the exact time of day using "minutes since midnight".
>
> What is the easiest and/or better way to do this in php?
>
> This is how I'm doing it now.
>
> // $iMinutes is the total number of minutes since midnight/12am
> // 0 = midnight/12am
> // 1439 = 11:59pm
>
> $iMinutes = 1230;
>
> if ($iMinutes < 0 || $iMinutes > 1439) {
> $restime = "??:??";
> } else {
> $iHour = $iMinutes / 60;
> $iMins = ($iMinutes - (60*$iHour)) % 60;
>
> if ($iHour <= 12) {
> $restime .= $iHour . ":";
> } else {
> $restime .= $iHour-12 . ":";
> }
>
> if ($iMins < 10) {
> $restime .= "0" . $iMins;
> } else {
> $restime .= $iMins;
> }
> if ($iHour < 12) {
> $restime .= " a.m.";
> } else if ($iHour==12 && $iMins==0) {
> $restime .= " noon";
> } else {
> $restime .= " pm";
> }
> }
>
>
> Thanks, Brent
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

attached mail follows:


Probably a stupid question, but hopefully has a simple answer. Is there a
way to get Grenwich Mean time? time() and date() functions that I can see
only seem to get date/time from the server, which knowing where that is,
could easily figure out GM time, but.... would rather go the other way.

Thanks.

Ben

attached mail follows:


[snip]
Probably a stupid question, but hopefully has a simple answer. Is there
a way to get Grenwich Mean time? time() and date() functions that I can
see only seem to get date/time from the server, which knowing where that
is, could easily figure out GM time, but.... would rather go the other
way.
[/snip]

You might want to take a look at gmmaketime
http://www.php.net/gmmaketime
HTH!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

attached mail follows:


Set your server to GMT.

----- Original Message -----
From: Ben Miller <benipmillercomcast.net>
Date: Thursday, October 21, 2004 10:48 am
Subject: [PHP] Simple Time Question

> Probably a stupid question, but hopefully has a simple answer. Is
> there a
> way to get Grenwich Mean time? time() and date() functions that I
> can see
> only seem to get date/time from the server, which knowing where
> that is,
> could easily figure out GM time, but.... would rather go the other
> way.
> Thanks.
>
> Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


You might want to look at this:
http://www.php.net/manual/en/function.date.php

On Thu, 21 Oct 2004 08:48:54 -0600, Ben Miller <benipmillercomcast.net> wrote:
> Probably a stupid question, but hopefully has a simple answer. Is there a
> way to get Grenwich Mean time? time() and date() functions that I can see
> only seem to get date/time from the server, which knowing where that is,
> could easily figure out GM time, but.... would rather go the other way.
>
> Thanks.
>
> Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
M.Saleh.E.G
97150-4779817

attached mail follows:


On Thu, 2004-10-21 at 08:48 -0600, Ben Miller wrote:
> Probably a stupid question, but hopefully has a simple answer. Is there a
> way to get Grenwich Mean time? time() and date() functions that I can see
> only seem to get date/time from the server, which knowing where that is,
> could easily figure out GM time, but.... would rather go the other way.
>
> Thanks.
>
> Ben
>

You can set an environment variable for your project like so:

putenv("TZ=US/Pacific");

just find the proper GMT time zone format..

-Robby

--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robbyplanetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
****************************************/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQBBd9db0QaQZBaqXgwRAsjyAKCtWt6B512rTTsPGHpyU4+sssnlMQCgyIEB
LeL4gH+/enP2uuuH7sOORvY=
=2G48
-----END PGP SIGNATURE-----

attached mail follows:


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

On 21 October 2004 15:49, Ben Miller wrote:

> Probably a stupid question, but hopefully has a simple answer. Is
> there a way to get Grenwich Mean time? time() and date() functions
> that I can see only seem to get date/time from the server, which
> knowing where that is, could easily figure out GM time, but.... would
> rather go the other way.

time() returns a UNIX timestamp which, by definition, is always in GMT.

date() formats that, converting for the current timezone.

gmdate() formats it without doing any timezone conversion, hence in GMT.

mktime() makes a timestamp (hence in GMT) from the supplied date/time
information, converting from the current timezone.

gmmktime() does the same, but without any timezone conversion, so the
information you supply must be in GMT.

In summary:

* timestamps are always in GMT.

* date() and mktime() do timezone conversion.

* gmdate() and gmmktime() do not.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.fordleedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

attached mail follows:


On Thu, 2004-10-21 at 12:25, Ford, Mike wrote:
> To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
>
>
>
> On 21 October 2004 15:49, Ben Miller wrote:
>
> > Probably a stupid question, but hopefully has a simple answer. Is
> > there a way to get Grenwich Mean time? time() and date() functions
> > that I can see only seem to get date/time from the server, which
> > knowing where that is, could easily figure out GM time, but.... would
> > rather go the other way.
>
> time() returns a UNIX timestamp which, by definition, is always in GMT.

No it isn't. It goes by your machine's clock.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


On Thu, 2004-10-21 at 13:00, Robert Cummings wrote:
> On Thu, 2004-10-21 at 12:25, Ford, Mike wrote:
> > To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
> >
> >
> >
> > On 21 October 2004 15:49, Ben Miller wrote:
> >
> > > Probably a stupid question, but hopefully has a simple answer. Is
> > > there a way to get Grenwich Mean time? time() and date() functions
> > > that I can see only seem to get date/time from the server, which
> > > knowing where that is, could easily figure out GM time, but.... would
> > > rather go the other way.
> >
> > time() returns a UNIX timestamp which, by definition, is always in GMT.
>
> No it isn't. It goes by your machine's clock.

Hmm I could be wrong. Seems the date function adds the timezone modifier
according to the comments on php.net for the time() function.

Apologies,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

On 21 October 2004 18:01, Robert Cummings wrote:

> On Thu, 2004-10-21 at 12:25, Ford, Mike wrote:
> > To view the terms under which this email is distributed,
> please go to http://disclaimer.leedsmet.ac.uk/email.htm
> >
> >
> >
>