php-general Digest 1 Jun 2003 12:45:55 -0000 Issue 2091
Topics (messages 149690 through 149725):
Re: Long screen display cut short.
149690 by: Floyd Baker
149696 by: Tim Burden
Re: PHP getting values from XML
149691 by: Jaap van Ganswijk
Re: regex problem
149692 by: Daniel J. Rychlik
trikky authentication question
149693 by: daniel.electroteque.org
149694 by: Volker Augustin
149695 by: daniel.electroteque.org
149697 by: John W. Holmes
149698 by: daniel.electroteque.org
149699 by: Volker Augustin
149700 by: daniel.electroteque.org
149701 by: John W. Holmes
149702 by: daniel.electroteque.org
149703 by: daniel.electroteque.org
149704 by: daniel.electroteque.org
149705 by: Volker Augustin
OOP question
149706 by: Jackson Miller
149713 by: Rasmus Lerdorf
149723 by: Ernest E Vogelsinger
149724 by: Ernest E Vogelsinger
mirror search is going to google !!!
149707 by: daniel.electroteque.org
149711 by: Rasmus Lerdorf
Add Up Prices in Array
149708 by: Ralph
149709 by: Rasmus Lerdorf
149714 by: Ralph
149717 by: Ralph
Re: connection_aborted was [PHP] trikky authentication question
149710 by: daniel.electroteque.org
149712 by: Rasmus Lerdorf
149720 by: daniel.electroteque.org
149722 by: Rasmus Lerdorf
mysql_connect() -- flags
149715 by: Armand Turpel
Re: Cookies and Sessions: What's the Best Recipe?
149716 by: Justin French
Shipping Rates
149718 by: Ralph
149719 by: Ralph
149721 by: Rasmus Lerdorf
Re: cheap PHP+SQL WebHosting
149725 by: Arcadius A.
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 ---
Yes, there are a bunch of arrays in the program.
This is on a DSL line... ?? Would the asynco thing be likely, or
possibly even standard, with DSL?
Did you come up with a workaround?
Floyd
On Sat, 31 May 2003 14:38:05 +0200, you wrote:
>On Fri, 30 May 2003 20:45:08 -0400 [EMAIL PROTECTED] (Floyd Baker) wrote:
>--------------------[snip]--------------------
>> I have a routine that works fine on local win98 but when it runs on
>> linux online, the screen output is cut short. I have lengthened the
>> 30 second script time max to 45 but that made no difference at all.
>>
>> Depending on the particulars, the routine stops at a certain spot. If
>> it is rerun, it stops at the very same spot again. Putting in other
>> particulars cause it to stop at a different point, further down. It
>> seems that changes which affect the number of mysql calculations, make
>> some difference in the length of the screen display, but it's only a
>> minor amount. It cuts off somewhere around 4 pages.
>--------------------[snip]--------------------
>
>I once had this effect on pages exceeding a total size of 8k when running a
>test server on an asynchronoous line (ADSL, in 712kB, out 64kB). As long as
>the page fits into a single IP packet (which usually equals 8kB) no
>problems occur, however if more than one packet is needed to transmit the
>page the webserver will only be able to send the first packet. All pages
>went fine when using a synchronous connection (in == out).
>
>
>--
> >O Ernest E. Vogelsinger
> (\) ICQ #13394035
> ^ http://www.vogelsinger.at/
--
--- End Message ---
--- Begin Message ---
I had same problem and it involved an array. In my case there was a typo,
and the array I was trying to do something with didn't even exist, but it
was hard to find because instead of dying with an error it would just sort
of sit there, not outputting anything further, until I clicked stop in the
browser.
Can't remember more details.
Haven't had problem since, we upgrade with releases.
----- Original Message -----
From: "Floyd Baker" <[EMAIL PROTECTED]>
Newsgroups: php.general
To: "Thomas Seifert" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, May 31, 2003 8:42 PM
Subject: Re: [PHP] Re: Long screen display cut short.
> On Sat, 31 May 2003 13:18:13 +0000, you wrote:
>
> >what is the online-version?
> >I mean which webserver-software in which version?
> >
> >
> >Thomas
>
> Linux RH 7.3
> Apache 1.3.24
> mySql 3.23.55
> PHP 4.2.0
>
> Also, this is an httpS connection if it makes a difference in some
> way.
>
> Floyd
>
>
>
>
>
> >On Fri, 30 May 2003 20:45:08 -0400 [EMAIL PROTECTED] (Floyd Baker) wrote:
> >
> >>
> >> Hello...
> >>
> >> I have a routine that works fine on local win98 but when it runs on
> >> linux online, the screen output is cut short. I have lengthened the
> >> 30 second script time max to 45 but that made no difference at all.
> >>
> >> Depending on the particulars, the routine stops at a certain spot. If
> >> it is rerun, it stops at the very same spot again. Putting in other
> >> particulars cause it to stop at a different point, further down. It
> >> seems that changes which affect the number of mysql calculations, make
> >> some difference in the length of the screen display, but it's only a
> >> minor amount. It cuts off somewhere around 4 pages.
> >>
> >> Any ideas please.
> >>
> >> Floyd
> >>
> >> --
>
> --
--- End Message ---
--- Begin Message ---
Hi,
At 2003-05-31 14:52 -0400, [EMAIL PROTECTED] wrote:
>I'm developing a site PHP site.
>
>I would like to define HTML code in XML and be able to get the HTML code using PHP.
>
>I was hoping for a simple example.
>
>I will not be able to update the version of PHP with any "modules" as my hosting
>company (hostway.com) admins the PHP environment.
I wrote a very compact stand-alone XML interpreter
for the Amazon.com XML webservices interface:
http://www.chipdir.nl/amazon/
The part that interprets the XML code is
only about 30 lines long. Please consider
that I can't guarantee that it's useable
as a general XML-interpreter, because it
was written with the quite neat Amazon
code in mind.
The code may also not be useable for big
source files. Furthermore the code reads
the XML code in such a way that the resulting
array stays as shallow as possible. To this
end certain information is not stored in the
array, and therefore it's not possible
to regenerate the XML code from the array
again.
I have also been busy expanding the script
code into a similar HTML interpreter (which
is much harder of course) but that means
that I don't have a very clear picture in
my head about what the quality of the XML
interpreter currently is. I think I have
found some serious improvements while
working on the HTML version.
One of the problems I encountered whilst trying
to keep the resulting tree shallow was, that
when you interpret something like:
<a>
<a>_data_
<b>_data_
<c>_data_
(I'm leaving out the end-tags.)
You can't put the a,b,c in an associative array,
with a,b,c as index, because every index should
be unique and the sequence might as well be:
<a>
<a>_data_
<b>_data_
<b>...
<c>
This means that you have to put the elements in
an enumerated array.
But in the case of say:
<author>
<name> _data_
<street> _data_
<city> _data_
One really would prefer to put them in an associative
array.
Of course one could check first if all the fields
are unique and decide then, but this might lead
to the fact that XML code like:
<authors>
<author>_data_
<author>_data_
<authors>
<author>_data_
leads to arrays of different depth.
I haven't checked yet if interpreting the DTD
could help to resolve this issue.
Greetings,
Jaap
--- End Message ---
--- Begin Message ---
If I wanted to remove <script></script> tags from my form as well as <html>
tags, would I use a preg_match function or is their another simple funtion
that does this ?
-Dan
----- Original Message -----
From: "Jim Lucas" <[EMAIL PROTECTED]>
To: "Daniel J. Rychlik" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Saturday, May 31, 2003 6:04 PM
Subject: Re: [PHP] regex problem
> Are you wanting the $_POST['nums1'] to have only numbers, -, ., #, : ????
>
> Is this what you are trying to match. if so, try this.
>
> if ( preg_match("/[^0-9\#\:\.\-]/", $_POST['nums1']) ) {
> throw error()
> }
>
> This will match anything that is not a number or one of the other special
> chars that are in the pattern to be matched.
>
> Therefor, if it does find anything that is not in the pattern to be
matched
> it will return true and then it will enter the if statement instead of
> skipping over it.
>
> Jim Lucas
> ----- Original Message -----
> From: "Daniel J. Rychlik" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, May 31, 2003 11:46 AM
> Subject: [PHP] regex problem
>
>
> Hello,,
>
> I have a preg_match issue matching numbers. I am currently using
>
> !preg_match ('/([0-9\-\.\#:])/', $_POST['nums1']
> throw error[]
>
> This fails if you use something like ' asdf ' but if you use ' asdf789 '
it
> passes false and does not throw an error.
> This is not the obvious solution.... I know its a problem in my regular
> expression. Should I ONLY be using
>
> ' /([0-9])/ ' , ?
>
> Thanks in advance.
> Daniel
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
hi guys i have an authentication class , there is one last big issue to
fix , i am trying to prevent multiple logins , it does this ok except , the
first login gets kicked instead of the second one , i have a last_login
date entry to work with , what else should i have so on the login check if
the user is logged in , there is an issue using the logged in feature , ok
u give it an interval of say 2 hours , this may prevent that person
reloggin in for two hours right ?? :| , or say its a few minutes , i can
log bak in after a few minutes and still kick the first login, what are my
options
--- End Message ---
--- Begin Message ---
hi,
this is only a very fast response :))
is solved this kind of problem like that:
(quick solution for a chatboard - user cannot login for xxxxx seconds -
maxidletime)
/***********two functions:******************/
function logoutMsgBoardUser($UserName)
global $MessageBoardTable,$SiteID;
$DB=new connectDB();
$actDate= date("Y-m-d H:i:s");
$newMessage=addslashes($UserName)." logged out.";
$host="System";
$Query="update ".$MessageBoardTable."
set logged_out='1' where
name='".addslashes($UserName)."'
and site_id='".$SiteID."'
and logged_out!='1'
";
$DB->Query($Query);
$Query="insert into ".$MessageBoardTable."
(site_id,name,msg,created,host,archiv,aktiv,logged_out)
values
'".$SiteID."',
'',
'".$newMessage."',
'".$actDate."',
'".$host."',
'0',
'1',
'1'
)";
$DB->Query($Query);
}
function getMsgBoardUserIdleTime($UserName)
global $MessageBoardTable,$SiteID;
$DB=new ConnectDB();
$Query="select created from ".$MessageBoardTable." where
site_id='".$SiteID."' and logged_out='0' and
name='".addslashes($UserName)."' and aktiv='1' order by id desc limit 1";
$DB->Query($Query);
if ($DB->next_record())
$lastUserPost=$DB->Record['created'];
$actDate= date("Y-m-d H:i:s");
$Result=strtotime(date ($actDate))-strtotime($lastUserPost);
} else
$Result=0;
}
return $Result;
}
/***************and the code... i think thats all**************/
if ($msglogin=='1') {
$newMessage=" <b>entered the Messageboard</b>";
if (getMsgBoardUserIdleTime($MName) >0) {
echo "Eine User mit diesem Namen ist bereits Online, bitte waehle einen
anderen...";
$logged_out=true;
$MName="";
}
}
if (isset($MName) && $MName!="") {
$MyIdleTime=getMsgBoardUserIdleTime($MName);
if ($MyIdleTime > $MaxIdleTime) {
logoutMsgBoardUser($MName);
$logged_out=true;
$MName="";
echo " logged out by system after ".$MyIdleTime." seconds without saying
anything ;)";
}
}
volker
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 01, 2003 4:11 AM
Subject: [PHP] trikky authentication question
> hi guys i have an authentication class , there is one last big issue to
> fix , i am trying to prevent multiple logins , it does this ok except ,
the
> first login gets kicked instead of the second one , i have a last_login
> date entry to work with , what else should i have so on the login check if
> the user is logged in , there is an issue using the logged in feature , ok
> u give it an interval of say 2 hours , this may prevent that person
> reloggin in for two hours right ?? :| , or say its a few minutes , i can
> log bak in after a few minutes and still kick the first login, what are my
> options
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
doh silly me , i'll have to set a logged out flag , will help me in the
long run :D thanks dude
> hi,
> this is only a very fast response :))
> is solved this kind of problem like that:
> (quick solution for a chatboard - user cannot login for xxxxx seconds -
> maxidletime)
> /***********two functions:******************/
>
> function logoutMsgBoardUser($UserName)
>
> global $MessageBoardTable,$SiteID;
> $DB=new connectDB();
> $actDate= date("Y-m-d H:i:s");
> $newMessage=addslashes($UserName)." logged out.";
> $host="System";
> $Query="update ".$MessageBoardTable."
> set logged_out='1' where
> name='".addslashes($UserName)."'
> and site_id='".$SiteID."'
> and logged_out!='1'
> ";
> $DB->Query($Query);
> $Query="insert into ".$MessageBoardTable."
> (site_id,name,msg,created,host,archiv,aktiv,logged_out)
> values
>
> '".$SiteID."',
> '',
> '".$newMessage."',
> '".$actDate."',
> '".$host."',
> '0',
> '1',
> '1'
> )";
> $DB->Query($Query);
> }
>
> function getMsgBoardUserIdleTime($UserName)
>
> global $MessageBoardTable,$SiteID;
> $DB=new ConnectDB();
> $Query="select created from ".$MessageBoardTable." where
> site_id='".$SiteID."' and logged_out='0' and
> name='".addslashes($UserName)."' and aktiv='1' order by id desc limit
> 1";
> $DB->Query($Query);
> if ($DB->next_record())
>
> $lastUserPost=$DB->Record['created'];
> $actDate= date("Y-m-d H:i:s");
> $Result=strtotime(date ($actDate))-strtotime($lastUserPost);
> } else
>
> $Result=0;
> }
> return $Result;
> }
> /***************and the code... i think thats all**************/
> if ($msglogin=='1') {
> $newMessage=" <b>entered the Messageboard</b>";
> if (getMsgBoardUserIdleTime($MName) >0) {
> echo "Eine User mit diesem Namen ist bereits Online, bitte waehle
> einen
> anderen...";
> $logged_out=true;
> $MName="";
> }
> }
>
> if (isset($MName) && $MName!="") {
> $MyIdleTime=getMsgBoardUserIdleTime($MName);
> if ($MyIdleTime > $MaxIdleTime) {
> logoutMsgBoardUser($MName);
> $logged_out=true;
> $MName="";
> echo " logged out by system after ".$MyIdleTime." seconds without
> saying
> anything ;)";
> }
> }
>
> volker
>
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Sunday, June 01, 2003 4:11 AM
> Subject: [PHP] trikky authentication question
>
>
>> hi guys i have an authentication class , there is one last big issue
>> to fix , i am trying to prevent multiple logins , it does this ok
>> except ,
> the
>> first login gets kicked instead of the second one , i have a
>> last_login date entry to work with , what else should i have so on the
>> login check if the user is logged in , there is an issue using the
>> logged in feature , ok u give it an interval of say 2 hours , this may
>> prevent that person reloggin in for two hours right ?? :| , or say its
>> a few minutes , i can log bak in after a few minutes and still kick
>> the first login, what are my options
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> hi guys i have an authentication class , there is one last big issue
to
> fix , i am trying to prevent multiple logins , it does this ok except
,
> the
> first login gets kicked instead of the second one , i have a
last_login
> date entry to work with , what else should i have so on the login
check if
> the user is logged in , there is an issue using the logged in feature
, ok
> u give it an interval of say 2 hours , this may prevent that person
> reloggin in for two hours right ?? :| , or say its a few minutes , i
can
> log bak in after a few minutes and still kick the first login, what
are my
> options
I generally keep it like this, so that the first user is logged out.
This way the user is alerted that someone has "hijacked" their account
and they can act upon it.
If you do it another way so that the first person remains logged on and
the second user is denied access, you'll just need some extra flags in
the database. Set a "logged_on" column when the user logs on and if
another user tries to use the same name and the "logged_on" column is
set, deny them. The issue you'll run into with this though, is how do
you know someone is logged off? Sure, some people may use the log off
button, but others will not. So you have to come up with a "timeout"
script. What if I accidentally close my browser and come back to log in?
The system will not let me because I'm still "logged_in" until X minutes
pass. Also with this method, you need to keep track of these attempted
log ins and somehow alert the first user.
Hope that helps.
---John W. Holmes...
Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
--- End Message ---
--- Begin Message ---
What if I accidentally close my browser and come back to log
> in? The system will not let me because I'm still "logged_in" until X
> minutes pass. Also with this method, you need to keep track of these
> attempted log ins and somehow alert the first user.
good question i'm checking this out atm :|
--- End Message ---
--- Begin Message ---
hmmm,
for me these few line are working well, user cannot login before
max-idletime is reached.... (i check the list every time an action is taken
on the board, if no user is online, i cant login forever and have to connect
as another user first ;)
thats all, you could check idletime for all users at the login window and
log them out if reached - before logging in ....
volker
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Sunday, June 01, 2003 5:06 AM
Subject: RE: [PHP] trikky authentication question
> What if I accidentally close my browser and come back to log
> > in? The system will not let me because I'm still "logged_in" until X
> > minutes pass. Also with this method, you need to keep track of these
> > attempted log ins and somehow alert the first user.
>
> good question i'm checking this out atm :|
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
so wot do i check upon , (NOW() - last_login) > max_idletime ? what do i do
with the other check for logged_in=0 ?
> hmmm,
> for me these few line are working well, user cannot login before
> max-idletime is reached.... (i check the list every time an action is
> taken on the board, if no user is online, i cant login forever and have
> to connect as another user first ;)
> thats all, you could check idletime for all users at the login window
> and log them out if reached - before logging in ....
> volker
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Sunday, June 01, 2003 5:06 AM
> Subject: RE: [PHP] trikky authentication question
>
>
>> What if I accidentally close my browser and come back to log
>> > in? The system will not let me because I'm still "logged_in" until X
>> > minutes pass. Also with this method, you need to keep track of these
>> > attempted log ins and somehow alert the first user.
>>
>> good question i'm checking this out atm :|
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
> for me these few line are working well, user cannot login before
> max-idletime is reached.... (i check the list every time an action is
> taken
> on the board, if no user is online, i cant login forever and have to
> connect
> as another user first ;)
And you call that a viable solution? That's ridiculous.
---John W. Holmes...
Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
--- End Message ---
--- Begin Message ---
wots the best solution then ??
"SELECT username FROM users WHERE logged_in=0 AND username='".$this->post
['username']."'"
thats my current one but yes i get blocked out , what else can i add to it ?
>
> And you call that a viable solution? That's ridiculous.
>
--- End Message ---
--- Begin Message ---
ok here is the latest sql query
SELECT username FROM users WHERE (logged_in=0 OR (NOW()-last_login) > 300
AND username='".$this->post['username']."'"
there is the idle time added but what after the idle time they log bak in
and then kiks the first login out ? there must be a better solution ??
>
> And you call that a viable solution? That's ridiculous.
>
> ---John W. Holmes...
--- End Message ---
--- Begin Message ---
ok well i just noticed my sql statement is a bit flakey as its not a true
idle time to get a true idle i'd have to keep a record of the time every
request to the pages when logged in, this is checking when they lasted
logged in so the user may still be logged in 300 seconds later , this isnt
really idle especially when the users will be fulltext searching a table of
100K + records :|, any suggestions ?
>> for me these few line are working well, user cannot login before
>> max-idletime is reached.... (i check the list every time an action is
>> taken
>> on the board, if no user is online, i cant login forever and have to
>> connect
>> as another user first ;)
>
> And you call that a viable solution? That's ridiculous.
>
> ---John W. Holmes...
>
> Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E
>
> PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> today. http://www.phparch.com/
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
i said that before!
just a hint to think off....any questions?
volker
> ----- Original Message -----
> From: "John W. Holmes" <[EMAIL PROTECTED]>
> To: "'Volker Augustin'" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Sunday, June 01, 2003 5:48 AM
> Subject: RE: [PHP] trikky authentication question
>
>
> > > for me these few line are working well, user cannot login before
> > > max-idletime is reached.... (i check the list every time an action is
> > > taken
> > > on the board, if no user is online, i cant login forever and have to
> > > connect
> > > as another user first ;)
> >
> > And you call that a viable solution? That's ridiculous.
> >
> > ---John W. Holmes...
> >
> > Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E
> >
> > PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> > today. http://www.phparch.com/
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
--- End Message ---
--- Begin Message ---
Is it possible to reference two instances of an object at once with a
single variable name while retaining the ability to reference the
objects seperately?
I am using the PEAR Template IT package and need to generate two similar
but different results at the same time. I am doing this with two
instances of the IT class ($tpl1 and $tpl2).
I have some code like this:
$tpl1->setVariable("var1","This");
$tpl2->setVariable("var1","This");
$tpl1->setVariable("var2","That");
$tpl2->setVariable("var2","That");
$tpl1->setVariable("var3","Something");
$tpl2->setVariable("var3","SomethingElse");
I would like for this to be:
$tpl3->setVariable("var1","This");
$tpl3->setVariable("var2","That");
$tpl1->setVariable("var3","Something");
$tpl2->setVariable("var3","SomethingElse");
Where $tpl3 is a reference to both $tpl1 and $tpl2.
Is this possible at all? It seems to make for very clean code for me,
but I can't think of how it could be possible.
Thanks in advance.
-Jackson
--- End Message ---
--- Begin Message ---
On Sat, 1 Jun 2003, Jackson Miller wrote:
> Is it possible to reference two instances of an object at once with a
> single variable name while retaining the ability to reference the
> objects seperately?
No chance. Well, you could hack it with some really fancy object
overloading, but in general, no, you cannot have a single reference that
references two distinct objects. References work the other way around.
Given a single distinct object, you can create multiple equivalent
references to it.
-Rasmus
--- End Message ---
--- Begin Message ---
At 08:39 01.06.2003, Jackson Miller said:
--------------------[snip]--------------------
>Is it possible to reference two instances of an object at once with a
>single variable name while retaining the ability to reference the
>objects seperately?
--------------------[snip]--------------------
Not using references.
I once built a small class that handles such stuff. Basically it's a
container for object references that are attached to it, and it will
execute any method to all objects simultaneously. Code plus testbed is
attached below.
The base implementation of CTeeObject checks if that all attached objects
are of the same class of the first attached object, or at least derived
from it. This is how I needed it but it's not mandatory, as the call agent
method or CTeeObject checks each attached object if the method exists. Upon
attaching objects, CTeeObject calls its check_object() method if the object
is ok to attach - you may override this method in a derived class to
perform less or additional checks.
For example you could provide a specialized CTeeObject-derived class that
doesn't use the generic call agent (for performance reasons) but calls
object methods directly (which would be quite feasible in your case). Use
the overridable check_object() to check if the object to attach has a
supported class.
<?php
class CTeeObject {
var $arObj;
var $class;
function CTeeObject() {
// we do nothing in the constructor class
// use the attach() method
$this->arObj = array();
}
function attach(&$hObj) {
// if this is the first object, simply accept it.
// for all successive objects make sure they have
// the same class (or at least derived from).
if (!count($this->arObj)) {
if (is_object($hObj)) {
$this->arObj[] =& $hObj;
$this->class = get_class($hObj);
}
}
else {
if (!$this->check_object($hObj))
return false;
$this->arObj[] =& $hObj;
}
return true;
}
// override this method in your derived class
// for additional class checks
function check_object(&$hObj)
{
return is_a($hObj, $this->class);
}
// generic call agent
function call_method($method)
{
// accessing unlisted arguments will trigger a notice/warning
// this is unavoidable here so modify error reporting
$erep = error_reporting(E_ERROR);
// build a list of arguments to pass
$arglist = array();
for ($i = 1; $i < func_num_args(); ++$i)
$arglist[] = func_get_arg($i);
// build the method call
$cmd = null;
for ($i = 0; $i < count($arglist); ++$i)
$cmd .= ($cmd ? ',' : null) . "\$arglist[$i]";
$cmd = "return \$hObj->$method($cmd);";
// error reporting to standard
// to have it available in the object implementation
error_reporting($erep);
// now walk all attached objects and execute the required
method
// but check if the object is still an object and that the
method exists
$result = array();
for ($i = 0; $i < count($this->arObj); ++$i) {
$hObj =& $this->arObj[$i];
if (is_object($hObj) && method_exists($hObj, $method))
$result[] = eval($cmd);
else
$result[] = null;
}
return $result;
}
}
////////////////////////////////////////////////////////
// Test Bed
class CBaseTest {
var $id;
function CBaseTest($id)
{
$this->id = $id;
}
function hello($hellostring)
{
echo sprintf('Hello from %s (%s): "%s"<br />',
get_class($this), $this->id, $hellostring);
return $this->id;
}
}
class CExtendedTest extends CBaseTest {
function say($what, $second)
{
echo sprintf('SayWhat from %s (%s): "%s" - %d<br />',
get_class($this), $this->id, $what, $second);
return $this->id;
}
}
$tee = new CTeeObject;
$tee->attach(new CBaseTest(1));
$tee->attach(new CExtendedTest(1));
$tee->attach(new CBaseTest(2));
$tee->attach(new CExtendedTest(2));
$tee->attach(new CBaseTest(3));
$tee->attach(new CExtendedTest(3));
$tee->attach(new CBaseTest(4));
$tee->attach(new CExtendedTest(4));
echo '<pre>'; $res_hello = $tee->call_method('hello', 'Called hello() (both
base and extended)');
echo '<hr>'; $res_say = $tee->call_method('say', 'Called say() (only
extended)', 4711);
echo '<hr>';
echo 'Hello results: '; print_r($res_hello);
echo 'Say results: '; print_r($res_say);
?>
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--- End Message ---
--- Begin Message ---
Just noticed a small glitch in the attach() method - check_object will not
be called for the first object. Use this attach() / check_object()
implementation instead. The "var $class" instance variable of CTeeObject
can be omitted.
function attach(&$hObj) {
if (!$this->check_object($hObj))
return false;
$this->arObj[] =& $hObj;
return true;
}
// override this method in your derived class
// for additional class checks
function check_object(&$hObj)
{
// if this is the first object, simply accept it.
// for all successive objects make sure they have
// the same class (or at least derived from).
if (is_object($hObj))
return (!count($this->arObj) || is_a($hObj,
get_class($this->arObj[0])));
return false;
}
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--- End Message ---
--- Begin Message ---
the idiot mirror search is going to google instead and not giving me results
http://www.google.com/search?q=manual%2Fen%2Ffunction.connection-
aborted.php+site:www.php.net&l=en
--- End Message ---
--- Begin Message ---
We are reworking our local search code. It was killing the server.
Pointed it at Google temporarily.
-Rasmus
On Sun, 1 Jun 2003 [EMAIL PROTECTED] wrote:
> the idiot mirror search is going to google instead and not giving me results
>
> http://www.google.com/search?q=manual%2Fen%2Ffunction.connection-
> aborted.php+site:www.php.net&l=en
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
I'm querying prices off a database then storing these in an array, I
want to add these up to get the grand total, how would I go about adding
up all the prices stored in the array?
Thanks in advance.
--- End Message ---
--- Begin Message ---
If they are coming out of your database, why not get your database to do
it for you by calling SUM() in your query?
On Sun, 1 Jun 2003, Ralph wrote:
> I'm querying prices off a database then storing these in an array, I
> want to add these up to get the grand total, how would I go about adding
> up all the prices stored in the array?
>
> Thanks in advance.
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Right... I never thought of this.
But can I use this if what I'm trying to get the (price * quantity).
-----Original Message-----
From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 01, 2003 12:43 AM
To: Ralph
Cc: PHP General Mailing List
Subject: Re: [PHP] Add Up Prices in Array
If they are coming out of your database, why not get your database to do
it for you by calling SUM() in your query?
On Sun, 1 Jun 2003, Ralph wrote:
> I'm querying prices off a database then storing these in an array, I
> want to add these up to get the grand total, how would I go about
adding
> up all the prices stored in the array?
>
> Thanks in advance.
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Disregard my last post, I went with what you suggested and I got it to
work.
Thanks again.
-----Original Message-----
From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 01, 2003 12:43 AM
To: Ralph
Cc: PHP General Mailing List
Subject: Re: [PHP] Add Up Prices in Array
If they are coming out of your database, why not get your database to do
it for you by calling SUM() in your query?
On Sun, 1 Jun 2003, Ralph wrote:
--- End Message ---
--- Begin Message ---
how can i get this to work ??
if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
WHERE userID=$this->userID");
> ok well i just noticed my sql statement is a bit flakey as its not a
> true idle time to get a true idle i'd have to keep a record of the time
> every request to the pages when logged in, this is checking when they
> lasted logged in so the user may still be logged in 300 seconds later
> , this isnt really idle especially when the users will be fulltext
> searching a table of 100K + records :|, any suggestions ?
>
>>> for me these few line are working well, user cannot login before
>>> max-idletime is reached.... (i check the list every time an action is
>>> taken
>>> on the board, if no user is online, i cant login forever and have to
>>> connect
>>> as another user first ;)
>>
>> And you call that a viable solution? That's ridiculous.
>>
>> ---John W. Holmes...
>>
>> Amazon Wishlist: http://www.amazon.com/o/registry/3BEXC84AB3A5E
>>
>> PHP Architect - A monthly magazine for PHP Professionals. Get your
>> copy today. http://www.phparch.com/
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Sun, 1 Jun 2003 [EMAIL PROTECTED] wrote:
> how can i get this to work ??
>
> if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
> WHERE userID=$this->userID");
Did you read the connection handling chapter in the manual?
http://www.php.net/manual/en/features.connection-handling.php
-Rasmus
--- End Message ---
--- Begin Message ---
of course thats where i got the example from but it doesnt work
ignore_user_abort(true);
if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
WHERE userID=$this->userID");
if i close the browser its not setting the fiel to 0 meaning they are logged
out
-----Original Message-----
From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 01, 2003 5:46 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] RE: connection_aborted was [PHP] trikky
authentication question
On Sun, 1 Jun 2003 [EMAIL PROTECTED] wrote:
> how can i get this to work ??
>
> if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
> WHERE userID=$this->userID");
Did you read the connection handling chapter in the manual?
http://www.php.net/manual/en/features.connection-handling.php
-Rasmus
--- End Message ---
--- Begin Message ---
?? Are you reading that chapter at all? Closing the browser has
absolutely nothing to do with aborted connections unless the browser is
closed while data is actually flowing across the wire. You are completely
on the wrong track here. HTTP is a simple stateless protocol. Sessions
can be used to emulate state, but that doesn't mean you suddenly have a
stateful connection-oriented protocol. Between clicks of your browser you
do not have an active connection from the browser to the web server (with
the minor exception of keep-alive connections, but they aren't what you
think anyway, so ignore those). Since you don't have an active
connection, closing your browser could not possible abort a connection.
-Rasmus
On Sun, 1 Jun 2003, electroteque wrote:
> of course thats where i got the example from but it doesnt work
>
> ignore_user_abort(true);
> if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
> WHERE userID=$this->userID");
>
> if i close the browser its not setting the fiel to 0 meaning they are logged
> out
> -----Original Message-----
> From: Rasmus Lerdorf [mailto:[EMAIL PROTECTED]
> Sent: Sunday, June 01, 2003 5:46 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] RE: connection_aborted was [PHP] trikky
> authentication question
>
>
> On Sun, 1 Jun 2003 [EMAIL PROTECTED] wrote:
> > how can i get this to work ??
> >
> > if (connection_aborted()) $this->db->query("UPDATE users SET logged_in=0
> > WHERE userID=$this->userID");
>
> Did you read the connection handling chapter in the manual?
>
> http://www.php.net/manual/en/features.connection-handling.php
>
> -Rasmus
>
--- End Message ---
--- Begin Message ---
Hi,
Is there any body who have experience with the flags in mysql_connect() in
php >= 4.3 . Especially the MYSQL_CLIENT_COMPRESS flag.
I dont know if it works or not. I cant make any difference. Should php must
be compiled with a special flag to get work this?
Thanks
Armand
--- End Message ---
--- Begin Message ---
on 01/06/03 6:01 AM, Monty ([EMAIL PROTECTED]) wrote:
> I have a member site that uses sessions. People who have their browser
> cookies turned off, however, cannot use our site. I read somewhere that to
> avoid this, I'd have to manually append the PHPSESSID var to every URL when
> redirecting in a script.
Actually, the session ID has to appear in every URL... if you compile PHP
with enable-trans-sid, then PHP takes care of this for you in *most* cases.
As you say above, you need to append them manually to things like header()
redirects.
One way around this would be to write a simple wrapper function which does
this for you automatically:
<?
// UNTESTED
function redirectWithSession($location)
{
$sid = session_id();
$sname = session_name();
header("Location: {$location}?{$sname}={$sid}");
}
?>
Then (after testing the above code thoroughly) you just need to do a batch
search and replace on your whole site source for 'header("Location: ' with
'redirectWithSession(', and everything should be cool.... I think. Please
test all thoroughly :)
Or, just go through your code and patch it up :)
> Is this really the best or only way to avoid this problem? Or, is it simply
> unavoidable? Right now, I tell users that the site will only work with
> browsers that have cookies turned on, but, I'd rather the site was
> accessible to all. However, I also don't like passing session IDs via the
> URL because of the security risk.
There is no difference in the security risk between URL and cookies, if they
are sent in plain text. SSL is a different story.
You have a choice: make sure your site can be used without cookies (and
deal with the small effort during development), or be prepared to turn away
users.
I know which I picked :)
Justin
--- End Message ---
--- Begin Message ---
Maybe it's just that it's late, but can't seem to figure this out. I
want to show a shipping price depending on the amount of purchase. I
thought about using a lot of if() statements, but I know this is not the
best way to go about this.
Can anybody enlighten me on this one and give me a better approach.
Here is an example of my shipping rates:
Less than $20.00 = $7.45
$20.01-$35.00 = $8.45
$35.01- $55.00 = $9.45
$55.01-$80.00 = $10.45
$80.01-$100.00 = $11.45
$100.01-$150.00 = $13.45
$150.01-$200.00 = $15.55
$200.01 or more = $19.45
Thanks.
--- End Message ---
--- Begin Message ---
I thought about this but how would I go about performing greater than or
equal to without having to specify a CASE for every price range?
-----Original Message-----
From: Jason Paschal [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 01, 2003 1:47 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Shipping Rates
this, maybe?
http://www.php.net/switch
>From: Ralph <[EMAIL PROTECTED]>
>To: PHP General Mailing List <[EMAIL PROTECTED]>
>Subject: [PHP] Shipping Rates
>Date: Sun, 01 Jun 2003 01:48:30 -0700
>
>Maybe it's just that it's late, but can't seem to figure this out. I
>want to show a shipping price depending on the amount of purchase. I
>thought about using a lot of if() statements, but I know this is not
the
>best way to go about this.
>
>Can anybody enlighten me on this one and give me a better approach.
>
>Here is an example of my shipping rates:
>
>Less than $20.00 = $7.45
>$20.01-$35.00 = $8.45
>$35.01- $55.00 = $9.45
>$55.01-$80.00 = $10.45
>$80.01-$100.00 = $11.45
>$100.01-$150.00 = $13.45
>$150.01-$200.00 = $15.55
>$200.01 or more = $19.45
>
>Thanks.
>
>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
--- End Message ---
--- Begin Message ---
Better approach in what sense? From a performance perspective you are not
going to beat a specific set of if conditions unless there is an distinct
formula you can apply. I will assume there is no simple mathematical
relationship for your full set of data and what you are really looking for
is a way to just feed the pricing structure into your code by some
mechanism and then have it just work, so your goal is to make it more
maintenable. To that end, you could stick your pricing table into an
array of arrays and simple loop through it. Something like this:
function find_rate($num) {
$rates = array(array('7.45'=>20),
array('8.45'=>35),
array('9.45'=>55),
array('10.45'=>80),
array('11.45'=>100),
array('13.45'=>150),
array('15.55'=>200),
array('19.45'=>999999999));
foreach($rates as $i => $vals) {
if($num > current($vals)) continue;
else { $price = key($vals); break; }
}
return $price;
}
This should return the correct shipping price for whatever you pass into
find_rate().
-Rasmus
On Sun, 1 Jun 2003, Ralph wrote:
> Maybe it's just that it's late, but can't seem to figure this out. I
> want to show a shipping price depending on the amount of purchase. I
> thought about using a lot of if() statements, but I know this is not the
> best way to go about this.
>
> Can anybody enlighten me on this one and give me a better approach.
>
> Here is an example of my shipping rates:
>
> Less than $20.00 = $7.45
> $20.01-$35.00 = $8.45
> $35.01- $55.00 = $9.45
> $55.01-$80.00 = $10.45
> $80.01-$100.00 = $11.45
> $100.01-$150.00 = $13.45
> $150.01-$200.00 = $15.55
> $200.01 or more = $19.45
>
> Thanks.
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Thanks!
Arcadius.
"Nabil" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> www.spiderhosts.com
>
> i'v been for so long with them, and the service is good
> Nabil
> www.cabms.org
> www.d2ue.com
>
>
> "Arcadius A." <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hello!
> > Please, do you know of any cheap PHP+SQL web hosting company?
> >
> > I know we always get what we pay for, but I really need somethingk
cheap.
> >
> > Thanks in advance.
> >
> > Arcadius.
> >
> >
>
>
--- End Message ---