php-general Digest 12 Oct 2007 03:21:17 -0000 Issue 5068

Topics (messages 263107 through 263130):

Re: Filter input
        263107 by: Manuel Vacelet

Re: Classes - Dumb question
        263108 by: Jay Blanchard

Re: FileZilla Password Decoder --- $i think therefore $i am
        263109 by: Amos Vryhof

IIS vs Apache
        263110 by: Philip Thompson

Detect local or remote call?
        263111 by: Anders Norrbring
        263112 by: Nathan Nobbe
        263114 by: Marcus Mueller
        263115 by: Nathan Nobbe
        263116 by: Robert Cummings
        263117 by: Anders Norrbring

Re: round()
        263113 by: Jürgen Wind
        263118 by: Jürgen Wind
        263129 by: Instruct ICC

Need help adding dBase support to PHP
        263119 by: Jon Westcot
        263120 by: Nathan Nobbe
        263121 by: Jon Westcot
        263122 by: Nathan Nobbe
        263124 by: Jon Westcot
        263125 by: Nathan Nobbe
        263126 by: Jon Westcot
        263127 by: Nathan Nobbe
        263128 by: Nathan Nobbe

preg_match_all Help
        263123 by: admin.buskirkgraphics.com

Re: Sessions running out of storage space - Increase memory?
        263130 by: Matthew Powell

Administrivia:

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

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

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On 10/11/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
> What are you wanting to validate?
>
> Do you want a package/class/function set that when called will validate 
> different types of input?
> Email, string, int, etc...

Basically yes.
I want to validate:
- type: (string, int, float, ..)
- characteristics (length, allowed characters, ...)
- nature (email, ISBN, ...)

I also want this lib. to let me define my own rules.
For instance, I'm dealing with parameters that looks like 'field_33',
'field_1', 'label', 'title'
I want to be able to tells:
validate stuff that match:
- (field_[0-9]+ or [a-z]+)
and maybe in some cases
- (field_[0-9]+ or label or title)

The thing that remains not very clear to me is where validation stop
and where application logic start.

Example:
A given 'item' (value = 7) have 3 'fields':
- field_33
- field_5
- label

When it comes to validate the fields value of the item '7'
should I validate 'field' against
- ('field_33', 'field_5', 'label')
  -> I validate the data are well formed AND coherent.
or
-('field_[0-9]+', [a-z]+)
  -> I only care about the form and I let the "application part" deal
with coherency later.

I don't know if I'm clear enough!

--- End Message ---
--- Begin Message ---
[snip]
Not trying to hijack the thread... Hopefully this is related enough,  
if not I apologize. Would a good use of a class be to write a generic  
database connection script? and then feed in the different variables,  
such as customer login, database, stuff like that?

something like class DBConnect {
        // Connect to database
        mysql_connect($server, $login, $password, $database);
        }

or no?
[/snip]

I don't think so because it is inefficient...wrapping an existing stand-alone 
function is sort of redundant. If you were writing a database abstraction layer 
that would be a horse of a different color.

--- End Message ---
--- Begin Message ---
Thanks!

That Helped Immensely..... the final function is below (with a little documentation)... I'll post my final converter somewhere soon... it's done, and works.

// Decodes a FileZilla 2 password
function DecodePassword($strPass) {
  // The Encryption Salt for FileZilla 2 Passwords
  $strKey = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        
  // Split the encrypted strings into chunks of 3
  $passPieces = str_split($strPass,3);
  // How many characters in the final password
  $nPassLen = strlen($strPass) / 3;
  $nOffset = ($nPassLen % strlen($strKey));

  // Clear the variable that holds the decoded password
  $strDecodedPass = "";
        
  // Step through each 3-character chunk
  foreach($passPieces as $i=>$passPiece) {
    // this should not be needed, but it ensures the correct data type
    // I think it might be just a throwback from converting from the
    // Python script
    $c = intval($passPiece);

    // I don't rightly know what this does, but it seems to work.
    // Like I said, it was converted from a python script that worked.
    $c2 = ord($strKey[($i + $nOffset) % strlen($strKey)]);
    $c3 = chr(($c ^ $c2));

    // Adds the decoded character to the final password String
    $strDecodedPass .= $c3;
  }
  // Spit back the whole collection of decoded characters
  return $strDecodedPass;
}

Jochem Maas wrote:
Amos Vryhof wrote:
Good Morning everyone,


....

def DecodePassword( strPass):
    """Decode a filezilla password"""
    strKey = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    nPassLen = len(strPass) / 3
    nOffset = nPassLen % len(strKey)

    strDecodedPass = ""

    for i in range(nPassLen):
        c = int(strPass[i * 3:(i * 3) + 3])
        c2 = ord(strKey[(i + nOffset) % len(strKey)])
        c3 = chr((c ^ c2))

        strDecodedPass += c3

    return strDecodedPass

...and tried to convert it to PHP, but since I don't know Python and
there is no documentation in the script to say what it's doing, my
function doesn't spit out all of the right characters... (it does some
though?? maybe coincidence)

  function DecodePassword($strPass) {
    $strKey = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    $nPassLen = strlen($strPass) / 3;
    $nOffset = ($nPassLen % strlen($strKey));

    $strDecodedPass = "";
$passPieces = str_split($strPass,3); foreach($passPieces as $passPiece) {
    $c = intval($passPiece);
        $c2 = ord($strKey[($i + $nOffset) % strlen($strKey)]);

                             ^---- WHERE IS $i DEFINED? (hint: it's not :-)

        $c3 = chr(($c ^ $c2));

       $strDecodedPass .= $c3;
    }

    return $strDecodedPass;
}

I know I simplified quite a bit, but I might have done it wrong...I
tried to convert line-for line, but I'm not sure what the stuff on Lines
10 to 13 do. (Lack of Perl knowledge)

There are perl and Javascript functions to do the decoding at
http://filezilla.sourceforge.net/forum/viewtopic.php?t=170

I'm not looking for a major undertaking, just something to do the
conversion so I don't have to rebuild definitions for 200 and something
websites.... If I can get it working properly, I'll probably put a
version on my server so people can convert their files as well, as I can
see this being a major PITA.

Thanks!


--- End Message ---
--- Begin Message ---
>From this article <
http://blogs.iis.net/bills/archive/2007/05/07/iis-vs-apache.aspx> written in
May of this year, the author makes this comment about IIS and PHP:

[snippet]
"If you're worried about IIS performance and reliability when running PHP
vs. running on Apache, you're concerns are definitely valid.  Up until
recently there were only two ways to run PHP:  the slow way (CGI), and the
unreliable way (ISAPI).  :)  This is primarily a result of the lack of
thread-safety in some PHP extensions - they were originally written for the
pre-fork Linux/Apache environment which is not multi-threaded.  Running them
on IIS with the PHP ISAPI causes them to crash, and take out the IIS process
serving your application.

"Fortunately, the Microsoft / Zend partnership has brought about fixes to
these issues with many performance and compatibility fixes by Zend, and a
FastCGI feature for IIS which enables fast, reliable PHP hosting.  FastCGI
is available now in Tech Preview form, and has also been included in Windows
Server "Longhorn" Beta 3.  It will be included in Vista SP1 and Longhorn
Server at RTM."
[/snippet]

This author (employed my M$) even says that PHP ISAPI can cause IIS to
crash. Am I taking the one-liner out of context? Does this happen often?
What are the conditions in which it would cause it to crash?

What I am currently doing is some research to see if we want to move our web
server from IIS 6 to Apache 2. We will still be running on a Windows 2k3
server. So, I wanted to query the list and see what you have to say about
using IIS or Apache on a Windows server - we are a Windows environment (my
hands are tied there =). Our development language is only PHP at this point.
We are currently using MySQL, but my supervisor is considering moving to MS
SQL Server (blegh!) - any issues with Apache there?

Thanks in advance,
~Philip

--- End Message ---
--- Begin Message --- Is there a good way to detect in a script if it's called locally from command line, or via a remote browser?

Anders.

--- End Message ---
--- Begin Message ---
On 10/11/07, Anders Norrbring <[EMAIL PROTECTED]> wrote:
>
> Is there a good way to detect in a script if it's called locally from
> command line, or via a remote browser?
>
> Anders


maybe not the best, but works for linux:

<?php
if(isset($_SERVER['SHELL'])) {
    echo 'cli script' . PHP_EOL;
} else {
    echo 'web script';
}
?>

-nathan

--- End Message ---
--- Begin Message ---
Anders Norrbring wrote:
> Is there a good way to detect in a script if it's called locally from
> command line, or via a remote browser?

Check out <http://www.php.net/manual/en/function.php-sapi-name.php>.

Greetings
m.

--- End Message ---
--- Begin Message ---
On 10/11/07, Marcus Mueller <[EMAIL PROTECTED]> wrote:
>
> Anders Norrbring wrote:
> > Is there a good way to detect in a script if it's called locally from
> > command line, or via a remote browser?
>
> Check out <http://www.php.net/manual/en/function.php-sapi-name.php>.



much better:)

php > echo php_sapi_name();
cli

-nathan

--- End Message ---
--- Begin Message ---
On Thu, 2007-10-11 at 19:58 +0200, Anders Norrbring wrote:
> Is there a good way to detect in a script if it's called locally from 
> command line, or via a remote browser?

I've always used

    if( isset( $_SERVER['SERVER_PORT'] ) )
    {
        return 'web';
    }

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
Nathan Nobbe skrev:
On 10/11/07, *Marcus Mueller* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Anders Norrbring wrote:
     > Is there a good way to detect in a script if it's called locally from
     > command line, or via a remote browser?

    Check out < http://www.php.net/manual/en/function.php-sapi-name.php>.



much better:)

php > echo php_sapi_name();
cli

-nathan


Thanks, seems to be the easiest way.. ;)

Anders.

--- End Message ---
--- Begin Message ---
I get correct results:

5.2.4 PHP_VERSION
round(5.555,2):5.56
toFixed(5.555,2):5.56


admin-214 wrote:
> 
>> While we're entertaining algorithms, has anyone else noticed that 
> 
>> php's round() isn't the most accurate algorithm to round?
> 
>  
> 
> If you will refer to chafy's reply  on 28-Feb-2007 06:13
> <http://us2.php.net/manual/en/function.round.php#73537> 
> 
> The function round numbers to a given precision.
> 
> function toFixed($number, $round=2)
> { 
>     
>     $tempd = $number*pow(10,$round);
>     $tempd1 = round($tempd);
>     $number = $tempd1/pow(10,$round);
>     return $number;
>      
> }
> echo toFixed(5.555,2);  //return 5.56 
> 
>  
> 
> If your rounding issue is passed 2 decimal places. I found this function
> covenant and problem solving. As for the accuracy  of the algorithm 
> 
> I disagree. I will need to see an example where the round() is inaccurate.
> 
>  
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/round%28%29-tf4602528.html#a13161858
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
well,
seems to be OS dependent:

PHP_OS:Linux (Suse 9.x 32bit) | PHP_VERSION:5.0.3
$t=1.255;
round($t,2):1.26
$t += .00000001;
round($t,2):1.26
____

PHP_OS:WINNT (2000) | PHP_VERSION:5.2.4
$t=1.255;
round($t,2):1.25

$t += .00000001;
round($t,2):1.26

-- 
View this message in context: 
http://www.nabble.com/round%28%29-tf4602528.html#a13164737
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
> well,
> seems to be OS dependent:
> 
> PHP_OS:Linux (Suse 9.x 32bit) | PHP_VERSION:5.0.3
> $t=1.255;
> round($t,2):1.26
> $t += .00000001;
> round($t,2):1.26
> ____
> 
> PHP_OS:WINNT (2000) | PHP_VERSION:5.2.4
> $t=1.255;
> round($t,2):1.25
> 
> $t += .00000001;
> round($t,2):1.26
> 
> -- 
> View this message in context: 
> http://www.nabble.com/round%28%29-tf4602528.html#a13164737
> Sent from the PHP - General mailing list archive at Nabble.com.

First, you may have to be aware of floating point precision on your platform.
http://php.he.net/manual/en/language.types.float.php
"The size of a float is platform-dependent"

What is $t after $t += .00000001; ?

Now I see why BCMath was mentioned.

_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it 
now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033

--- End Message ---
--- Begin Message ---
Hi all:

    I'm not versed at all with Linux, and I need some help in configuring PHP 
to allow me to use the dBase-related functions.  From what I read in the help 
files, it seems that I need to recompile PHP with the "--enable-dbase" command, 
but I don't know how to do this.

    Can someone out there help me out?  All help will be greatly appreciated!

    Thanks,

        Jon


--- End Message ---
--- Begin Message ---
On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
>
> Hi all:
>
>     I'm not versed at all with Linux, and I need some help in configuring
> PHP to allow me to use the dBase-related functions.  From what I read in the
> help files, it seems that I need to recompile PHP with the "--enable-dbase"
> command, but I don't know how to do this.
>
>     Can someone out there help me out?  All help will be greatly
> appreciated!


what linux distribution are you using?

-nathan

--- End Message ---
--- Begin Message ---
Hi Nathan:

    I have no idea.  Where would I look to find this out?  Will phpinfo() give 
me this?  And, if so, where would I find it?

    Jon

----- Original Message ----- 
From: Nathan Nobbe 
To: Jon Westcot 
Cc: PHP General 
Sent: Thursday, October 11, 2007 5:00 PM
Subject: Re: [PHP] Need help adding dBase support to PHP


On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
  Hi all:

      I'm not versed at all with Linux, and I need some help in configuring PHP 
to allow me to use the dBase-related functions.  From what I read in the help 
files, it seems that I need to recompile PHP with the "--enable-dbase" command, 
but I don't know how to do this. 

      Can someone out there help me out?  All help will be greatly appreciated!

what linux distribution are you using?

-nathan



--- End Message ---
--- Begin Message ---
On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
>
> Hi Nathan:
>
>     I have no idea.  Where would I look to find this out?  Will phpinfo()
> give me this?  And, if so, where would I find it?


you might try

uname -a

from the command line; but theres no guarantee it will show the
distribution.  it will show the kernel, and sometime kernels
are named after the distro since they are often modified by the
distribution.

-nathan

--- End Message ---
--- Begin Message ---
Hi again, Nathan:

    I'm not certain how to get to a command line.  The server is a shared 
server provided by GoDaddy, if that's any help.  They told me that I needed to 
change something in the .htaccess file, but that didn't sound right at all.

    Thanks again for your help.

        Jon

----- Original Message ----- 
From: Nathan Nobbe 
To: Jon Westcot 
Cc: PHP General 
Sent: Thursday, October 11, 2007 5:08 PM
Subject: Re: [PHP] Need help adding dBase support to PHP


On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
  Hi Nathan:

      I have no idea.  Where would I look to find this out?  Will phpinfo() 
give me this?  And, if so, where would I find it?

you might try

uname -a

from the command line; but theres no guarantee it will show the distribution.  
it will show the kernel, and sometime kernels 
are named after the distro since they are often modified by the distribution.

-nathan




--- End Message ---
--- Begin Message ---
On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
>
> Hi again, Nathan:
>
>     I'm not certain how to get to a command line.  The server is a shared
> server provided by GoDaddy, if that's any help.  They told me that I needed
> to change something in the .htaccess file, but that didn't sound right at
> all.



they may be right.  did they give you some sort of documentation you could
point us to?
also, to determine if you have command line access, look around and see if
they provide ssh
access to the machine.  if so i can tell you how to ssh in, even if you have
windows or mac.
that will give you a command line prompt on the remote machine.

-nathan

--- End Message ---
--- Begin Message ---
Hi again:

    Thanks for the info.  From what I can see, GoDaddy does NOT provide access 
to ssh.  Any other thoughts?  Or is there some way to tell me, in general 
terms, how to configure PHP to allow the dbase functions to be used?

    Jon

----- Original Message ----- 
From: Nathan Nobbe 
To: Jon Westcot 
Cc: PHP General 
Sent: Thursday, October 11, 2007 5:34 PM
Subject: Re: [PHP] Need help adding dBase support to PHP


On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
  Hi again, Nathan:

      I'm not certain how to get to a command line.  The server is a shared 
server provided by GoDaddy, if that's any help.  They told me that I needed to 
change something in the .htaccess file, but that didn't sound right at all. 


they may be right.  did they give you some sort of documentation you could 
point us to?
also, to determine if you have command line access, look around and see if they 
provide ssh
access to the machine.  if so i can tell you how to ssh in, even if you have 
windows or mac. 
that will give you a command line prompt on the remote machine.

-nathan




--- End Message ---
--- Begin Message ---
On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
>
> Hi again:
>
>     Thanks for the info.  From what I can see, GoDaddy does NOT provide
> access to ssh.  Any other thoughts?  Or is there some way to tell me, in
> general terms, how to configure PHP to allow the dbase functions to be used?



if  godaddy is recommending that you place values in a .htaccess file they
probly mean you should upload a .htaccess
file via ftp.  im assuming thats how the give you access to the system
(since there is no ssh access).
im a bit unsure of the .htaccess setting, though i recently posted a small
how-to on using .htaccess files to override
settings in php.ini; this is common in shared hosting environments.
http://gentoo-wiki.com/HOWTO_php.ini_overrides_w/_.htaccess

basically, to have dbase support, php must be compiled w/ --enable-dbase,
per the documentation.
http://www.php.net/manual/en/rlef.dbase.php

perhaps, it is compiled in and the php.ini settings are preventing you from
using the functions (though that sounds hard to believe).
you might try tossing a phpinfo script on the box and looking for dbase in
the output; particularly look for --enable-dbase, or --disable-dbase.
you should see a dbase section also, if its compiled in.  if it is there we
can get a better idea of what sort of values could be placed in the
.htaccess file that would influence the behavior of the dbase component on
that system.

-nathan

--- End Message ---
--- Begin Message ---
On 10/11/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
>
> On 10/11/07, Jon Westcot <[EMAIL PROTECTED]> wrote:
> >
> > Hi again:
> >
> >     Thanks for the info.  From what I can see, GoDaddy does NOT provide
> > access to ssh.  Any other thoughts?  Or is there some way to tell me, in
> > general terms, how to configure PHP to allow the dbase functions to be used?
> >
>
>
>
> if  godaddy is recommending that you place values in a .htaccess file they
> probly mean you should upload a .htaccess
> file via ftp.  im assuming thats how the give you access to the system
> (since there is no ssh access).
> im a bit unsure of the .htaccess setting, though i recently posted a small
> how-to on using .htaccess files to override
> settings in php.ini; this is common in shared hosting environments.
> http://gentoo-wiki.com/HOWTO_php.ini_overrides_w/_.htaccess
>
> basically, to have dbase support, php must be compiled w/ --enable-dbase,
> per the documentation.
> http://www.php.net/manual/en/rlef.dbase.php
>
> perhaps, it is compiled in and the php.ini settings are preventing you
> from using the functions (though that sounds hard to believe).
> you might try tossing a phpinfo script on the box and looking for dbase in
> the output; particularly look for --enable-dbase, or --disable-dbase.
> you should see a dbase section also, if its compiled in.  if it is there
> we can get a better idea of what sort of values could be placed in the
> .htaccess file that would influence the behavior of the dbase component on
> that system.
>
> -nathan
>


oh,
i just spent and extra second and discovered:
(from documentation :)

This extension has no configuration directives defined in php.ini.

if dbase does not appear to be installed on the system when you look at
phpifno output i would draft an email to them expressing that it
doesnt appear to be compiled in and ask them if they can add it.

-nathan

--- End Message ---
--- Begin Message ---
I have tried this many way  and for some reason

I cannot pull content between the 2 pattern options.

 

 

function pullchannel($document)

{

                preg_match_all('/<div class="channel" [^<>]*>(.*)<div
class="channel" [^<>]*>/i',$document,$elements);

$match = implode("\r\n",$elements[0]);

$match = str_replace('"',"","$match");

return $match;

}

 

 


--- End Message ---
--- Begin Message ---
Dan wrote:
> I need to retrieve a huge amount of data form a database and do so many
> times.  To eliminate the overhead of connecting to the database and
> pulling down all that info over and over, I'm trying to pull it down
> only once and stick it into a session.  The problem is I get the first
> few results and everything works fine.  But then after those first 5 or
> so I only get 0's. My first thought is that this is because of a limit
> on memory that sessions can take up or file size/space where the
> sessions are stored.  I looked in the PHP.INI and I didn't find anything
> though.
> 
> Any ideas on how to fix this problem or a more elegant solution to my
> huge data needs?
> 
> - Dan


APC?

apc_store('some_array',serialize($some_array),86400);
caches $some_array in RAM for 24 hours.

$some_array = unserialize(apc_fetch('some_array'));
brings it back out.

Note - don't do this if you're dealing with massive amounts of data
unique to each session_id, though.  Come to think of it... if you're
dealing with massive amounts of data for each session_id, that might be
part of your problem. :)

Matt

--- End Message ---

Reply via email to