Re: [PHP] Optimize simple file XOR code

2004-06-24 Thread Marcel Tschopp
Hi Marcus

Try this:

function CryptFile($hash, $filename)
{
// The key used is generated using another function.
// Since this function is only called once it has
// nothing to do with the performance of this function
$key = GenerateKey($hash);
$keylen = strlen($key = implode('', $key));

$handle = fopen($filename, 'r');
while (!feof($handle))
{
  // Set the time limit or the script will time out
  // on large files
  set_time_limit(30);

  $data = fread($handle, 8192);
  for ($i = 0; $i  strlen($data); $i = $i + $keylen)
  {
$data = substr_replace($data, substr($data, $i, $keylen) ^ $key, $i, $keylen);
  }

  // Return the encrypted version to the browser
  echo $data;
}
}

It should return the same results, but at my machine it is about 30
percent faster.

Cheers
Marcel


 Hi!
 
 I'm using a very simple algorithm to encrypt files sent from the server
 On Demand. The algorithm uses XOR for the encryption. My problem is
 that the code is very slow, it can only process about 40 KB per second
 on my system, so my question is, is there any more speed optimized way
 to write this code?
 
 Here is my function:
 
   function CryptFile($hash, $filename)
   {
 // The current position in the key generated below
 $key_pos = 0;
 
 // The key used is generated using another function.
 // Since this function is only called once it has
 // nothing to do with the performance of this function
 $key = GenerateKey($hash);
 
 $handle=fopen($filename, r);
 while (!feof($handle))
 {
   // Set the time limit or the script will time out
   // on large files
   set_time_limit(30);
 
   $data = fread($handle,8192);
   for ($i=0; $istrlen($data); $i++)
   {
 // Change the data read from the file by using
 // XOR with the key
 $data[$i] = $data[$i] ^ $key[$key_pos];
 
 // Calculate the next position in the key
 $key_pos=($key_pos+1) % count($key);
   }
 
   // Return the encrypted version to the browser
   echo $data;
 }
   }
 
 My guess is that if one should start optimizing the code anywhere, it
 would be within the for-loop. Any ideas?
 
 Thanks in advance!
 
 Regards,
 Marcus
 
 -- 
 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] DSOFile issues

2004-06-22 Thread Marcel Tschopp
Hi everybody,

I need to get the Office Document Properties from MSWord-files and i
found DSOFile for COM:
http://support.microsoft.com/support/kb/articles/Q224/3/51.asp

But now the problem is, that the COM Object don't releases the file
lock. Here is the code I use:

?php

$propReader = new COM('DSOleFile.PropertyReader');
$info = pathinfo(__FILE__);

$docProps = $propReader-getDocumentProperties($info['dirname'] . '/Dok0.doc');
$custProps = $docProps-customProperties;

while($elem = $custProps-next()) {
echo $elem-Name . ': ' . $elem-Value . 'br';
}

unset($custProps);
unset($docProps);
unset($propReader);

?

I don't find anything online about that problem... Does anyone have
experience with DSOFile?

Thanks in advance,
Marcel Tschopp

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



[PHP] Re: Re: Auth_User

2004-06-21 Thread Marcel Tschopp
Eventually the apache module mod_ntlm (http://modntlm.sourceforge.net/)
could help... don't know if it really works but it looks very
interesting.

cheers
Marcel

 If you are using IIS with PHP as an ISAPI-module, it is possible to find out
 the NT-User through $_SERVER['AUTH_USER'].
 Apparently it is not so easy on Apache.
 Does anyone know a solution?
 
 Gabor
 
 
 Gerben [EMAIL PROTECTED] schrieb im Newsbeitrag
 news:[EMAIL PROTECTED]
  This var means something else
  when you write the following code:
  Header(WWW-Authenticate: Basic realm=\Enter username and
 password\);
  Header(HTTP/1.0 401 Unauthorized);
  Your browser will produce a popup requesting a username an password
 
  This it what you get returned when using $_SERVER['AUTH_USER']
 
 
 
 
  Gabor NiederläNder [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
   Hi!
  
   I have installed a Apache Server (+php) in a Windows NT network. I
   would like to identify the Windows NT user visiting my php pages.
   When I was using IIS, I think it was quite easy to find it out through
   the $_SERVER['AUTH_USER'] variable. But it doesn't seem to work with
   apache. Is there another way?
  
   Cheers,
   Gabor
 
 -- 
 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] Programming User-Customized Categories ??

2004-06-18 Thread Marcel Tschopp
Hey

Why don't you make a second table 'categories' and have the two tables
in relation?
For example:

Table 'contacts':
id   name  category_id
--
 0   John Doe3(Category New York Office)
 1   Jane Smith  4(Category Orlando Office)
 2   Mark Jones  2(Category Creative)

Table 'categories':
id   nameparent_id
--
 1   Sales   0(Main category)
 2   Creative0(Main category)
 3   New York Office 1(Subcategory of Sales)
 4   Orlando Office  1(Subcategory of Sales)

So you have unlimited subcategories and the users can choose and add
them easily. In addition, you have normalized your data...

cheers
Marcel


On Fri, 18 Jun 2004 16:29:14 -0400
Monty wrote:

 Hi, I need to add the ability for users to define and set up their own
 categories and sub-categories that can be used to group contacts they enter
 into a database. Here's an example of how the data might be stored...
 
 
 NameMain Category   Sub Category
 -   -   
 John DoeSales   New York Office
 Jane Smith  Sales   Orlando Office
 Mark Jones  Creative
 Sarah Williams  Creative
 Kevin Brown Manager Office Manager
 Joe Johnson Manager Site Manager

 
 I need to allow users to define the types of Main Categories they want, and
 to also define whether or not those Main Categories will have Sub
 Categories, which they can also define.
 
 I know how to do this if the types of categories and sub-categories were
 pre-defined, but, I'm finding it a lot trickier to allow the users to
 customize these with their own category types. So, I'm hoping someone might
 be able to point me to an example of how custom categories and
 sub-categories can be programmed in PHP and set up in MySQL.
 
 Any suggestions or advice would be much appreciated!
 
 Monty
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

--

Marcel Tschopp [EMAIL PROTECTED]

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