php-general Digest 25 Jul 2006 19:55:59 -0000 Issue 4258

Topics (messages 239755 through 239778):

captcha and blacklist
        239755 by: nicolas figaro
        239771 by: Jon Anderson

convert byte to MB
        239756 by: weetat
        239757 by: André Medeiros
        239758 by: Andrew Brampton
        239759 by: cajbecu
        239761 by: Andrei
        239762 by: Austin Denyer
        239768 by: zerof

[on the wrong end of someone else's bad day] Re: [PHP] convert byte to MB
        239760 by: Jochem Maas

Re: select option and php
        239763 by: Jochem Maas

Re: Stumped! 4.x to 5.1 problem!!
        239764 by: Jochem Maas
        239765 by: markw.mohawksoft.com

Re: xml v php question
        239766 by: David Tulloh
        239767 by: tedd
        239777 by: Kevin Waterson
        239778 by: Larry Garfield

Re: PAYMENT TRANSACTION
        239769 by: BBC

Re: SQL Result Set -> HTML Table Fragment (but Simple)
        239770 by: tedd

Error Reporting for file commands
        239772 by: James Nunnerley
        239773 by: Jon Anderson

Re: Spam:[PHP] Error Reporting for file commands
        239774 by: James Nunnerley
        239775 by: Jochem Maas

Lots of queries!
        239776 by: Philip Thompson

Administrivia:

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

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

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


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

I'd like to set a captcha on my web server(s).

The code works quite fine, but I'd like to blacklist (for an amount of time) the ips that failed
with the captcha x times.

The web server works with an SQL server, but I cannot ask the page to check for each IP
with a request to the database.

I can't also store the blocked IP to a filename on the server, because the site is served by several
http servers.

I thought about a DNS server for the blacklist (the same way it works for antispam), but
perhaps someone has a better idea ?

thanks

N F

--- End Message ---
--- Begin Message --- So you want a blacklist that bans IPs for some amount of time, and that's capable of sharing the blacklist between multiple HTTP servers...

Seems to me that you need some sort of central or shared database...I'm not quite sure why SQL wouldn't be an option, but it seems to me that it should be. You could also use something like memcache on one of the servers to store blocked IPs. It would likely be somewhat faster than SQL, and is simpler as well. Memcache has a built-in timeout mechanism that could work rather well for that sort of thing as well.

If you need to block IPs without using a PHP solution, you could hack something together with your platform's native firewall utility (e.g. iptables/netfilter for Linux). It seems to me that DNS would be even more of a kludge.

I believe that memcache or SQL would be a significantly cleaner solution.

jon

nicolas figaro wrote:
Hi,

I'd like to set a captcha on my web server(s).

The code works quite fine, but I'd like to blacklist (for an amount of time) the ips that failed
with the captcha x times.

The web server works with an SQL server, but I cannot ask the page to check for each IP
with a request to the database.

I can't also store the blocked IP to a filename on the server, because the site is served by several
http servers.

I thought about a DNS server for the blacklist (the same way it works for antispam), but
perhaps someone has a better idea ?

thanks

N F


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

 I have data which have value in bytes for example ,

   $bytes = 33554432;

  How to convert this to MB ?

THanks

 - weetat (PHP Novice)

--- End Message ---
--- Begin Message ---
divide by 1024, and you'll get KB

divide again by 1024 and you'll get MB

same for GB, TB, etc

On 7/25/06, weetat <[EMAIL PROTECTED]> wrote:
Hi all ,

  I have data which have value in bytes for example ,

    $bytes = 33554432;

   How to convert this to MB ?

THanks

  - weetat (PHP Novice)

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



--- End Message ---
--- Begin Message ---
Divide by 1024 and you get KiB
Divide by 1000 and you get KB

Read: http://physics.nist.gov/cuu/Units/binary.html

Andrew

----- Original Message ----- From: "André Medeiros" <[EMAIL PROTECTED]>
To: "weetat" <[EMAIL PROTECTED]>
Cc: <php-general@lists.php.net>
Sent: Tuesday, July 25, 2006 12:41 PM
Subject: Re: [PHP] convert byte to MB


divide by 1024, and you'll get KB

divide again by 1024 and you'll get MB

same for GB, TB, etc

On 7/25/06, weetat <[EMAIL PROTECTED]> wrote:
Hi all ,

  I have data which have value in bytes for example ,

    $bytes = 33554432;

   How to convert this to MB ?

THanks

  - weetat (PHP Novice)

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



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




--- End Message ---
--- Begin Message ---
weetat wrote:
> Hi all ,
> 
>  I have data which have value in bytes for example ,
> 
>    $bytes = 33554432;
> 
>   How to convert this to MB ?
> 
> THanks
> 
>  - weetat (PHP Novice)
> 

1GB = 1024 * 1MB = 1024 * (1024 * 1KB) = 1024 * (1024 * (1024 * 1byte))

--- End Message ---
--- Begin Message ---
        So what u'r trying to say is that we should use KiB and not KB for
kilobytes? That's funny!

        Andrei

Andrew Brampton wrote:
> Divide by 1024 and you get KiB
> Divide by 1000 and you get KB
> 
> Read: http://physics.nist.gov/cuu/Units/binary.html
> 
> Andrew
> 
> ----- Original Message ----- From: "André Medeiros" <[EMAIL PROTECTED]>
> To: "weetat" <[EMAIL PROTECTED]>
> Cc: <php-general@lists.php.net>
> Sent: Tuesday, July 25, 2006 12:41 PM
> Subject: Re: [PHP] convert byte to MB
> 
> 
>> divide by 1024, and you'll get KB
>>
>> divide again by 1024 and you'll get MB
>>
>> same for GB, TB, etc
>>
>> On 7/25/06, weetat <[EMAIL PROTECTED]> wrote:
>>> Hi all ,
>>>
>>>   I have data which have value in bytes for example ,
>>>
>>>     $bytes = 33554432;
>>>
>>>    How to convert this to MB ?
>>>
>>> THanks
>>>
>>>   - weetat (PHP Novice)
>>>
>>> -- 
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
> 

--- End Message ---
--- Begin Message ---
Andrei wrote:
>       So what u'r trying to say is that we should use KiB and not KB for
> kilobytes? That's funny!

I know a lot of people who do just that.

Regards,
Austin.

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---
--- Begin Message ---
weetat escreveu:
Hi all ,
 I have data which have value in bytes for example ,
   $bytes = 33554432;
  How to convert this to MB ?
THanks
------------
Please see:
http://www.unc.edu/~rowlett/units/index.html
http://www.unc.edu/~rowlett/units/dictM.html
-----
zerof

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

weetat wrote:
> Hi all ,
> 
>  I have data which have value in bytes for example ,
> 
>    $bytes = 33554432;
> 
>   How to convert this to MB ?

how to read the manual thanks.

        http://php.net/filesize

no doubt you won't bother to read any of the user notes and therefore
miss *at least* 4 different implementations that do what you want - not to
mention that if you study the relevant code in the user notes you won't read
you might even learn how to count in bytes (which is IT 101 in anyone's book).

> 
> THanks
> 
>  - weetat (PHP Novice)

your website indicates your a professional, competent, bla bla company -
might I suggest that even the slightest ammount of competence precludes
the ability to STFW and RTFM (and the actually doing so); novice or no novice.

> 

--- End Message ---
--- Begin Message ---
weetat wrote:
> Hi Jay ,
> 
>    I am not in the javascript group.

'the javascript group' ??

>   document.forms['listfrm'].submit;

document.forms['listfrm'].submit();

                                ^^--- i.e. actually call the method

--- End Message ---
--- Begin Message ---
markw@mohawksoft.com wrote:
> [snip]
>> seems the perceived problem is being caused by something else?
>>
> 
> Sorry, I have to respectfully disagree.

ok :-).

> 
> I was converting all indexes to string indexes, and simply using
> "zend_hash_update" to re-constitute the objects and they simply did not
> work. When I scanned indexes strings to test for purely numeric content,
> and when true, used "zend_hash_index_update" instead, it worked.

ah - now it makes more sense, your seeing a change in behaviour at the 'C'
level, from a userland perspective "0" and 0 still reference the same element in
an array.

but obviously when playing with array indexes internally (under the hood of the
php engine) things are different between version 4 and 5.

> 
> This behavior appears different in 5.1.X from 4.x, I can't explain it
> 100%, but I know that this change fixed the problem I was seeing.

good to see you fixed the issue!

> 

--- End Message ---
--- Begin Message ---
> markw@mohawksoft.com wrote:
>> [snip]
>>> seems the perceived problem is being caused by something else?
>>>
>>
>> Sorry, I have to respectfully disagree.
>
> ok :-).

Men of integrity must be able to disgree peacefully. :-)

>
>>
>> I was converting all indexes to string indexes, and simply using
>> "zend_hash_update" to re-constitute the objects and they simply did not
>> work. When I scanned indexes strings to test for purely numeric content,
>> and when true, used "zend_hash_index_update" instead, it worked.
>
> ah - now it makes more sense, your seeing a change in behaviour at the 'C'
> level, from a userland perspective "0" and 0 still reference the same
> element in an array.

It is funny, but no. I thought it would work, but it simply didn't, not
even with a $var["0"] index. There was, it seemed, no way to extract the
members of the array.


>
> but obviously when playing with array indexes internally (under the hood
> of the php engine) things are different between version 4 and 5.

That's my bet.
>
>>
>> This behavior appears different in 5.1.X from 4.x, I can't explain it
>> 100%, but I know that this change fixed the problem I was seeing.
>
> good to see you fixed the issue!

Well, the point I was trying to make was that there are other extensions,
like wddx, that do the same thing, and people should know about it.

--- End Message ---
--- Begin Message ---
Larry Garfield wrote:
> Disable short tags.
> 
> If short tags are enabled, the PHP parser sees the <? and switches into PHP 
> mode.  It then starts parsing the "xml" and sees that it's not proper PHP, 
> and freaks out.  
> 
> You can:
> 
> a) Use PHP to print out the XML declaration as a string:
> <?php print '<?xml version="1.0" encoding="utf-8"?>'; ?>
> 
> b) Disable short tags so that the PHP parser ignores <? and only recognizes 
> <?php.
> 
> The correct answer is (b).  (PHP 6 won't even have short tags, so get used to 
> not having them.)
> 

Can you find anywhere where this was announced?  I don't recall seeing
any decision on it.

A quick search found several mentions of the devs deciding to keep short
tags when going from php 4 to php 5.  The php 6 todo list shows that <%
will be removed but <? will stay.

--- End Message ---
--- Begin Message ---
At 11:01 PM -0500 7/24/06, Larry Garfield wrote:
Disable short tags.

If short tags are enabled, the PHP parser sees the <? and switches into PHP
mode.  It then starts parsing the "xml" and sees that it's not proper PHP,
and freaks out.
You can:

Bingo !

That works : )

Apparently the "better" minds are on this list.

Thanks very much.

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
This one time, at band camp, Larry Garfield <[EMAIL PROTECTED]> wrote:

 
> The correct answer is (b).  (PHP 6 won't even have short tags, so get used to 
> not having them.)

ummm, I think it was decided to stay in php6. I could be mildly/wildly mistaken

Kevin


-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
On Tue, July 25, 2006 3:15 pm, Kevin Waterson said:
> This one time, at band camp, Larry Garfield <[EMAIL PROTECTED]>
> wrote:
>
>> The correct answer is (b).  (PHP 6 won't even have short tags, so get
>> used to
>> not having them.)
>
> ummm, I think it was decided to stay in php6. I could be mildly/wildly
> mistaken
>
> Kevin

The last I heard, they were still slated for removal.  The PHP core team
does have a habit of changing their minds about such things on a regular
basis, however, so who knows what their plan is this week. :-)

--Larry Garfield

--- End Message ---
--- Begin Message ---
>Hi,
>   We r using the paypal secure transaction.if u want i will send u the code 
> and the tutorials
Hi Suresh Kumar,
I'm sorry I don't reply email directly. I've been a kind of busy lately...
If you want to send the code and tutorial of pay pal secure transaction, I will 
love to.
And thank you very much.
                     Best Regards
============BBC============
                     **o<0>o**

--- End Message ---
--- Begin Message ---
At 12:46 AM -0400 7/25/06, Michael B Allen wrote:
Ok, I've been tinkering a little. This isn't "simple" but it's not a
lot of code either.

Granted, and no offense, it isn't simple the way you've attempted it.

You simply have three columns with these conditions:

1. Is gray if odd;
2. Is a time stamp
3. Is green if > 1000.

After placing your data in arrays via the dB, start a table and loop pulling variables ($i, $timestamp[], $value[]) from the arrays and display them like so:

<td id="<?php if ($i & 1) echo "grey"; ?>"> <?php echo($i); ?> </td>
<td> <?php echo date("M j, Y g:i a", $timestamp[$i]); ?> </td>
<td id="<?php if ($value[$i]>1000) echo "green"; ?>"> <?php echo($value[$i]); ?> </td>

Place the colors "gray" and "green" in a css, where they should be.

I have not tested this code, so it may have errors, but the technique should work.

hth's

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
We've created a file manager which allows users to access their web space on
a server.  It's working brilliantly, except that it would seem there are
some caching issues, either by the system cache or the web server cache that
are causing us a headache.

When the script tries to delete a file, we always check (using file_exists)
to see whether the file exists before it's deleted.

The check comes back true, but the unlink then fails, saying no file or
directory there!

We've tried turning off all errors (using error_reoprting(0) ) but this
would seem to have little difference in the error - it still comes back with
a failure.

We are using our own error handling, but before the command is carried out,
there is this 0 call...

Does anyone know how we can stop these errors?

Cheers
Nunners

--- End Message ---
--- Begin Message ---
You could try prefixing the unlink function call with an @:

if (file_exists($fn)) {
   @unlink($fn);
}

The @ should suppress any errors.

jon

James Nunnerley wrote:
We've created a file manager which allows users to access their web space on
a server.  It's working brilliantly, except that it would seem there are
some caching issues, either by the system cache or the web server cache that
are causing us a headache.

When the script tries to delete a file, we always check (using file_exists)
to see whether the file exists before it's deleted.

The check comes back true, but the unlink then fails, saying no file or
directory there!

We've tried turning off all errors (using error_reoprting(0) ) but this
would seem to have little difference in the error - it still comes back with
a failure.

We are using our own error handling, but before the command is carried out,
there is this 0 call...

Does anyone know how we can stop these errors?

Cheers
Nunners


--- End Message ---
--- Begin Message ---
> [snip]
> When the script tries to delete a file, we always check (using
> file_exists) to see whether the file exists before it's deleted.
>
> The check comes back true, but the unlink then fails, saying no file or
> directory there!
> [/snip]
>
> Could you please post the code you are using to check and unlink the
> file?

Heres the function - sometimes the scandir fails, sometimes the unlink,
sometimes the rmdir at the end.  They all have @ to try and surpress the
error, but I think it's a system halt failure - I can only assume?

You'll also see there are quite a lot of clearstatcache - that was another
attempt to sort this problem out!

function system_rmdir($dir) {
        $current_error_level = error_level();
        error_reporting(0);
        $dir = $dir."/";
        $dir=str_replace("//", "/", $dir);
        clearstatcache();
        if (is_dir($dir)) {
                $dir_contents = scandir($dir);
                foreach ($dir_contents as $item) {
                        clearstatcache();
                        if (is_dir($dir.$item) && $item != '.' && $item !=
'..') {
                                system_rmdir($dir.$item.'/');
                        } elseif (file_exists($dir.$item) && $item != '.' &&
$item != '..') {
                                @unlink($dir.$item);
                        }
                }
                clearstatcache();
                if (is_dir($dir)) {
                        @rmdir($dir);
                }
        }
        error_reporting($current_error_level);
}

Thanks
Nunners

--- End Message ---
--- Begin Message ---
James Nunnerley wrote:
>> [snip]
>> When the script tries to delete a file, we always check (using
>> file_exists) to see whether the file exists before it's deleted.
>>
>> The check comes back true, but the unlink then fails, saying no file or
>> directory there!
>> [/snip]
>>
>> Could you please post the code you are using to check and unlink the
>> file?
> 
> Heres the function - sometimes the scandir fails, sometimes the unlink,
> sometimes the rmdir at the end.  They all have @ to try and surpress the
> error, but I think it's a system halt failure - I can only assume?

my mind boggles as to what a 'system halt failure' is. is a system fails to
halt It would suggest that it's still running, and if it *has* halted then any 
attempt
to run a script (php or otherwise) is futile... maybe I'm missing something. :-)

> 
> You'll also see there are quite a lot of clearstatcache - that was another
> attempt to sort this problem out!

a few things:

1. I don't tihnk you need all those clearstatcache() calls .. from the manual:
"Note:  This function caches information about specific filenames, so you only 
need to call clearstatcache() if you are
performing multiple operations on the same filename and require the information 
about that particular file to not be
cached."

2. you might be looking at a user/group permissions problem... maybe start 
echoing out the
user and/or group owner of the files to see if that correlates with the 
failures.

3. turn error reporting to full in order to try and determine the problem?

> 
> function system_rmdir($dir) {
>       $current_error_level = error_level();
>       error_reporting(0);
>       $dir = $dir."/";
>       $dir=str_replace("//", "/", $dir);
>       clearstatcache();
>       if (is_dir($dir)) {
>               $dir_contents = scandir($dir);
>               foreach ($dir_contents as $item) {
>                       clearstatcache();
>                       if (is_dir($dir.$item) && $item != '.' && $item !=
> '..') {
>                               system_rmdir($dir.$item.'/');
>                       } elseif (file_exists($dir.$item) && $item != '.' &&
> $item != '..') {
>                               @unlink($dir.$item);
>                       }
>               }
>               clearstatcache();
>               if (is_dir($dir)) {
>                       @rmdir($dir);
>               }
>       }
>       error_reporting($current_error_level);
> }
> 
> Thanks
> Nunners
> 

--- End Message ---
--- Begin Message ---
Hi all.

I have a list of people in a database who live in particular rooms. Next semester, they may live somewhere else, so I need to update my database. (I know the data becomes stale, but not that often.) Here's what I'm doing to update:

1. Pull list of IDs from database A - store in array
2. Foreach ID in array, search database B to see if they have a new room
  2a. If no, go back to step 2 and go to next ID
3. Compare new room to current room
  3a. If different, update the record to new room

That's basically it. Now, I know this works (sorta) because the records are updating with the appropriate information. Here's the problem I'm running into: it only does a certain amount and then quits!! WHY!!?!

The total number of records I have is 1335 - pulled from step 1. However, when I go through the list and query for new rooms, it stops... randomly... not even at the same record each time. Sometime it's 230, sometimes it's 476 - truly random from what I can tell. I am sorting the query (ORDER BY) each time, so I know it's the same order.

Any thoughts on why this is happening? Possibly a buffer issue?

Thanks in advance.
~Philip

--- End Message ---

Reply via email to