Re: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Robert Cummings

Jim Lucas wrote:

Daevid Vincent wrote:

Anyone have a function that will return an integer of the number of
dimensions an array has?

I did some quick searches and came up with nothing. 
The closest was here of someone asking the same thing, but his solution

isn't right:
http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
http://php.net/manual/en/function.count.php

From a human standpoint, it's easy to see, "oh, this is a TWO
dimensional"...



How about this...  Using a slightly modified array that you posted, I came up
with this in about 10 minutes

I am working with the following data structure

 array(
0 => array('Flight Number', 'flight_number'),
1 => array(
0 => array('Timestamp Departure', 'timestamp_departure'),
1 => array('Timestamp Arrival', 'timestamp_arrival'),
  )
),
  1 => array('Departure City', 'departure_city'),
  2 => array('Arrival City', 'arrival_city'),
);

print_r($in);

echo "\n\n";

$max_depth = 0;
$cur_depth = 0;
function max_array_depth($ar) {
global $cur_depth, $max_depth;
if ( is_array($ar) ) {
$cur_depth++;
if ( $cur_depth > $max_depth ) {
$max_depth = $cur_depth;
}
foreach ( $ar AS $row ) {
max_array_depth($row);
}
$cur_depth--;
}
}

max_array_depth($in);

echo "Max depth of array is: {$max_depth}";

?>

http://www.cmsws.com/examples/php/testscripts/dae...@daevid.com/0002.php


Globals are dirty for this kind of recursive utility function. Here's a 
cleaner example:

 $maxDepth )
{
$maxDepth = $subDepth;
}
}

return 1 + $maxDepth;
}

?>

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Jim Lucas
Daevid Vincent wrote:
> Anyone have a function that will return an integer of the number of
> dimensions an array has?
> 
> I did some quick searches and came up with nothing. 
> The closest was here of someone asking the same thing, but his solution
> isn't right:
> http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
> http://php.net/manual/en/function.count.php
> 
> From a human standpoint, it's easy to see, "oh, this is a TWO
> dimensional"...
> 

How about this...  Using a slightly modified array that you posted, I came up
with this in about 10 minutes

I am working with the following data structure

 array(
0 => array('Flight Number', 'flight_number'),
1 => array(
0 => array('Timestamp Departure', 'timestamp_departure'),
1 => array('Timestamp Arrival', 'timestamp_arrival'),
  )
),
  1 => array('Departure City', 'departure_city'),
  2 => array('Arrival City', 'arrival_city'),
);

print_r($in);

echo "\n\n";

$max_depth = 0;
$cur_depth = 0;
function max_array_depth($ar) {
global $cur_depth, $max_depth;
if ( is_array($ar) ) {
$cur_depth++;
if ( $cur_depth > $max_depth ) {
$max_depth = $cur_depth;
}
foreach ( $ar AS $row ) {
max_array_depth($row);
}
$cur_depth--;
}
}

max_array_depth($in);

echo "Max depth of array is: {$max_depth}";

?>

http://www.cmsws.com/examples/php/testscripts/dae...@daevid.com/0002.php

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

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



RE: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 17:23 -0700, Daevid Vincent wrote:

> Oh. I know it's not a simple solution to do right Ashley. And exacerbated
> by the fact that each array dimension can have different dimensions as
> well. This is why I wanted someone else's solution first before I spend
> hours or days on one that works reliably. :)
> 
> 
>   _  
> 
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
> Sent: Monday, March 15, 2010 4:44 PM
> Subject: Re: [PHP] Need routine to tell me number of dimensions in array
> 
> The only way to do it reliably would be to iterate the entire array,
> element by element, as all the elements of an array might not necessarily
> be all of the array type or int's.
> 
> 


Best way I can think of is to iterate the entire thing and keep a count
as you do. I'm not aware of any functions that can do what you need
there.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Daevid Vincent
Oh. I know it's not a simple solution to do right Ashley. And exacerbated
by the fact that each array dimension can have different dimensions as
well. This is why I wanted someone else's solution first before I spend
hours or days on one that works reliably. :)


  _  

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Monday, March 15, 2010 4:44 PM
Subject: Re: [PHP] Need routine to tell me number of dimensions in array

The only way to do it reliably would be to iterate the entire array,
element by element, as all the elements of an array might not necessarily
be all of the array type or int's.




Re: [PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 16:45 -0700, Daevid Vincent wrote:

> Anyone have a function that will return an integer of the number of
> dimensions an array has?
> 
> I did some quick searches and came up with nothing. 
> The closest was here of someone asking the same thing, but his solution
> isn't right:
> http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
> http://php.net/manual/en/function.count.php
> 
> From a human standpoint, it's easy to see, "oh, this is a TWO
> dimensional"...
> 
> Array
> (
> [0] => Array
> (
> [0] => Data marked as faulty or timestamps before 2005 or in
> the future (2035)
> [1] => bad_data
> )
> 
> [1] => Array
> (
> [0] => Hardware Part Numbers
> [1] => hardware_part_numbers
> )
> 
> [2] => Array
> (
> [0] => Software Part Numbers
> [1] => software_part_numbers
> )
> 
> [3] => Array
> (
> [0] => Software Version Number
> [1] => software_version_numbers
> )
> 
> [4] => Array
> (
> [0] => Configuration Part Numbers
> [1] => configuration_part_numbers
> )
> 
> )
> 
> From a programatic POV, it's not quite that easy to see "this is a THREE
> dimensional", since element [0][0] is missing and it actually starts at
> [0][1], so you can't do an is_array($foo[0][0]) on it (but if you did on
> [0][1] it would pass) so you have to itterate over ALL elements of the
> array until you find one that hits or you exhaust that dimension. But then
> you have to traverse any subdimensions too, most likely recursively.
> 
> Array
> (
> [0] => Array
> (
> [1] => Array
> (
> [0] => Aircraft Registration
> [1] => aircraft_registration
> )
> 
> [2] => Array
> (
> [0] => Aircraft Type-Subtype
> [1] => aircraft_type_subtype
> )
> 
> [3] => Array
> (
> [0] => System
> [1] => system_type_name
> )
> 
> [4] => Array
> (
> [0] => Flight Count
> [1] => flight_count
> )
> 
> ...
> 
> 
> Then it gets even more complex as this has all sorts of holes in it...
> 
> Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [0] => Flight Number
> [1] => flight_number
> )
> 
> [4] => Array
> (
> [0] => Timestamp Departure
> [1] => timestamp_departure
> )
> 
> [6] => Array
> (
> [0] => Timestamp Arrival
> [1] => timestamp_arrival
> )
> 
> [8] => Array
> (
> [0] => Departure City
> [1] => departure_city
> )
> 
> [9] => Array
> (
> [0] => Arrival City
> [1] => arrival_city
> )
> 
> Now I could take the time to dig in and figure this all out, but I thought
> maybe someone already had a solution they could share?
> 
> 


The only way to do it reliably would be to iterate the entire array,
element by element, as all the elements of an array might not
necessarily be all of the array type or int's.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Need routine to tell me number of dimensions in array.

2010-03-15 Thread Daevid Vincent
Anyone have a function that will return an integer of the number of
dimensions an array has?

I did some quick searches and came up with nothing. 
The closest was here of someone asking the same thing, but his solution
isn't right:
http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
http://php.net/manual/en/function.count.php

>From a human standpoint, it's easy to see, "oh, this is a TWO
dimensional"...

Array
(
[0] => Array
(
[0] => Data marked as faulty or timestamps before 2005 or in
the future (2035)
[1] => bad_data
)

[1] => Array
(
[0] => Hardware Part Numbers
[1] => hardware_part_numbers
)

[2] => Array
(
[0] => Software Part Numbers
[1] => software_part_numbers
)

[3] => Array
(
[0] => Software Version Number
[1] => software_version_numbers
)

[4] => Array
(
[0] => Configuration Part Numbers
[1] => configuration_part_numbers
)

)

>From a programatic POV, it's not quite that easy to see "this is a THREE
dimensional", since element [0][0] is missing and it actually starts at
[0][1], so you can't do an is_array($foo[0][0]) on it (but if you did on
[0][1] it would pass) so you have to itterate over ALL elements of the
array until you find one that hits or you exhaust that dimension. But then
you have to traverse any subdimensions too, most likely recursively.

Array
(
[0] => Array
(
[1] => Array
(
[0] => Aircraft Registration
[1] => aircraft_registration
)

[2] => Array
(
[0] => Aircraft Type-Subtype
[1] => aircraft_type_subtype
)

[3] => Array
(
[0] => System
[1] => system_type_name
)

[4] => Array
(
[0] => Flight Count
[1] => flight_count
)

...


Then it gets even more complex as this has all sorts of holes in it...

Array
(
[0] => Array
(
[0] => Array
(
[0] => Flight Number
[1] => flight_number
)

[4] => Array
(
[0] => Timestamp Departure
[1] => timestamp_departure
)

[6] => Array
(
[0] => Timestamp Arrival
[1] => timestamp_arrival
)

[8] => Array
(
[0] => Departure City
[1] => departure_city
)

[9] => Array
(
[0] => Arrival City
[1] => arrival_city
)

Now I could take the time to dig in and figure this all out, but I thought
maybe someone already had a solution they could share?


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



Re: [PHP] Event Handling

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 20:02 -0300, Gabriel Sosa wrote:

> Indeed. This is kinda offtopic but if you put a cron running with a
> loop you will kill your server. I would recomend use libevent + ALARM
> signal to process on a time basis. On the other hand using C would be
> a nice aproach since you can put your script on an sleep mode until
> the next alarm signal is trigered + less resources taken
> 
> Saludos
> 
> On 3/15/10, Paul M Foster  wrote:
> > On Mon, Mar 15, 2010 at 05:38:04PM -, Alex Major wrote:
> >
> >> Thanks to all for your help on this, it's been very interesting for me to
> >> read.
> >>
> >> The system needs to check arrivals in real time (give or take a second or
> >> two), using a cron job every minute doesn't provide the real time checking
> >> I
> >> would like.
> >>
> >> However, when I then got to thinking about it, wouldn't this be an ideal
> >> solution? I create a PHP script that loops for 60 seconds, checking the
> >> database each second for new entries and processing them (meaning I get
> >> near
> >> real time monitoring), and then have that PHP script called by a cron job
> >> every minute.
> >>
> >> The reason I think that could be a good solution for me, is that if the
> >> PHP
> >> script crashed (for any reason), then at most it's 59 seconds before the
> >> system kicks in again and begins processing all the queued arrivals. If I
> >> coded a PHP script to loop infinitely processing things every second, it's
> >> possible I wouldn't notice a crash for a considerable amount of time. The
> >> proposed solution provides a good fail-safe, I think.
> >>
> >> Does that solution seem sensible? Or overkill?
> >>
> >> Thanks again for your help in this, it's quite novel for me.
> >
> > I would think that the PHP CLI extension would need to be installed on
> > the server for this to work. I don't know that that's common. (I could
> > be completely wrong.)
> >
> > I would recommend coding this in C, because it would use far less
> > resources.
> >
> > Paul
> >
> > --
> > Paul M. Foster
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> -- 
> Sent from my mobile device
> 
> Gabriel Sosa
> Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein
> 


Using cron won't kill the server! Cron isn't only for scheduled tasks
but repeated ones as well and is perfect for running in the background
on a server all the time.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Event Handling

2010-03-15 Thread Gabriel Sosa
Indeed. This is kinda offtopic but if you put a cron running with a
loop you will kill your server. I would recomend use libevent + ALARM
signal to process on a time basis. On the other hand using C would be
a nice aproach since you can put your script on an sleep mode until
the next alarm signal is trigered + less resources taken

Saludos

On 3/15/10, Paul M Foster  wrote:
> On Mon, Mar 15, 2010 at 05:38:04PM -, Alex Major wrote:
>
>> Thanks to all for your help on this, it's been very interesting for me to
>> read.
>>
>> The system needs to check arrivals in real time (give or take a second or
>> two), using a cron job every minute doesn't provide the real time checking
>> I
>> would like.
>>
>> However, when I then got to thinking about it, wouldn't this be an ideal
>> solution? I create a PHP script that loops for 60 seconds, checking the
>> database each second for new entries and processing them (meaning I get
>> near
>> real time monitoring), and then have that PHP script called by a cron job
>> every minute.
>>
>> The reason I think that could be a good solution for me, is that if the
>> PHP
>> script crashed (for any reason), then at most it's 59 seconds before the
>> system kicks in again and begins processing all the queued arrivals. If I
>> coded a PHP script to loop infinitely processing things every second, it's
>> possible I wouldn't notice a crash for a considerable amount of time. The
>> proposed solution provides a good fail-safe, I think.
>>
>> Does that solution seem sensible? Or overkill?
>>
>> Thanks again for your help in this, it's quite novel for me.
>
> I would think that the PHP CLI extension would need to be installed on
> the server for this to work. I don't know that that's common. (I could
> be completely wrong.)
>
> I would recommend coding this in C, because it would use far less
> resources.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
Sent from my mobile device

Gabriel Sosa
Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein

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



RE: [PHP] how to get the local time

2010-03-15 Thread Daevid Vincent
You either have to use JS on the client side. 

Or you store the user's timezone as a preference in their profile and
compute using that by setting a TZ variable.

Normally you would store all data in mySQL in UTC and then convert on the
fly as mentioned above for each user. 

> -Original Message-
> From: saeed ahmed [mailto:saeed@gmail.com] 
> Sent: Monday, March 15, 2010 1:11 PM
> To: php-general@lists.php.net
> Subject: [PHP] how to get the local time
> 
> hi friends,
> 
> I'm trying to set local time in my php script. I was trying 
> date and time
> function but its always show the server time not local time. 
> i need help on
> this problem. how can i set the local time. i need sweden time zone
> -
> Regards
> Saeed Ahmed
> http://saeed05.wordpress.com
> -
> 


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



[PHP] Re: how to get the local time

2010-03-15 Thread Gary
You should be able to get the local time for Sweden by adding



However, I dont know about getting the local time of someone visiting from a 
different time zone.

gary


"saeed ahmed"  wrote in message 
news:b10025e1003151310j483caed1mef9ec76874a53...@mail.gmail.com...
> hi friends,
>
> I'm trying to set local time in my php script. I was trying date and time
> function but its always show the server time not local time. i need help 
> on
> this problem. how can i set the local time. i need sweden time zone
> -
> Regards
> Saeed Ahmed
> http://saeed05.wordpress.com
> -
>
>
>
> __ Information from ESET Smart Security, version of virus 
> signature database 4946 (20100315) __
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
> 



__ Information from ESET Smart Security, version of virus signature 
database 4946 (20100315) __

The message was checked by ESET Smart Security.

http://www.eset.com





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



Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Jim Lucas
Al wrote:
> Anyone have a regex pattern for deleting multiple backslashes e.g., \\\
> 
> I pretty good with regex; but, be damned if I can delete them with
> preg_replace()
> 
> I've tried "" as the manual says
> 
> preg_replace("//", '', $str);
> 
> preg_replace("/()+/", '', $str);
> 
> preg_replace("/\x5C/", '', $str);
> 
> preg_replace("/\\x5c/", '', $str);
> 
> And lots of others.
> 
> stripslashes() and stripcslashes() are limited.
> 
> 
> 

Might I ask, how are the multiple slashes getting generated in the first place?
 Where is the data coming from?

Next question would be: Do you want to completely remove all instances of
multiple backslashes?  Or, do you want to replace all instances of multiple
backslashes with a single backslash?

I would try something like this:


done!


-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

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



Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Al



On 3/15/2010 3:30 PM, Ashley Sheridan wrote:

On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:




On 3/15/2010 3:11 PM, Ashley Sheridan wrote:


On Mon, 2010-03-15 at 15:03 -0400, Al wrote:


Anyone have a regex pattern for deleting multiple backslashes e.g., \\\

I pretty good with regex; but, be damned if I can delete them with 
preg_replace()

I've tried "" as the manual says

preg_replace("//", '', $str);

preg_replace("/()+/", '', $str);

preg_replace("/\x5C/", '', $str);

preg_replace("/\\x5c/", '', $str);

And lots of others.

stripslashes() and stripcslashes() are limited.







What about this:

$str = 'text\\dfnfg\\dhdsg';
echo preg_replace('/\\\{2,}/', '', $str);

I think what was catching you out was that you were escaping the \
once for the regex, but then it needed it again because it was in a
single quoted string, meaning 3 slashes in total. Took me a little
while to figure that out as well!

The {2,} part just tells it to only remove the slashes where they
occur in runs of two or more.




I agree, it should work; but, it doesn't.

Most everything that looks reasonable works in The Regex Coach,
including you suggestion.

I'm starting to think there is a bug in the regex engine; haven't
looked yet.  It's doubtful though because the bug would screw existing
code.


Thanks,
Ash
http://www.ashleysheridan.co.uk






I tried the code I just gave you and it's working, so I'm not sure now
what issue you're having with it?

Thanks,
Ash
http://www.ashleysheridan.co.uk





Thanks ever so much guys. Sometimes it's helpful when someone else confirms 
something must work.


Problem was that I had a series of cleanup and security checks on a POST array 
and inadvertently used the original POST array in one of the steps following the 
backslash remove step, so obviously it didn't work.


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



Re: [PHP] how to get the local time

2010-03-15 Thread Ashley Sheridan
On Tue, 2010-03-16 at 02:10 +0600, saeed ahmed wrote:

> hi friends,
> 
> I'm trying to set local time in my php script. I was trying date and time
> function but its always show the server time not local time. i need help on
> this problem. how can i set the local time. i need sweden time zone
> -
> Regards
> Saeed Ahmed
> http://saeed05.wordpress.com
> -


Do you mean local time as in the clients computer time? If so, as far as
I know you can't get that with PHP. What you would have to do is grab it
with JavaScript or something, and then pass that across to your server
script.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] how to get the local time

2010-03-15 Thread saeed ahmed
hi friends,

I'm trying to set local time in my php script. I was trying date and time
function but its always show the server time not local time. i need help on
this problem. how can i set the local time. i need sweden time zone
-
Regards
Saeed Ahmed
http://saeed05.wordpress.com
-


Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread james stojan
Double check your code I came up with the same solution as Ash did and it
worked fine in Wamp.

On Mon, Mar 15, 2010 at 3:30 PM, Ashley Sheridan
wrote:

> On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:
>
> >
> >
> > On 3/15/2010 3:11 PM, Ashley Sheridan wrote:
> >
> > > On Mon, 2010-03-15 at 15:03 -0400, Al wrote:
> > >
> > > > Anyone have a regex pattern for deleting multiple backslashes e.g.,
> \\\
> > > >
> > > > I pretty good with regex; but, be damned if I can delete them with
> preg_replace()
> > > >
> > > > I've tried "" as the manual says
> > > >
> > > > preg_replace("//", '', $str);
> > > >
> > > > preg_replace("/()+/", '', $str);
> > > >
> > > > preg_replace("/\x5C/", '', $str);
> > > >
> > > > preg_replace("/\\x5c/", '', $str);
> > > >
> > > > And lots of others.
> > > >
> > > > stripslashes() and stripcslashes() are limited.
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > > What about this:
> > >
> > > $str = 'text\\dfnfg\\dhdsg';
> > > echo preg_replace('/\\\{2,}/', '', $str);
> > >
> > > I think what was catching you out was that you were escaping the \
> > > once for the regex, but then it needed it again because it was in a
> > > single quoted string, meaning 3 slashes in total. Took me a little
> > > while to figure that out as well!
> > >
> > > The {2,} part just tells it to only remove the slashes where they
> > > occur in runs of two or more.
> > >
> >
> >
> > I agree, it should work; but, it doesn't.
> >
> > Most everything that looks reasonable works in The Regex Coach,
> > including you suggestion.
> >
> > I'm starting to think there is a bug in the regex engine; haven't
> > looked yet.  It's doubtful though because the bug would screw existing
> > code.
> >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
>
>
> I tried the code I just gave you and it's working, so I'm not sure now
> what issue you're having with it?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:

> 
> 
> On 3/15/2010 3:11 PM, Ashley Sheridan wrote: 
> 
> > On Mon, 2010-03-15 at 15:03 -0400, Al wrote: 
> > 
> > > Anyone have a regex pattern for deleting multiple backslashes e.g., 
> > > \\\
> > > 
> > > I pretty good with regex; but, be damned if I can delete them with 
> > > preg_replace()
> > > 
> > > I've tried "" as the manual says
> > > 
> > > preg_replace("//", '', $str);
> > > 
> > > preg_replace("/()+/", '', $str);
> > > 
> > > preg_replace("/\x5C/", '', $str);
> > > 
> > > preg_replace("/\\x5c/", '', $str);
> > > 
> > > And lots of others.
> > > 
> > > stripslashes() and stripcslashes() are limited.
> > > 
> > > 
> > > 
> > > 
> > 
> > 
> > What about this:
> > 
> > $str = 'text\\dfnfg\\dhdsg';
> > echo preg_replace('/\\\{2,}/', '', $str);
> > 
> > I think what was catching you out was that you were escaping the \
> > once for the regex, but then it needed it again because it was in a
> > single quoted string, meaning 3 slashes in total. Took me a little
> > while to figure that out as well!
> > 
> > The {2,} part just tells it to only remove the slashes where they
> > occur in runs of two or more.
> > 
> 
> 
> I agree, it should work; but, it doesn't.  
> 
> Most everything that looks reasonable works in The Regex Coach,
> including you suggestion.  
> 
> I'm starting to think there is a bug in the regex engine; haven't
> looked yet.  It's doubtful though because the bug would screw existing
> code.  
> 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> > 


I tried the code I just gave you and it's working, so I'm not sure now
what issue you're having with it?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 15:03 -0400, Al wrote:

> Anyone have a regex pattern for deleting multiple backslashes e.g., \\\
> 
> I pretty good with regex; but, be damned if I can delete them with 
> preg_replace()
> 
> I've tried "" as the manual says
> 
> preg_replace("//", '', $str);
> 
> preg_replace("/()+/", '', $str);
> 
> preg_replace("/\x5C/", '', $str);
> 
> preg_replace("/\\x5c/", '', $str);
> 
> And lots of others.
> 
> stripslashes() and stripcslashes() are limited.
> 
> 
> 


What about this:

$str = 'text\\dfnfg\\dhdsg';
echo preg_replace('/\\\{2,}/', '', $str);

I think what was catching you out was that you were escaping the \ once
for the regex, but then it needed it again because it was in a single
quoted string, meaning 3 slashes in total. Took me a little while to
figure that out as well!

The {2,} part just tells it to only remove the slashes where they occur
in runs of two or more.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Deleting multiple backslashes; regex?

2010-03-15 Thread Al

Anyone have a regex pattern for deleting multiple backslashes e.g., \\\

I pretty good with regex; but, be damned if I can delete them with 
preg_replace()

I've tried "" as the manual says

preg_replace("//", '', $str);

preg_replace("/()+/", '', $str);

preg_replace("/\x5C/", '', $str);

preg_replace("/\\x5c/", '', $str);

And lots of others.

stripslashes() and stripcslashes() are limited.



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



RE: [PHP] Re: PHP in HTML code

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 14:12 -0400, Bob McConnell wrote:

> From: Jochem Maas
> 
> > Op 3/13/10 3:49 PM, Jorge Gomes schreef:
> >> First of all, i recommend the use of normal php tags ()
> because
> >> the short tags are atm marked as* **DEPRECATED*.
> > 
> > that's a documentation error.
> 
> No it's not. The short tags conflict with both XML and XHTML and
> therefore are being phased out. You should be replacing them as quickly
> as you can.
> 
> Bob McConnell
> 
> 


I don't see where in the documentation where it's marked as deprecated.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] ldap_bind() connectivity

2010-03-15 Thread Ashley M. Kirchner
> -Original Message-
> From: Peter Lind [mailto:peter.e.l...@gmail.com]
> Sent: Monday, March 15, 2010 3:13 AM
> To: Ashley M. Kirchner
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] ldap_bind() connectivity
> 
> You might want to check what the function outputs with:
> 
> var_dump($ldapbind);
> 
> after the call to ldap_bing(). That way you'll know what actually got
> returned from the function.


SOLVED.  As it turned out, it had nothing to do with ldap_bind() ... it had to 
do with the fact that my brain is still adjusting from the time change and I 
missed an 'echo' ...

Thanks all.

A


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



RE: [PHP] Re: PHP in HTML code

2010-03-15 Thread Bob McConnell
From: Jochem Maas

> Op 3/13/10 3:49 PM, Jorge Gomes schreef:
>> First of all, i recommend the use of normal php tags ()
because
>> the short tags are atm marked as* **DEPRECATED*.
> 
> that's a documentation error.

No it's not. The short tags conflict with both XML and XHTML and
therefore are being phased out. You should be replacing them as quickly
as you can.

Bob McConnell


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



Re: [PHP] Event Handling

2010-03-15 Thread Paul M Foster
On Mon, Mar 15, 2010 at 05:38:04PM -, Alex Major wrote:

> Thanks to all for your help on this, it's been very interesting for me to
> read.
> 
> The system needs to check arrivals in real time (give or take a second or
> two), using a cron job every minute doesn't provide the real time checking I
> would like.
> 
> However, when I then got to thinking about it, wouldn't this be an ideal
> solution? I create a PHP script that loops for 60 seconds, checking the
> database each second for new entries and processing them (meaning I get near
> real time monitoring), and then have that PHP script called by a cron job
> every minute.
> 
> The reason I think that could be a good solution for me, is that if the PHP
> script crashed (for any reason), then at most it's 59 seconds before the
> system kicks in again and begins processing all the queued arrivals. If I
> coded a PHP script to loop infinitely processing things every second, it's
> possible I wouldn't notice a crash for a considerable amount of time. The
> proposed solution provides a good fail-safe, I think.
> 
> Does that solution seem sensible? Or overkill?
> 
> Thanks again for your help in this, it's quite novel for me.

I would think that the PHP CLI extension would need to be installed on
the server for this to work. I don't know that that's common. (I could
be completely wrong.)

I would recommend coding this in C, because it would use far less
resources.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Re: PHP in HTML code

2010-03-15 Thread Jochem Maas
Op 3/13/10 3:49 PM, Jorge Gomes schreef:
> First of all, i recommend the use of normal php tags () because
> the short tags are atm marked as* **DEPRECATED*.

that's a documentation error.

> 
> You should also echo your values to the page, instead using the shortcut  (stop being a lazy ass! :P):

it's not lazy, it's succinct and much easier to read (once you know what it 
means),
but ... if you require portable code and your liable to be running on shared
hosting where you don't control the ini settings you might consider not using 
it.

it is often feasable to turn them on explicitly in your 'init' routine so that
your template/output code can use short tags:



I can't recall that this is ever locked down on a server so that you can't
change it, although the default if quite often set to FALSE.

> 
> 
> 
> 
> 
> 
> 
> 
> remember that between tags, we have normal php code.
> 
> Rewards

how much?

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



RE: [PHP] Event Handling

2010-03-15 Thread Alex Major
Thanks to all for your help on this, it's been very interesting for me to
read.

The system needs to check arrivals in real time (give or take a second or
two), using a cron job every minute doesn't provide the real time checking I
would like.

However, when I then got to thinking about it, wouldn't this be an ideal
solution? I create a PHP script that loops for 60 seconds, checking the
database each second for new entries and processing them (meaning I get near
real time monitoring), and then have that PHP script called by a cron job
every minute.

The reason I think that could be a good solution for me, is that if the PHP
script crashed (for any reason), then at most it's 59 seconds before the
system kicks in again and begins processing all the queued arrivals. If I
coded a PHP script to loop infinitely processing things every second, it's
possible I wouldn't notice a crash for a considerable amount of time. The
proposed solution provides a good fail-safe, I think.

Does that solution seem sensible? Or overkill?

Thanks again for your help in this, it's quite novel for me.

-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 15 March 2010 12:56
To: Midhun Girish
Cc: Jochem Maas; David Hutto; php-general@lists.php.net; Alex Major
Subject: Re: [PHP] Event Handling

On Mon, 2010-03-15 at 18:28 +0530, Midhun Girish wrote:

> rene "a page with an ajax script that kicks off the
check-for-recent-events
> script on the server".. but that method is highly non reliable i dont
> think anyone will take that risk especially for an important web app
> cron or any equivalent which runs on the server must be used instead of
> that..
> 
> 
> Midhun Girish
> Development Lead
> MobAlive Technologies
> 
> 
> 
> On Mon, Mar 15, 2010 at 6:08 PM, Jochem Maas  wrote:
> 
> > Op 3/15/10 12:00 PM, David Hutto schreef:
> > > On Mon, Mar 15, 2010 at 7:31 AM, Jochem Maas 
> > wrote:
> > >
> > >> Op 3/15/10 8:24 AM, Midhun Girish schreef:
> > >>> Hi ,
> > >>> Just as David Hutto has said,What you need is the cronjob... Make a
> > >> script
> > >>> say "check.php" which checks the db to see if any new entries are
> > made...
> > >>> and if yes send the mail ...
> > >>>
> > >>> now using the cronjob feature in linux os(which will be provided as
a
> > >>> service in your linux hosting cpanel), set a cronjob which calls the
"
> > >>> http://www.yoursite.com/check.php"; URL every minute now a
trigger
> > >> will
> > >>> be there every minute to the script and the emails will be send
> > >> irrespective
> > >>> of whether anyone is browsing the site or not hope it is
clear...
> > >>>
> > >>
> > >> use cron - yes
> > >> have cron call a web URL - no, instead just call the script via the
php
> > CLI
> > >> sapi,
> > >> e.g. a cmdline as follows in cron:
> > >>
> > >> /usr/env php /path/to/your/check.php &> /dev/null
> > >>
> > >
> > >
> > > I do believe removing the /dev/null will send error messages during
the
> > > building of the script, correct?
> > >
> >
> > the '&> /dev/null' redirects all output - I kind of make the assumption
> > that the
> > script would be logging stuff to a file or something when in production.
> >
> > so, yes, remove the redirection when your developing/testing the script.
> >
> >
> >


I agree. Even setting a cron on a local computer to call home to a
server script would be preferable to Ajax calls.

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



Re: [PHP] mysqli procedural calls and manual entries ?

2010-03-15 Thread Daniel Brown
On Fri, Mar 12, 2010 at 06:48, Daniel Egeberg  wrote:
>
> Hi Per,
>
> The manual already supports that. If you install the sqlite extension
> on your webserver, it should work.

Dan;

The question wasn't whether or not it supports that kind of
lookup, but rather why it's not working.  We've had issues with the
mysqli_* stuff for years.  It's a known issue to us, but not to
everyone.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] mysqli procedural calls and manual entries ?

2010-03-15 Thread Daniel Egeberg
On Fri, Mar 12, 2010 at 08:49, Per Jessen  wrote:
> I run a local mirror of the PHP manual, and I most often go straight to
> the "Search for" box to look up the format of a function.  With the
> mysqli functions, I've found than many of them simply
> aren't "available" that way.  E.g. mysqli_connect() - "Sorry, but the
> function mysqli_connect  is not in the online manual.".
>
> Would it be a lot of effort to create function manual entries for the
> procedural style of mysqli_*?
>
>
> /Per

Hi Per,

The manual already supports that. If you install the sqlite extension
on your webserver, it should work.

-- 
Daniel Egeberg

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



Re: [PHP] long polling solution for LAMP with limited privilege

2010-03-15 Thread Rene Veerman
On shared hosting, you usually can't change the 30 sec max timeout on
the server..

So long polling >30s is not possible.

Short polling could be the answer, which can be done with ajax (see
jquery.com) from javascript, especially if you keep the cost of "are
there any new events for this client" down..

On Mon, Mar 15, 2010 at 6:13 PM, Ryan Sun  wrote:
> I wonder if you guys have a
> long-polling(http://meteorserver.org/interaction-modes/) solution for
> a shared hosting(eg. hostmonster)
>
> --
> 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



[PHP] long polling solution for LAMP with limited privilege

2010-03-15 Thread Ryan Sun
I wonder if you guys have a
long-polling(http://meteorserver.org/interaction-modes/) solution for
a shared hosting(eg. hostmonster)

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



[PHP] Using Mono library from PHP

2010-03-15 Thread Fernando
Is there a way to use a Mono library from PHP running on Apache 2.2 on a 
Debian server?


I have seen samples of using COM and DOTNET, but it seems to work only 
on Windows not on Linux.


Your help is really appreciated.

Thank you,

Fernando.


Re: [PHP] Splitting a string ...

2010-03-15 Thread shiplu
Here is the regex for you.


$company_domain = '\w+'; // replace with your own company domain pattern.
$user_name = '\w+'; // replace with your own username pattern
$email_domain = '\w+\.\w{2,4}'; // google for standard domain name
regex pattern and replace it.

$regexp = 
"~({$company_domain}[/])?(?P$user_name)(@$email_domain)?~";

preg_match($regexp, $text, $matches);

print_r($matches); // $matches['username'] will contain username.

-- 
Shiplu Mokaddim
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

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



Re: [PHP] Doing dynamic routing for an office

2010-03-15 Thread Andrew Ballard
On Fri, Mar 12, 2010 at 3:30 AM, Per Jessen  wrote:
> Ian wrote:
>
>> Hi,
>>
>> I have had a weird request as a project and that is to build a system
>> where the clients can put down their office plans into a system and
>> based on where you are in the buliding (either via defined kiosks or
>> mobile dropdown filters) it will print out directions on how to get
>> somewhere within that building. Now, to do it from a fixed location is
>> okay - that could just be a manual input for each building, but for
>> the variable start point I have no idea how to do it.
>
> I don't know exactly where to go and look, but such mapping systems are
> very common these days (think GPS navigation systems etc), so the
> algorithms involved must be equally well known and -documented.
>
> /Per
>
> --
> Per Jessen, Zürich (-1.7°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I believe this is the general idea. Various points within the area
(country, building, etc.) that you are mapping are the nodes within
the graph, so you are looking for the best (often, but not necessarily
the shortest) route between two nodes.

http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

Andrew

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



Re: [PHP] Event Handling

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 18:28 +0530, Midhun Girish wrote:

> rene "a page with an ajax script that kicks off the check-for-recent-events
> script on the server".. but that method is highly non reliable i dont
> think anyone will take that risk especially for an important web app
> cron or any equivalent which runs on the server must be used instead of
> that..
> 
> 
> Midhun Girish
> Development Lead
> MobAlive Technologies
> 
> 
> 
> On Mon, Mar 15, 2010 at 6:08 PM, Jochem Maas  wrote:
> 
> > Op 3/15/10 12:00 PM, David Hutto schreef:
> > > On Mon, Mar 15, 2010 at 7:31 AM, Jochem Maas 
> > wrote:
> > >
> > >> Op 3/15/10 8:24 AM, Midhun Girish schreef:
> > >>> Hi ,
> > >>> Just as David Hutto has said,What you need is the cronjob... Make a
> > >> script
> > >>> say "check.php" which checks the db to see if any new entries are
> > made...
> > >>> and if yes send the mail ...
> > >>>
> > >>> now using the cronjob feature in linux os(which will be provided as a
> > >>> service in your linux hosting cpanel), set a cronjob which calls the "
> > >>> http://www.yoursite.com/check.php"; URL every minute now a trigger
> > >> will
> > >>> be there every minute to the script and the emails will be send
> > >> irrespective
> > >>> of whether anyone is browsing the site or not hope it is clear...
> > >>>
> > >>
> > >> use cron - yes
> > >> have cron call a web URL - no, instead just call the script via the php
> > CLI
> > >> sapi,
> > >> e.g. a cmdline as follows in cron:
> > >>
> > >> /usr/env php /path/to/your/check.php &> /dev/null
> > >>
> > >
> > >
> > > I do believe removing the /dev/null will send error messages during the
> > > building of the script, correct?
> > >
> >
> > the '&> /dev/null' redirects all output - I kind of make the assumption
> > that the
> > script would be logging stuff to a file or something when in production.
> >
> > so, yes, remove the redirection when your developing/testing the script.
> >
> >
> >


I agree. Even setting a cron on a local computer to call home to a
server script would be preferable to Ajax calls.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: Splitting a string ...

2010-03-15 Thread Al



On 3/14/2010 9:54 PM, Ashley M. Kirchner wrote:

I'm not a regexp person (wish I was though), and I'm hoping someone can give
me a hand here.  Consider the following strings:



-  domain\usern...@example.org

-  domain\username

-  the same as above but with / instead of \  (hey, it happens)

-  usern...@example.org

-  username



Essentially I have a sign-up form where folks will be typing in their
username.  The problem is, in our organization, when you tell someone to
enter their username, it could end up being any of the above examples
because they're used to a domain log in procedure where in some cases they
type the whole thing, in other cases just the e-mail, or sometimes just the
username.



So what I'd like is a way to capture just the 'username' part, regardless of
what other pieces they put in.  In the past I would write a rather
inefficient split() routine and eventually get what I need.  With split()
getting deprecated, I figured I may as well start looking into how to do it
properly.  There's preg_split(), str_split(), explode() . possibly others.



So, what's the proper way to do this?  How can I capture just the part I
need, regardless of how they typed it in?



Thanks!



A




The basic problem is that the slashes are legitimate characters for usernames 
per the RFC 5322; http://en.wikipedia.org/wiki/E-mail_address


However, per the "Notwithstanding the addresses permitted by these 
standards" paragraph, I disallow the "! # $ % * / ? ^ ` { | } ~" and have 
not found a problem.


You didn't mention whether you had control over the whole submission process. If 
so, I'd suggest checking the submitted address and sending back to the client a 
message asking them to correct their submission and resending it.


You can check for any of the above characters and bounce the submission back to 
the client.


Check out filter_var($emailAddr, FILTER_VALIDATE_EMAIL) It will catch a lot of 
errors.


Also, you'll find the helpful preg_match("%[[:alnum:][:punct:]]%", $addr); These 
are legit characters.  First remove everything following the @ and the @ itself. 
Obviously, you can use if(!preg_match) to catch anything not valid.


There are several str functions that'll do it or simply preg_replace("%...@.*%", 
'', $addr)



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



Re: [PHP] Event Handling

2010-03-15 Thread Midhun Girish
rene "a page with an ajax script that kicks off the check-for-recent-events
script on the server".. but that method is highly non reliable i dont
think anyone will take that risk especially for an important web app
cron or any equivalent which runs on the server must be used instead of
that..


Midhun Girish
Development Lead
MobAlive Technologies



On Mon, Mar 15, 2010 at 6:08 PM, Jochem Maas  wrote:

> Op 3/15/10 12:00 PM, David Hutto schreef:
> > On Mon, Mar 15, 2010 at 7:31 AM, Jochem Maas 
> wrote:
> >
> >> Op 3/15/10 8:24 AM, Midhun Girish schreef:
> >>> Hi ,
> >>> Just as David Hutto has said,What you need is the cronjob... Make a
> >> script
> >>> say "check.php" which checks the db to see if any new entries are
> made...
> >>> and if yes send the mail ...
> >>>
> >>> now using the cronjob feature in linux os(which will be provided as a
> >>> service in your linux hosting cpanel), set a cronjob which calls the "
> >>> http://www.yoursite.com/check.php"; URL every minute now a trigger
> >> will
> >>> be there every minute to the script and the emails will be send
> >> irrespective
> >>> of whether anyone is browsing the site or not hope it is clear...
> >>>
> >>
> >> use cron - yes
> >> have cron call a web URL - no, instead just call the script via the php
> CLI
> >> sapi,
> >> e.g. a cmdline as follows in cron:
> >>
> >> /usr/env php /path/to/your/check.php &> /dev/null
> >>
> >
> >
> > I do believe removing the /dev/null will send error messages during the
> > building of the script, correct?
> >
>
> the '&> /dev/null' redirects all output - I kind of make the assumption
> that the
> script would be logging stuff to a file or something when in production.
>
> so, yes, remove the redirection when your developing/testing the script.
>
>
>


Re: [PHP] Re: I need a fresh look at storing variables in MySQL

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 12:48 +, Colin Guthrie wrote:

> 'Twas brillig, and Jochem Maas at 14/03/10 23:56 did gyre and gimble:
> > Op 3/14/10 11:45 AM, Ashley Sheridan schreef:
> >> On Sun, 2010-03-14 at 12:25 +0100, Rene Veerman wrote:
> >>
> >>> On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman  wrote:
> 
>  I'd love to have a copy of whatever function you use to filter out bad
>  HTML/js/flash for use cases where users are allowed to enter html.
>  I'm aware of strip_tags() "allowed tags" param, but haven't got a good 
>  list
>  for it.
> 
> >>>
> >>> oh, and even  tags can be used for cookie-stuffing on many browsers..
> >>>
> >>
> >>
> >> Yes, and you call strip_tags() before the data goes to the browser for
> >> display, not before it gets inserted into the database. Essentially, you
> >> need to keep as much original information as possible.
> > 
> > I disagree with both you. I'm like that :)
> > 
> > let's assume we're not talking about data that is allowed to contain HTML,
> > in such cases I would do a strip_tags() on the incoming data then compare
> > the output ofstrip_tags() to the original input ... if they don't match then
> > I would log the problem and refuse to input the data at all.
> > 
> > using strip_tags() on a piece of data everytime you output it if you know
> > that it shouldn't contain any in the first is a waste of resources ... this
> > does assume that you can trust the data source ... which in the case of a 
> > database
> > that you control should be the case.
> 
> I used to think like that too, but I've relatively recently changed my
> position.
> 
> While it's not as extreme an example, I used to keep data in the
> database *after* I had processed it with htmlspecialchars() (not quite
> the same as strip_tags, but the principle is the same).
> 
> The issue I had was that over time, I've found the need to output to
> other formats - e.g. spread sheets, plain text emails, PDFs etc. in
> which case this pre-encoded format is a pain and I have to call
> html_entity_decode() to reverse the htmlspecialchars() I did in the
> first place. This is a royal pain in the bum and it's really ugly in the
> code, remembering what format the data is in in order to process it
> appropriately at the right points.
> 
> Nowadays I work rather differently and always escape at the point of
> output (this does not exclude filtering at the point of input too, but I
> do not keep things encoded any longer - I keep it raw).
> 
> Any half way decently designed caching layer will prevent any major
> impact from escaping at the point of output anyway.
> 
> Now you could argue that encoding at the save point and reversing the
> encoding when needed is still a better approach and I wont argue too
> heavily, but for the sake of my sanity I'm much happier working the way
> I do now. The view layers are very clearly escaping everything that
> needs escaping and no logic for the "is it or is it not already escaped"
> leaks into this layer.
> 
> (I appreciate strip tags and htmlspecialchars are not the same and my
> general usage may not apply to a pure striptags usage).
> 
> > at any rate, strip_tags() doesn't belong in an 'anti-sql-injection' routine 
> > as
> > it has nothing to do with sql injection at all.
> 
> Indeed, it's more about XSS and CSRF rather than SQL injection.
> 
> Col
> 
> -- 
> 
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
> 
> Day Job:
>   Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
>   Mandriva Linux Contributor [http://www.mandriva.com/]
>   PulseAudio Hacker [http://www.pulseaudio.org/]
>   Trac Hacker [http://trac.edgewall.org/]
> 
> 


You could escape the content with strip_tags() and insert both copies
into the database if you're really worried about wasted resources. That
way, you keep a copy of the original data, and the one you're most
likely going to display in a web page.

It's like the whole argument about modifying textarea content to replace
newlines with  tags. At some point, you might need that content for
another use, and when you do, you'll wish you had the original. Just
because you don't see that use in your immediate future, it doesn't mean
it won't occur.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Re: I need a fresh look at storing variables in MySQL

2010-03-15 Thread Colin Guthrie
'Twas brillig, and Jochem Maas at 14/03/10 23:56 did gyre and gimble:
> Op 3/14/10 11:45 AM, Ashley Sheridan schreef:
>> On Sun, 2010-03-14 at 12:25 +0100, Rene Veerman wrote:
>>
>>> On Sun, Mar 14, 2010 at 12:24 PM, Rene Veerman  wrote:

 I'd love to have a copy of whatever function you use to filter out bad
 HTML/js/flash for use cases where users are allowed to enter html.
 I'm aware of strip_tags() "allowed tags" param, but haven't got a good list
 for it.

>>>
>>> oh, and even  tags can be used for cookie-stuffing on many browsers..
>>>
>>
>>
>> Yes, and you call strip_tags() before the data goes to the browser for
>> display, not before it gets inserted into the database. Essentially, you
>> need to keep as much original information as possible.
> 
> I disagree with both you. I'm like that :)
> 
> let's assume we're not talking about data that is allowed to contain HTML,
> in such cases I would do a strip_tags() on the incoming data then compare
> the output ofstrip_tags() to the original input ... if they don't match then
> I would log the problem and refuse to input the data at all.
> 
> using strip_tags() on a piece of data everytime you output it if you know
> that it shouldn't contain any in the first is a waste of resources ... this
> does assume that you can trust the data source ... which in the case of a 
> database
> that you control should be the case.

I used to think like that too, but I've relatively recently changed my
position.

While it's not as extreme an example, I used to keep data in the
database *after* I had processed it with htmlspecialchars() (not quite
the same as strip_tags, but the principle is the same).

The issue I had was that over time, I've found the need to output to
other formats - e.g. spread sheets, plain text emails, PDFs etc. in
which case this pre-encoded format is a pain and I have to call
html_entity_decode() to reverse the htmlspecialchars() I did in the
first place. This is a royal pain in the bum and it's really ugly in the
code, remembering what format the data is in in order to process it
appropriately at the right points.

Nowadays I work rather differently and always escape at the point of
output (this does not exclude filtering at the point of input too, but I
do not keep things encoded any longer - I keep it raw).

Any half way decently designed caching layer will prevent any major
impact from escaping at the point of output anyway.

Now you could argue that encoding at the save point and reversing the
encoding when needed is still a better approach and I wont argue too
heavily, but for the sake of my sanity I'm much happier working the way
I do now. The view layers are very clearly escaping everything that
needs escaping and no logic for the "is it or is it not already escaped"
leaks into this layer.

(I appreciate strip tags and htmlspecialchars are not the same and my
general usage may not apply to a pure striptags usage).

> at any rate, strip_tags() doesn't belong in an 'anti-sql-injection' routine as
> it has nothing to do with sql injection at all.

Indeed, it's more about XSS and CSRF rather than SQL injection.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



Re: [PHP] Event Handling

2010-03-15 Thread Jochem Maas
Op 3/15/10 12:00 PM, David Hutto schreef:
> On Mon, Mar 15, 2010 at 7:31 AM, Jochem Maas  wrote:
> 
>> Op 3/15/10 8:24 AM, Midhun Girish schreef:
>>> Hi ,
>>> Just as David Hutto has said,What you need is the cronjob... Make a
>> script
>>> say "check.php" which checks the db to see if any new entries are made...
>>> and if yes send the mail ...
>>>
>>> now using the cronjob feature in linux os(which will be provided as a
>>> service in your linux hosting cpanel), set a cronjob which calls the "
>>> http://www.yoursite.com/check.php"; URL every minute now a trigger
>> will
>>> be there every minute to the script and the emails will be send
>> irrespective
>>> of whether anyone is browsing the site or not hope it is clear...
>>>
>>
>> use cron - yes
>> have cron call a web URL - no, instead just call the script via the php CLI
>> sapi,
>> e.g. a cmdline as follows in cron:
>>
>> /usr/env php /path/to/your/check.php &> /dev/null
>>
> 
> 
> I do believe removing the /dev/null will send error messages during the
> building of the script, correct?
> 

the '&> /dev/null' redirects all output - I kind of make the assumption that the
script would be logging stuff to a file or something when in production.

so, yes, remove the redirection when your developing/testing the script.



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



Re: [PHP] Event Handling

2010-03-15 Thread Rene Veerman
+1..

Assuming you have had a 100% success rate of getting cars to their
destination on time for years;

If for some reason you can't set up a cron job, you _could_ have a
browser do the cron-ing for you; a page with an ajax script that kicks
off the check-for-recent-events script on the server.
granularity in milliseconds :)
if you have a windowing system on the server, you can run that browser
script on the server ;)

But if i were boss of such an operation, i'd have all cars outfitted
with gps, and have the gps monitoring app call up urls on my server to
indicate car status & location.
i agree this could be non-trivial, as something has to compare car
location gps coordinates to dropoff location coordinates, and if there
are many cars on the road, it's less than ideal to have the php server
do all the coordinate checking.
But there would be many benefits to a gps installation (with a "panic"
and "car-trouble" button in the vehicle).

RFID tags also might be a solution, one that could cost less to
install and operate.

On Mon, Mar 15, 2010 at 10:17 AM, Lester Caine  wrote:
> Alex Major wrote:
>>
>> I'm currently looking at building a web application, however I've run into
>> an area of development I've not come across before. The web site in its
>> basic form allows users to send cars from a point and then the car will
>> arrive at another point. When the car is set on its way, the start time,
>> travel duration and end time are all known and stored in a MySQL database,
>
> The question HAS to be asked ... how do you know the actual travel time ;)
> I think I would be expecting to have to enter something on arrival 
>
> --
> Lester Caine - G8HFL
> -
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> 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



Re: [PHP] Event Handling

2010-03-15 Thread David Hutto
On Mon, Mar 15, 2010 at 7:31 AM, Jochem Maas  wrote:

> Op 3/15/10 8:24 AM, Midhun Girish schreef:
> > Hi ,
> > Just as David Hutto has said,What you need is the cronjob... Make a
> script
> > say "check.php" which checks the db to see if any new entries are made...
> > and if yes send the mail ...
> >
> > now using the cronjob feature in linux os(which will be provided as a
> > service in your linux hosting cpanel), set a cronjob which calls the "
> > http://www.yoursite.com/check.php"; URL every minute now a trigger
> will
> > be there every minute to the script and the emails will be send
> irrespective
> > of whether anyone is browsing the site or not hope it is clear...
> >
>
> use cron - yes
> have cron call a web URL - no, instead just call the script via the php CLI
> sapi,
> e.g. a cmdline as follows in cron:
>
> /usr/env php /path/to/your/check.php &> /dev/null
>


I do believe removing the /dev/null will send error messages during the
building of the script, correct?


Re: [PHP] Event Handling

2010-03-15 Thread Jochem Maas
Op 3/15/10 8:24 AM, Midhun Girish schreef:
> Hi ,
> Just as David Hutto has said,What you need is the cronjob... Make a script
> say "check.php" which checks the db to see if any new entries are made...
> and if yes send the mail ...
> 
> now using the cronjob feature in linux os(which will be provided as a
> service in your linux hosting cpanel), set a cronjob which calls the "
> http://www.yoursite.com/check.php"; URL every minute now a trigger will
> be there every minute to the script and the emails will be send irrespective
> of whether anyone is browsing the site or not hope it is clear...
> 

use cron - yes
have cron call a web URL - no, instead just call the script via the php CLI 
sapi,
e.g. a cmdline as follows in cron:

/usr/env php /path/to/your/check.php &> /dev/null

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



Re: [PHP] ldap_bind() connectivity

2010-03-15 Thread chamila gayan
 if you sure you have valid credentials check your account and sure it
hasn't locked, perhaps it may locked.

On Mon, Mar 15, 2010 at 2:42 PM, Peter Lind  wrote:

> You might want to check what the function outputs with:
>
> var_dump($ldapbind);
>
> after the call to ldap_bing(). That way you'll know what actually got
> returned from the function.
>
> On 15 March 2010 09:54, Ashley M. Kirchner  wrote:
> > Thanks to Jochem Mass for helping earlier to the string splitting.  Works
> > great (so far).  Now on to my next problem, which has to do with
> > ldap_bind().
> >
> >
> >
> > I have the following code:
> >
> >
> >
> >  $ldapconn = @ldap_connect($adServer);
> >
> >  $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
> >
> >
> >
> >  if ($ldapbind) {
> >
> >/** Successful authentication **/
> >
> >$_SESSION['username'] = $username;
> >
> >$_SESSION['password'] = $password;
> >
> >  } else {
> >
> >/** Authentication failure **/
> >
> >$form->setError($field, "« Invalid username or password
> > »");
> >
> >  }
> >
> >  ldap_unbind($ldapconn);
> >
> >
> >
> > The problem with this is that if the ldap_bind() fails in the second
> line,
> > it instantly spits text out to the browser:
> >
> >
> >
> > Warning: ldap_bind() [function.ldap-bind
> >  ]: Unable
> to
> > bind to server: Invalid credentials in /home/contest/include/session.php
> on
> > line 351
> >
> >
> >
> > And because it does that, it never reaches the if routine right below it
> and
> > everything just bombs.  If I call it with @ldap_bind($ldapconn .) nothing
> > happens.  The error message gets suppressed but it also doesn't do
> anything
> > with the if routine afterwards.  It's almost like $ldapbind isn't getting
> > set at all.
> >
> >
> >
> > What am I missing here?
> >
> >
>
>
>
> --
> 
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> Flickr: http://www.flickr.com/photos/fake51
> BeWelcome: Fake51
> Couchsurfing: Fake51
> 
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Event Handling

2010-03-15 Thread David Hutto
On Mon, Mar 15, 2010 at 5:17 AM, Lester Caine  wrote:

> Alex Major wrote:
>
>> I'm currently looking at building a web application, however I've run into
>> an area of development I've not come across before. The web site in its
>> basic form allows users to send cars from a point and then the car will
>> arrive at another point. When the car is set on its way, the start time,
>> travel duration and end time are all known and stored in a MySQL database,
>>
>
> The question HAS to be asked ... how do you know the actual travel time ;)
> I think I would be expecting to have to enter something on arrival 
>
> --
> Lester Caine - G8HFL
> -
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You could judge the ETA if the shipping was tracked through GPS.


Re: [PHP] Event Handling

2010-03-15 Thread Lester Caine

Alex Major wrote:

I'm currently looking at building a web application, however I've run into
an area of development I've not come across before. The web site in its
basic form allows users to send cars from a point and then the car will
arrive at another point. When the car is set on its way, the start time,
travel duration and end time are all known and stored in a MySQL database,


The question HAS to be asked ... how do you know the actual travel time ;)
I think I would be expecting to have to enter something on arrival 

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] Re: Event Handling

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 14:40 +0530, Midhun Girish wrote:

> ok so we have a script which checks if any cars have arrived within
> last 10 minutes... if yes, a mail will be send. suppose the server
> fails for 30 minutes so when the cron comes next time, we will
> have to check for cars which arrived within last 40 minutes and not
> 10.. right...  so how will we set a time limit in the script? its
> variable na.. but the flag is ok.. you can send a mail to all db
> entries which have flag 0 and then update the flag to 1. 
> 
> 
> Midhun Girish
> Development Lead
> MobAlive Technologies
> 
> 
> 
> On Mon, Mar 15, 2010 at 2:29 PM, Ashley Sheridan
>  wrote:
> 
> 
> On Mon, 2010-03-15 at 14:28 +0530, Midhun Girish wrote: 
> 
> > hey ash,
> > 
> > do we need both of those checks ? ie the time and the flag? i think 
> they
> > both do the same thing ie prevent duplicates.. am i right? and i 
> think flag
> > would be a more reliable method coz it will ensure that the email 
> will be
> > send even if the cron fails to execute for some time,
> > 
> > Midhun Girish
> > Development Lead
> > MobAlive Technologies
> > Trivandrum
> > 
> > 
> > On Mon, Mar 15, 2010 at 2:13 PM, Ashley Sheridan
> > wrote:
> > 
> > > On Mon, 2010-03-15 at 18:07 +1030, David Robley wrote:
> > >
> > > > Alex Major wrote:
> > > >
> > > > > Greetings all,
> > > > >
> > > > > I'm currently looking at building a web application, however 
> I've run
> > > into
> > > > > an area of development I've not come across before. The web 
> site in its
> > > > > basic form allows users to send cars from a point and then 
> the car will
> > > > > arrive at another point. When the car is set on its way, the 
> start
> > > time,
> > > > > travel duration and end time are all known and stored in a 
> MySQL
> > > database,
> > > > > what I would like to happen is that an event is triggered on 
> the server
> > > at
> > > > > the end time and then an e-mail is sent to the user. This 
> should happen
> > > > > regardless of whether someone is browsing the website or not.
> > > > >
> > > > > I don't believe that I'll be able to solely use PHP, I have 
> spent the
> > > > > afternoon trying to look at potential solutions but I have to 
> admit
> > > I've
> > > > > drawn a blank. Google hasn't been helpful (64 pages so far), 
> as any
> > > > > searches related to "event handling" bring up a load of 
> JavaScript
> > > > > tutorials/help for 'onclick' events etc. I have searched 
> through the
> > > PHP
> > > > > documentation and found "libevent"
> > > > > (http://www.php.net/manual/en/book.libevent.php ), I don't 
> believe
> > > that is
> > > > > what I require (although in all honesty the lack of 
> documentation on it
> > > > > means I'm quite in the dark as to its purpose). Another 
> potential
> > > > > candidate I came across was a PHP/Java bridge
> > > > > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I 
> could use
> > > the
> > > > > java virtual machine, register events with it and then 
> callback PHP
> > > > > scripts, although this seems extremely long winded.
> > > > >
> > > > > I was hoping that someone might have some experience with 
> this kind of
> > > > > issue and could point me in the right direction. I'm sure 
> I've missed
> > > > > something right in front of me.
> > > > >
> > > > > Alex.
> > > >
> > > > I think what you want is something to trigger a php script every
> > > > $period-of-time; if your host supports it, cron is the means of 
> executing
> > > > an application at regular intervals down to a minute 
> granularity. There
> > > are
> > > > some web-based cron services also, but they may not have the 
> same
> > > > granularity as a locally based cron.
> > > >
> > > >
> > > > Cheers
> > > > --
> > > > David Robley
> > > >
> > > > "Wow!" barked Tom, with a bow.
> > > > Today is Prickle-Prickle, the 1st day of Discord in the YOLD 
> 3176.
> > > >
> > > >
> > >
> > >
> > > You could store the end times in the database, and cron can run a 
> script
> > > that will check each of these times to find any that are within x
> > > minutes that an email hasn't been sent out for. You'll need an 
> extra
> > > field to indicate whether an email has been sent or not.
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.

Re: [PHP] ldap_bind() connectivity

2010-03-15 Thread Peter Lind
You might want to check what the function outputs with:

var_dump($ldapbind);

after the call to ldap_bing(). That way you'll know what actually got
returned from the function.

On 15 March 2010 09:54, Ashley M. Kirchner  wrote:
> Thanks to Jochem Mass for helping earlier to the string splitting.  Works
> great (so far).  Now on to my next problem, which has to do with
> ldap_bind().
>
>
>
> I have the following code:
>
>
>
>      $ldapconn = @ldap_connect($adServer);
>
>      $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);
>
>
>
>      if ($ldapbind) {
>
>        /** Successful authentication **/
>
>        $_SESSION['username'] = $username;
>
>        $_SESSION['password'] = $password;
>
>      } else {
>
>        /** Authentication failure **/
>
>        $form->setError($field, "« Invalid username or password
> »");
>
>      }
>
>      ldap_unbind($ldapconn);
>
>
>
> The problem with this is that if the ldap_bind() fails in the second line,
> it instantly spits text out to the browser:
>
>
>
> Warning: ldap_bind() [function.ldap-bind
>  ]: Unable to
> bind to server: Invalid credentials in /home/contest/include/session.php on
> line 351
>
>
>
> And because it does that, it never reaches the if routine right below it and
> everything just bombs.  If I call it with @ldap_bind($ldapconn .) nothing
> happens.  The error message gets suppressed but it also doesn't do anything
> with the if routine afterwards.  It's almost like $ldapbind isn't getting
> set at all.
>
>
>
> What am I missing here?
>
>



-- 

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51


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



Re: [PHP] Re: Event Handling

2010-03-15 Thread Midhun Girish
ok so we have a script which checks if any cars have arrived within last 10
minutes... if yes, a mail will be send. suppose the server fails for 30
minutes so when the cron comes next time, we will have to check for cars
which arrived within last 40 minutes and not 10.. right...  so how will we
set a time limit in the script? its variable na.. but the flag is ok.. you
can send a mail to all db entries which have flag 0 and then update the flag
to 1.


Midhun Girish
Development Lead
MobAlive Technologies


On Mon, Mar 15, 2010 at 2:29 PM, Ashley Sheridan
wrote:

>  On Mon, 2010-03-15 at 14:28 +0530, Midhun Girish wrote:
>
> hey ash,
>
> do we need both of those checks ? ie the time and the flag? i think they
> both do the same thing ie prevent duplicates.. am i right? and i think flag
> would be a more reliable method coz it will ensure that the email will be
> send even if the cron fails to execute for some time,
>
> Midhun Girish
> Development Lead
> MobAlive Technologies
> Trivandrum
>
>
> On Mon, Mar 15, 2010 at 2:13 PM, Ashley Sheridan
> wrote:
>
> > On Mon, 2010-03-15 at 18:07 +1030, David Robley wrote:
> >
> > > Alex Major wrote:
> > >
> > > > Greetings all,
> > > >
> > > > I'm currently looking at building a web application, however I've run
> > into
> > > > an area of development I've not come across before. The web site in its
> > > > basic form allows users to send cars from a point and then the car will
> > > > arrive at another point. When the car is set on its way, the start
> > time,
> > > > travel duration and end time are all known and stored in a MySQL
> > database,
> > > > what I would like to happen is that an event is triggered on the server
> > at
> > > > the end time and then an e-mail is sent to the user. This should happen
> > > > regardless of whether someone is browsing the website or not.
> > > >
> > > > I don't believe that I'll be able to solely use PHP, I have spent the
> > > > afternoon trying to look at potential solutions but I have to admit
> > I've
> > > > drawn a blank. Google hasn't been helpful (64 pages so far), as any
> > > > searches related to "event handling" bring up a load of JavaScript
> > > > tutorials/help for 'onclick' events etc. I have searched through the
> > PHP
> > > > documentation and found "libevent"
> > > > (http://www.php.net/manual/en/book.libevent.php ), I don't believe
> > that is
> > > > what I require (although in all honesty the lack of documentation on it
> > > > means I'm quite in the dark as to its purpose). Another potential
> > > > candidate I came across was a PHP/Java bridge
> > > > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use
> > the
> > > > java virtual machine, register events with it and then callback PHP
> > > > scripts, although this seems extremely long winded.
> > > >
> > > > I was hoping that someone might have some experience with this kind of
> > > > issue and could point me in the right direction. I'm sure I've missed
> > > > something right in front of me.
> > > >
> > > > Alex.
> > >
> > > I think what you want is something to trigger a php script every
> > > $period-of-time; if your host supports it, cron is the means of executing
> > > an application at regular intervals down to a minute granularity. There
> > are
> > > some web-based cron services also, but they may not have the same
> > > granularity as a locally based cron.
> > >
> > >
> > > Cheers
> > > --
> > > David Robley
> > >
> > > "Wow!" barked Tom, with a bow.
> > > Today is Prickle-Prickle, the 1st day of Discord in the YOLD 3176.
> > >
> > >
> >
> >
> > You could store the end times in the database, and cron can run a script
> > that will check each of these times to find any that are within x
> > minutes that an email hasn't been sent out for. You'll need an extra
> > field to indicate whether an email has been sent or not.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
>
> Consider a cron script that runs every 10 minutes. You'll want to check the
> db for cars that are due to arrive within just over 10 minutes. The flag is
> there more for you own clarification that the email has been sent. What if
> the cron fails, or you restart your server, or the script your cron calls is
> just running a little slowly?
>
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


Re: [PHP] Re: Event Handling

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 14:28 +0530, Midhun Girish wrote:

> hey ash,
> 
> do we need both of those checks ? ie the time and the flag? i think they
> both do the same thing ie prevent duplicates.. am i right? and i think flag
> would be a more reliable method coz it will ensure that the email will be
> send even if the cron fails to execute for some time,
> 
> Midhun Girish
> Development Lead
> MobAlive Technologies
> Trivandrum
> 
> 
> On Mon, Mar 15, 2010 at 2:13 PM, Ashley Sheridan
> wrote:
> 
> > On Mon, 2010-03-15 at 18:07 +1030, David Robley wrote:
> >
> > > Alex Major wrote:
> > >
> > > > Greetings all,
> > > >
> > > > I'm currently looking at building a web application, however I've run
> > into
> > > > an area of development I've not come across before. The web site in its
> > > > basic form allows users to send cars from a point and then the car will
> > > > arrive at another point. When the car is set on its way, the start
> > time,
> > > > travel duration and end time are all known and stored in a MySQL
> > database,
> > > > what I would like to happen is that an event is triggered on the server
> > at
> > > > the end time and then an e-mail is sent to the user. This should happen
> > > > regardless of whether someone is browsing the website or not.
> > > >
> > > > I don't believe that I'll be able to solely use PHP, I have spent the
> > > > afternoon trying to look at potential solutions but I have to admit
> > I've
> > > > drawn a blank. Google hasn't been helpful (64 pages so far), as any
> > > > searches related to "event handling" bring up a load of JavaScript
> > > > tutorials/help for 'onclick' events etc. I have searched through the
> > PHP
> > > > documentation and found "libevent"
> > > > (http://www.php.net/manual/en/book.libevent.php ), I don't believe
> > that is
> > > > what I require (although in all honesty the lack of documentation on it
> > > > means I'm quite in the dark as to its purpose). Another potential
> > > > candidate I came across was a PHP/Java bridge
> > > > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use
> > the
> > > > java virtual machine, register events with it and then callback PHP
> > > > scripts, although this seems extremely long winded.
> > > >
> > > > I was hoping that someone might have some experience with this kind of
> > > > issue and could point me in the right direction. I'm sure I've missed
> > > > something right in front of me.
> > > >
> > > > Alex.
> > >
> > > I think what you want is something to trigger a php script every
> > > $period-of-time; if your host supports it, cron is the means of executing
> > > an application at regular intervals down to a minute granularity. There
> > are
> > > some web-based cron services also, but they may not have the same
> > > granularity as a locally based cron.
> > >
> > >
> > > Cheers
> > > --
> > > David Robley
> > >
> > > "Wow!" barked Tom, with a bow.
> > > Today is Prickle-Prickle, the 1st day of Discord in the YOLD 3176.
> > >
> > >
> >
> >
> > You could store the end times in the database, and cron can run a script
> > that will check each of these times to find any that are within x
> > minutes that an email hasn't been sent out for. You'll need an extra
> > field to indicate whether an email has been sent or not.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >


Consider a cron script that runs every 10 minutes. You'll want to check
the db for cars that are due to arrive within just over 10 minutes. The
flag is there more for you own clarification that the email has been
sent. What if the cron fails, or you restart your server, or the script
your cron calls is just running a little slowly?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: Event Handling

2010-03-15 Thread Midhun Girish
hey ash,

do we need both of those checks ? ie the time and the flag? i think they
both do the same thing ie prevent duplicates.. am i right? and i think flag
would be a more reliable method coz it will ensure that the email will be
send even if the cron fails to execute for some time,

Midhun Girish
Development Lead
MobAlive Technologies
Trivandrum


On Mon, Mar 15, 2010 at 2:13 PM, Ashley Sheridan
wrote:

> On Mon, 2010-03-15 at 18:07 +1030, David Robley wrote:
>
> > Alex Major wrote:
> >
> > > Greetings all,
> > >
> > > I'm currently looking at building a web application, however I've run
> into
> > > an area of development I've not come across before. The web site in its
> > > basic form allows users to send cars from a point and then the car will
> > > arrive at another point. When the car is set on its way, the start
> time,
> > > travel duration and end time are all known and stored in a MySQL
> database,
> > > what I would like to happen is that an event is triggered on the server
> at
> > > the end time and then an e-mail is sent to the user. This should happen
> > > regardless of whether someone is browsing the website or not.
> > >
> > > I don't believe that I'll be able to solely use PHP, I have spent the
> > > afternoon trying to look at potential solutions but I have to admit
> I've
> > > drawn a blank. Google hasn't been helpful (64 pages so far), as any
> > > searches related to "event handling" bring up a load of JavaScript
> > > tutorials/help for 'onclick' events etc. I have searched through the
> PHP
> > > documentation and found "libevent"
> > > (http://www.php.net/manual/en/book.libevent.php ), I don't believe
> that is
> > > what I require (although in all honesty the lack of documentation on it
> > > means I'm quite in the dark as to its purpose). Another potential
> > > candidate I came across was a PHP/Java bridge
> > > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use
> the
> > > java virtual machine, register events with it and then callback PHP
> > > scripts, although this seems extremely long winded.
> > >
> > > I was hoping that someone might have some experience with this kind of
> > > issue and could point me in the right direction. I'm sure I've missed
> > > something right in front of me.
> > >
> > > Alex.
> >
> > I think what you want is something to trigger a php script every
> > $period-of-time; if your host supports it, cron is the means of executing
> > an application at regular intervals down to a minute granularity. There
> are
> > some web-based cron services also, but they may not have the same
> > granularity as a locally based cron.
> >
> >
> > Cheers
> > --
> > David Robley
> >
> > "Wow!" barked Tom, with a bow.
> > Today is Prickle-Prickle, the 1st day of Discord in the YOLD 3176.
> >
> >
>
>
> You could store the end times in the database, and cron can run a script
> that will check each of these times to find any that are within x
> minutes that an email hasn't been sent out for. You'll need an extra
> field to indicate whether an email has been sent or not.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


[PHP] ldap_bind() connectivity

2010-03-15 Thread Ashley M. Kirchner
Thanks to Jochem Mass for helping earlier to the string splitting.  Works
great (so far).  Now on to my next problem, which has to do with
ldap_bind().

 

I have the following code:

 

  $ldapconn = @ldap_connect($adServer);

  $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);

 

  if ($ldapbind) {

/** Successful authentication **/

$_SESSION['username'] = $username;

$_SESSION['password'] = $password;

  } else {

/** Authentication failure **/

$form->setError($field, "« Invalid username or password
»");

  }

  ldap_unbind($ldapconn);

 

The problem with this is that if the ldap_bind() fails in the second line,
it instantly spits text out to the browser:

 

Warning: ldap_bind() [function.ldap-bind
 ]: Unable to
bind to server: Invalid credentials in /home/contest/include/session.php on
line 351

 

And because it does that, it never reaches the if routine right below it and
everything just bombs.  If I call it with @ldap_bind($ldapconn .) nothing
happens.  The error message gets suppressed but it also doesn't do anything
with the if routine afterwards.  It's almost like $ldapbind isn't getting
set at all.

 

What am I missing here?



Re: [PHP] Re: Event Handling

2010-03-15 Thread Ashley Sheridan
On Mon, 2010-03-15 at 18:07 +1030, David Robley wrote:

> Alex Major wrote:
> 
> > Greetings all,
> > 
> > I'm currently looking at building a web application, however I've run into
> > an area of development I've not come across before. The web site in its
> > basic form allows users to send cars from a point and then the car will
> > arrive at another point. When the car is set on its way, the start time,
> > travel duration and end time are all known and stored in a MySQL database,
> > what I would like to happen is that an event is triggered on the server at
> > the end time and then an e-mail is sent to the user. This should happen
> > regardless of whether someone is browsing the website or not.
> > 
> > I don't believe that I'll be able to solely use PHP, I have spent the
> > afternoon trying to look at potential solutions but I have to admit I've
> > drawn a blank. Google hasn't been helpful (64 pages so far), as any
> > searches related to "event handling" bring up a load of JavaScript
> > tutorials/help for 'onclick' events etc. I have searched through the PHP
> > documentation and found "libevent"
> > (http://www.php.net/manual/en/book.libevent.php ), I don't believe that is
> > what I require (although in all honesty the lack of documentation on it
> > means I'm quite in the dark as to its purpose). Another potential
> > candidate I came across was a PHP/Java bridge
> > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use the
> > java virtual machine, register events with it and then callback PHP
> > scripts, although this seems extremely long winded.
> > 
> > I was hoping that someone might have some experience with this kind of
> > issue and could point me in the right direction. I'm sure I've missed
> > something right in front of me.
> > 
> > Alex.
> 
> I think what you want is something to trigger a php script every
> $period-of-time; if your host supports it, cron is the means of executing
> an application at regular intervals down to a minute granularity. There are
> some web-based cron services also, but they may not have the same
> granularity as a locally based cron.
> 
> 
> Cheers
> -- 
> David Robley
> 
> "Wow!" barked Tom, with a bow.
> Today is Prickle-Prickle, the 1st day of Discord in the YOLD 3176. 
> 
> 


You could store the end times in the database, and cron can run a script
that will check each of these times to find any that are within x
minutes that an email hasn't been sent out for. You'll need an extra
field to indicate whether an email has been sent or not.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Event Handling

2010-03-15 Thread Midhun Girish
Hi ,
Just as David Hutto has said,What you need is the cronjob... Make a script
say "check.php" which checks the db to see if any new entries are made...
and if yes send the mail ...

now using the cronjob feature in linux os(which will be provided as a
service in your linux hosting cpanel), set a cronjob which calls the "
http://www.yoursite.com/check.php"; URL every minute now a trigger will
be there every minute to the script and the emails will be send irrespective
of whether anyone is browsing the site or not hope it is clear...

Midhun Girish
Development Lead
MobAlive Technologies



On Mon, Mar 15, 2010 at 1:10 PM, David Hutto  wrote:
>
> --- On *Mon, 3/15/10, David Hutto * wrote:
>
> From: David Hutto 
> Subject: Re: [PHP] Event Handling
> To: php-general@lists.php.net, "Alex Major" 
> Date: Monday, March 15, 2010, 3:34 AM
>
>
>
> --- On Mon, 3/15/10, Alex Major
> http://us.mc453.mail.yahoo.com/mc/compose?to=...@allydm.co.uk>>
> wrote:
>
> > From: Alex Major http://us.mc453.mail.yahoo.com/mc/compose?to=...@allydm.co.uk>
> >
> > Subject: [PHP] Event Handling
> > To: php-general@lists.php.net<
http://us.mc453.mail.yahoo.com/mc/compose?to=php-gene...@lists.php.net>
> > Date: Monday, March 15, 2010, 2:59 AM
> > Greetings all,
> >
> > I'm currently looking at building a web application,
> > however I've run into
> > an area of development I've not come across before. The web
> > site in its
> > basic form allows users to send cars from a point and then
> > the car will
> > arrive at another point. When the car is set on its way,
> > the start time,
> > travel duration and end time are all known and stored in a
> > MySQL database,
> > what I would like to happen is that an event is triggered
> > on the server at
> > the end time and then an e-mail is sent to the user. This
> > should happen
> > regardless of whether someone is browsing the website or
> > not.
> >
> > I don't believe that I'll be able to solely use PHP, I have
> > spent the
> > afternoon trying to look at potential solutions but I have
> > to admit I've
> > drawn a blank. Google hasn't been helpful (64 pages so
> > far), as any searches
> > related to "event handling" bring up a load of JavaScript
> > tutorials/help for
> > 'onclick' events etc. I have searched through the PHP
> > documentation and
> > found "libevent" (http://www.php.net/manual/en/book.libevent.php ), I
> > don't
> > believe that is what I require (although in all honesty the
> > lack of
> > documentation on it means I'm quite in the dark as to its
> > purpose). Another
> > potential candidate I came across was a PHP/Java bridge
> > (http://php-java-bridge.sourceforge.net/pjb/ ), whereby
> > I could use the java
> > virtual machine, register events with it and then callback
> > PHP scripts,
> > although this seems extremely long winded.
> >
> > I was hoping that someone might have some experience with
> > this kind of issue
> > and could point me in the right direction. I'm sure I've
> > missed something
> > right in front of me.
> >
> > Alex.
> >
> >
>
> I'm a noob at php myself, but what you might want to look at is cron jobs
> and autoresponders. Here's an address to one I've messed with before:
> infinite.ibasics.biz/ I believe it uses cron jobs, I've messed with a lot
so
> it's hard to recall.
>
> You might want to have the web app insert the new info in the tables, and
> have the cron job and script do the rest.
>
> David


Re: [PHP] Event Handling

2010-03-15 Thread David Hutto
--- On *Mon, 3/15/10, David Hutto * wrote:

From: David Hutto 
Subject: Re: [PHP] Event Handling
To: php-general@lists.php.net, "Alex Major" 
Date: Monday, March 15, 2010, 3:34 AM



--- On Mon, 3/15/10, Alex Major
http://us.mc453.mail.yahoo.com/mc/compose?to=...@allydm.co.uk>>
wrote:

> From: Alex Major 
> http://us.mc453.mail.yahoo.com/mc/compose?to=...@allydm.co.uk>
>
> Subject: [PHP] Event Handling
> To: 
> php-general@lists.php.net
> Date: Monday, March 15, 2010, 2:59 AM
> Greetings all,
>
> I'm currently looking at building a web application,
> however I've run into
> an area of development I've not come across before. The web
> site in its
> basic form allows users to send cars from a point and then
> the car will
> arrive at another point. When the car is set on its way,
> the start time,
> travel duration and end time are all known and stored in a
> MySQL database,
> what I would like to happen is that an event is triggered
> on the server at
> the end time and then an e-mail is sent to the user. This
> should happen
> regardless of whether someone is browsing the website or
> not.
>
> I don't believe that I'll be able to solely use PHP, I have
> spent the
> afternoon trying to look at potential solutions but I have
> to admit I've
> drawn a blank. Google hasn't been helpful (64 pages so
> far), as any searches
> related to "event handling" bring up a load of JavaScript
> tutorials/help for
> 'onclick' events etc. I have searched through the PHP
> documentation and
> found "libevent" (http://www.php.net/manual/en/book.libevent.php ), I
> don't
> believe that is what I require (although in all honesty the
> lack of
> documentation on it means I'm quite in the dark as to its
> purpose). Another
> potential candidate I came across was a PHP/Java bridge
> (http://php-java-bridge.sourceforge.net/pjb/ ), whereby
> I could use the java
> virtual machine, register events with it and then callback
> PHP scripts,
> although this seems extremely long winded.
>
> I was hoping that someone might have some experience with
> this kind of issue
> and could point me in the right direction. I'm sure I've
> missed something
> right in front of me.
>
> Alex.
>
>

I'm a noob at php myself, but what you might want to look at is cron jobs
and autoresponders. Here's an address to one I've messed with before:
infinite.ibasics.biz/ I believe it uses cron jobs, I've messed with a lot so
it's hard to recall.

You might want to have the web app insert the new info in the tables, and
have the cron job and script do the rest.

David


[PHP] Re: Event Handling

2010-03-15 Thread David Robley
Alex Major wrote:

> Greetings all,
> 
> I'm currently looking at building a web application, however I've run into
> an area of development I've not come across before. The web site in its
> basic form allows users to send cars from a point and then the car will
> arrive at another point. When the car is set on its way, the start time,
> travel duration and end time are all known and stored in a MySQL database,
> what I would like to happen is that an event is triggered on the server at
> the end time and then an e-mail is sent to the user. This should happen
> regardless of whether someone is browsing the website or not.
> 
> I don't believe that I'll be able to solely use PHP, I have spent the
> afternoon trying to look at potential solutions but I have to admit I've
> drawn a blank. Google hasn't been helpful (64 pages so far), as any
> searches related to "event handling" bring up a load of JavaScript
> tutorials/help for 'onclick' events etc. I have searched through the PHP
> documentation and found "libevent"
> (http://www.php.net/manual/en/book.libevent.php ), I don't believe that is
> what I require (although in all honesty the lack of documentation on it
> means I'm quite in the dark as to its purpose). Another potential
> candidate I came across was a PHP/Java bridge
> (http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use the
> java virtual machine, register events with it and then callback PHP
> scripts, although this seems extremely long winded.
> 
> I was hoping that someone might have some experience with this kind of
> issue and could point me in the right direction. I'm sure I've missed
> something right in front of me.
> 
> Alex.

I think what you want is something to trigger a php script every
$period-of-time; if your host supports it, cron is the means of executing
an application at regular intervals down to a minute granularity. There are
some web-based cron services also, but they may not have the same
granularity as a locally based cron.


Cheers
-- 
David Robley

"Wow!" barked Tom, with a bow.
Today is Prickle-Prickle, the 1st day of Discord in the YOLD 3176. 


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



[PHP] Event Handling

2010-03-15 Thread Alex Major
Greetings all,

I'm currently looking at building a web application, however I've run into
an area of development I've not come across before. The web site in its
basic form allows users to send cars from a point and then the car will
arrive at another point. When the car is set on its way, the start time,
travel duration and end time are all known and stored in a MySQL database,
what I would like to happen is that an event is triggered on the server at
the end time and then an e-mail is sent to the user. This should happen
regardless of whether someone is browsing the website or not.

I don't believe that I'll be able to solely use PHP, I have spent the
afternoon trying to look at potential solutions but I have to admit I've
drawn a blank. Google hasn't been helpful (64 pages so far), as any searches
related to "event handling" bring up a load of JavaScript tutorials/help for
'onclick' events etc. I have searched through the PHP documentation and
found "libevent" (http://www.php.net/manual/en/book.libevent.php ), I don't
believe that is what I require (although in all honesty the lack of
documentation on it means I'm quite in the dark as to its purpose). Another
potential candidate I came across was a PHP/Java bridge
(http://php-java-bridge.sourceforge.net/pjb/ ), whereby I could use the java
virtual machine, register events with it and then callback PHP scripts,
although this seems extremely long winded.

I was hoping that someone might have some experience with this kind of issue
and could point me in the right direction. I'm sure I've missed something
right in front of me. 

Alex.