Re: [PHP] Looking for complete entered URL

2013-04-20 Thread Tom Rogers
Hello Angela,

Sunday, April 21, 2013, 4:51:37 AM, you wrote:

 I've written a script that logs all visits to a web site,
 complete with referrer and IP address.  It also logs all 4xx errors.
 What I'd like to add to this is, if someone adds extra code after
 the page_name.php, to be able to capture any extra code and log that.

 I've tried:

 $_SERVER['QUERY_STRING']
 $_SERVER['REDIRECT_QUERY_STRING']
 $_SERVER['REDIRECT_URL']

 but nothing seems to get logged.

 Is there a way, when either a false url is entered and a
 404 is generated, or just when someone tacks on extra code to the
 URL, that I can grab that extra info?  I'm looking for the complete
 URL that was entered by the user, not anything returned by the server.

 I've created my own 4xx_error.php files which calls my
 tracking script, along with creating the proper ErrorDocument lines in the 
 main .htaccess file.

 There are a lot of pages that have come up in my search,
 but nothing seems to pertain to what I'm trying to do.

 Thank you,
 Angela

 BTW, I know about Piwik and I use that, as well.  This is something I'm doing 
 on my own.


You  can put this in the page and email your self the information that
is available:

?php
ob_start();
phpinfo(INFO_VARIABLES);
$s = ob_get_contents();
ob_end_clean();

email('y...@wherever.com', 'Error Listing, $s);

Then you can see all that's present and work out what to trap

-- 
Best regards,
 Tommailto:trog...@kwikin.com


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



Re: [PHP] PHP 5.4 Help

2013-03-06 Thread Tom Rogers
Hello LLC,

Thursday, March 7, 2013, 2:41:43 AM, you wrote:



 I need help from someone knowledgeable about PHP and I hope I am
 seeking it in the right place.  I beg your forgiveness if this is not the 
 right place.
  
 I purchased a software (1-2-3 Music) a few years ago and have used
 parts of it on my website so people can buy and download MP3 songs.
 I have tried to contact the company I purchased the program from but
 they seem to be out of business.  Have also tried contacting the
 main developer but am not able to make contact…my emails to him are rejected 
 by his mail box).
  
 Beginning on April 1, 2013 my Web Hosting company will no longer
 support PHP programs less than Version 5.4...Register_Globals will
 be turned off.  I have tested my software with the new upcoming
 restrictions and find none of my song downloads will function with the PHP 
 5.4 version.
  
 Will someone tell me if the small module included on the bottom of
 this note will function properly under PHP 5.4? (Register_Globals
 turned off).  If it does not function properly with Register_Globals
 turned off, is there a way to make changes  to the module so it does
 function properly with Register-Globals turned off?
  
 Thank you very much
 Floyd J. Badeaux   
 -
 Module:
 ?php
 define (DOCMA_HOME,
 /homepages/37/d48651986/htdocs/htdocs/1-2-3-music-store/docma_08306s);
 ini_set(display_errors, 0);
 require_once (DOCMA_HOME./system/prepend.inc);
  
 define (DOCUMENT_ROOT, preg_replace(/()+/, /, realpath(.)));
 session_start();
  
 $processName = $_REQUEST[pname];
 $process = process_get_process($processName);
$process-execute();
  
?
 ---
  

You will probably need to remove the '' from this line:
$process = process_get_process($processName);

All  objects  are  passed  around as a reference now so the '' is not
needed and may cause troubles.

Tom

-- 
Best regards,
 Tommailto:trog...@kwikin.com


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



Re: [PHP] SNMP via PHP

2012-10-15 Thread Tom Rogers
Hello Lester,

Monday, October 15, 2012, 9:09:13 PM, you wrote:

 OK I've spent the last two hours going through pages of crap generated by
 google, and that includes google crap created by searches on sites like
 http://www.phpbuilder.com - cause mainly of cause by php pages on sites
 supporting other languages :(
 Certainly it seems that PHP is preferred even to website java and ruby ...

 I had some problems over the weekend with the network here and decided it was
 time to get some monitoring in place locally. cacti simply loaded up and I 
 have
 working system, but now I'm having trouble getting SNMP sorted on the target
 machines. So I started looking for an editor to handle the MIB data and keep
 hitting one dead end after another.

 I'm sure there must be something out there using php-snmp for a browser?

 -- 
 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
 Rainbow Digital Media - http://rainbowdigitalmedia.co.uk


Did you see this: http://www.php.net/manual/en/book.snmp.php

-- 
Best regards,
 Tommailto:trog...@kwikin.com


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



Re: [PHP] Mysql search query ignoring dots

2011-01-24 Thread Tom Rogers
Hi,

Monday, January 24, 2011, 10:50:41 PM, you wrote:
BP Hi all,

BP I have to perform a mysql query in a table with millions of records.
BP I've full-text indexed my search field and I'm searching with MATCH AGAINST.
BP But there is a problem. In this field there are company names that 
BP contain dots, for istance I've PO.SE. srl and I want to find it if 
BP the user search for: POSE or PO.SE or P.O.S.E. etc.
BP I googled in the web but I don't find any solution. I don't want to 
BP add a new field with the cleaned version of my string because I would 
BP like to solve with the query and I prefer that the mysql table not 
BP become too big. But if I will not find a different solution, I will 
BP use this escamotage.
BP I've find a post that is similar but the solution don't seem to solve 
BP my situation.
BP You can see it at the url:
BP http://forums.mysql.com/read.php?10,395557,395584#msg-395584
BP In my case replace(email, '.', '') = replace(theSearchValue, '.', '');
BP is indifferent and don't change my results.

BP My query, searching POSE, is:

BP select aziende.* from aziende where 10 AND 
BP (MATCH(aziende.ragione_sociale) AGAINST('+POSE' IN BOOLEAN MODE) OR 
BP (replace(aziende.ragione_sociale, '.', '') = replace('POSE', '.', 
BP '')) order by aziende.ragione_sociale limit 0, 10

BP The alternative choice could be REGEXP but I've red that it make my 
BP query slow in a table of millions of records and I don't know how to 
BP exclude dots in the regular expression.

BP Can anyone help me?

BP Thanks in advance.
BP Barbara

BP -- 
BP 
BP Barbara Picci
BP Micro srl
BP viale Marconi 222, 09131 Cagliari  - tel. (+39) 070400240
BP http://www.microsrl.com


In  the interest of speed it may be worth creating a table with just a
link id and the text to search which you can cleanup before inserting.
It will probably save you a headache in the future and will be quicker
than complicated queries.

The list of possible ids can then be tested against the full table for
any other criteria which if the table is indexed properly will be fast
too.

-- 
regards,
Tom


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



Re: [PHP] Filestat.c erorrs when building php-5.3.3 on solaris

2010-09-09 Thread Tom Rogers
Hi,

Friday, September 10, 2010, 2:49:36 AM, you wrote:
SVCD Ok, I tried removing the --disable-posix and adding --with-tsrm-pthreads
SVCD to the configure options. 
SVCD The resulting configure looks like this:

SVCD CC='/usr/local/bin/gcc' \
SVCD './configure' \
SVCD '--prefix=/app/php533' \
SVCD '--enable-shared' \
SVCD '--with-tsrm-pthreads' \
SVCD '--with-gnu-ld' \
SVCD '--with-apxs2=/app/apache2216/bin/apxs' \
SVCD '--with-zlib' \
SVCD '--with-zlib-dir=/usr/lib' \
SVCD '--with-png-dir=/usr/include/libpng' \
SVCD '--with-openssl=/shared_ro/openssl_098' \
SVCD '--with-oci8=/shared_ro/users.oracle/11.1.0'

SVCD Now I get this:

SVCD /users/0/php-5.3.3/ext/posix/posix.c: In function
SVCD `zif_posix_getgrnam':
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1017: error: too many arguments
SVCD to function `getgrnam_r'
SVCD /users/0/php-5.3.3/ext/posix/posix.c: In function
SVCD `zif_posix_getgrgid':
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1067: error: too many arguments
SVCD to function `getgrgid_r'
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1067: warning: assignment makes
SVCD integer from pointer without a cast
SVCD /users/0/php-5.3.3/ext/posix/posix.c: In function
SVCD `zif_posix_getpwnam':
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1136: error: too many arguments
SVCD to function `getpwnam_r'
SVCD /users/0/php-5.3.3/ext/posix/posix.c: In function
SVCD `zif_posix_getpwuid':
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1184: error: too many arguments
SVCD to function `getpwuid_r'
SVCD /users/0/php-5.3.3/ext/posix/posix.c:1184: warning: assignment makes
SVCD integer from pointer without a cast
SVCD gmake: *** [ext/posix/posix.lo] Error 1

SVCD Do I need to add the -D_POSIX_PTHREAD_SEMANTICS in the makefile or
SVCD configure.in somewhere? Can you point me in the right direction?

SVCD   -Vicki Stanfield, RHCE, CISSP

SVCD -Original Message-
SVCD From: Tom Rogers [mailto:trog...@kwikin.com] 
SVCD Sent: Wednesday, September 08, 2010 10:06 PM
SVCD To: Tom Rogers
SVCD Cc: php-general@lists.php.net
SVCD Subject: Re: [PHP] Filestat.c erorrs when building php-5.3.3 on solaris

SVCD Hi,

SVCD Thursday, September 9, 2010, 11:31:06 AM, you wrote:
TR Hi,

TR Thursday, September 9, 2010, 2:07:50 AM, you wrote:
SVCD I am trying to build php-5.3.3 and getting the following error: 

SVCD /users/0/php-5.3.3/TSRM -I/users/0/php-5.3.3/Zend
SVCD -I/usr/local/include -g -O2 -DZTS   -c
SVCD /users/0/php-5.3.3/ext/standard/filestat.c -o
SVCD ext/standard/filestat.lo 
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chgrp':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:416: error: too
SVCD many
SVCD arguments to function `getgrnam_r'
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chown':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:517: error: too
SVCD many
SVCD arguments to function `getpwnam_r'
SVCD make: *** [ext/standard/filestat.lo] Error 1

SVCD I have set my ORACLE_HOME, my PATH, and my LD_LIBRARY_PATH
SVCD And used the following configure command:

SVCD ./configure --prefix=/app/php533
SVCD --with-apxs2=/app/apache2215/bin/apxs
SVCD --with-zlib --with-zlib-dir=/usr/lib
SVCD --with-png-dir=/usr/include/libpng
SVCD --with-openssl=/shared_ro/openssl_098
SVCD --with-oci8=/shared_ro/users.oracle/11.1.0

SVCD I am using gmake 3.80. Can anyone give me a hint as to what I am
SVCD doing
SVCD wrong in this build?

SVCD   -Vicki Stanfield, RHCE, CISSP


TR From   the   error  message  it  would  seem  the  operating
SVCD system's
TR getpwnam_r() function is not POSIX compatible.
TR What system are you compiling on?

TR -- 
TR regards,
TR Tom



SVCD It  would  seem  you  need to add -D_POSIX_PTHREAD_SEMANTICS to the cc
SVCD flags to get the right function.

SVCD -- 
SVCD regards,
SVCD Tom



That  should  get  added  automatically  when  you run configure if it
recognizes that the system is solaris.

Try adding --host=solaris to configure and see if that helps

-- 
regards,
Tom


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



Re: [PHP] Filestat.c erorrs when building php-5.3.3 on solaris

2010-09-08 Thread Tom Rogers
Hi,

Thursday, September 9, 2010, 2:07:50 AM, you wrote:
SVCD I am trying to build php-5.3.3 and getting the following error: 

SVCD /users/0/php-5.3.3/TSRM -I/users/0/php-5.3.3/Zend
SVCD -I/usr/local/include -g -O2 -DZTS   -c
SVCD /users/0/php-5.3.3/ext/standard/filestat.c -o
SVCD ext/standard/filestat.lo 
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chgrp':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:416: error: too many
SVCD arguments to function `getgrnam_r'
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chown':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:517: error: too many
SVCD arguments to function `getpwnam_r'
SVCD make: *** [ext/standard/filestat.lo] Error 1

SVCD I have set my ORACLE_HOME, my PATH, and my LD_LIBRARY_PATH
SVCD And used the following configure command:

SVCD ./configure --prefix=/app/php533 --with-apxs2=/app/apache2215/bin/apxs
SVCD --with-zlib --with-zlib-dir=/usr/lib
SVCD --with-png-dir=/usr/include/libpng
SVCD --with-openssl=/shared_ro/openssl_098
SVCD --with-oci8=/shared_ro/users.oracle/11.1.0

SVCD I am using gmake 3.80. Can anyone give me a hint as to what I am doing
SVCD wrong in this build?

SVCD   -Vicki Stanfield, RHCE, CISSP


From   the   error  message  it  would  seem  the  operating  system's
getpwnam_r() function is not POSIX compatible.
What system are you compiling on?

-- 
regards,
Tom


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



Re: [PHP] Filestat.c erorrs when building php-5.3.3 on solaris

2010-09-08 Thread Tom Rogers
Hi,

Thursday, September 9, 2010, 11:31:06 AM, you wrote:
TR Hi,

TR Thursday, September 9, 2010, 2:07:50 AM, you wrote:
SVCD I am trying to build php-5.3.3 and getting the following error: 

SVCD /users/0/php-5.3.3/TSRM -I/users/0/php-5.3.3/Zend
SVCD -I/usr/local/include -g -O2 -DZTS   -c
SVCD /users/0/php-5.3.3/ext/standard/filestat.c -o
SVCD ext/standard/filestat.lo 
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chgrp':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:416: error: too many
SVCD arguments to function `getgrnam_r'
SVCD /users/0/php-5.3.3/ext/standard/filestat.c: In function
SVCD `php_do_chown':
SVCD /users/0/php-5.3.3/ext/standard/filestat.c:517: error: too many
SVCD arguments to function `getpwnam_r'
SVCD make: *** [ext/standard/filestat.lo] Error 1

SVCD I have set my ORACLE_HOME, my PATH, and my LD_LIBRARY_PATH
SVCD And used the following configure command:

SVCD ./configure --prefix=/app/php533 --with-apxs2=/app/apache2215/bin/apxs
SVCD --with-zlib --with-zlib-dir=/usr/lib
SVCD --with-png-dir=/usr/include/libpng
SVCD --with-openssl=/shared_ro/openssl_098
SVCD --with-oci8=/shared_ro/users.oracle/11.1.0

SVCD I am using gmake 3.80. Can anyone give me a hint as to what I am doing
SVCD wrong in this build?

SVCD   -Vicki Stanfield, RHCE, CISSP


TR From   the   error  message  it  would  seem  the  operating  system's
TR getpwnam_r() function is not POSIX compatible.
TR What system are you compiling on?

TR -- 
TR regards,
TR Tom



It  would  seem  you  need to add -D_POSIX_PTHREAD_SEMANTICS to the cc
flags to get the right function.

-- 
regards,
Tom


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



Re: [PHP] PHP5 SOAP...

2009-06-16 Thread Tom Rogers
Hi,

Wednesday, June 17, 2009, 1:21:47 AM, you wrote:
RJ I'm working on a project using SOAP and WS-Security in which I am failing
RJ miserably.

RJ Is there a way to inspect the actual XML, header, etc. that is actually
RJ being sent. I feel like I am constructing the call correctly, and I know
RJ exactly what needs to be sent, but I dont know how to see exactly what is
RJ sent - all I get back are useless errors like not enough information sent,
RJ etc...

RJ Any ideas? Any SOAP pros out there?


RJ Russell Jones
RJ CTO Virante, Inc.
RJ r...@virante.com
RJ 919-459-1035

Not a pro but...
Try something like this:
//object to pass function variables
class requestObject {
function requestObject($list) {
foreach($list as $key=$val)
$this-$key = $val;
}
}

$client = new  SoapClient(wsdl.xml, array('login'= login, 'password'= 
password, 'trace'=true));

$soapstruct = new requestObject(array('clientId'=12342, 'leagueId'=0)); //use 
whatever variables are needed
try {
$info = $client-soapFunction($soapstruct);
echo REQUEST:\n . $client-__getLastRequest() . br /\n;
print_r($info);
} catch (SoapFault $e) {
echo SOAP Fault: .$e-getMessage().br /\n;
echo REQUEST:\n . $client-__getLastRequest() . br /\n;
}

-- 
regards,
Tom


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



Re: [PHP] ! and !=

2009-04-22 Thread Tom Rogers
Hi,

Thursday, April 23, 2009, 8:30:34 AM, you wrote:
GL Hi all. Maybe I'm just getting confused by all the
GL languages I'm trying to work with! But, isn't:

GL if(!$var1 == $var2){

GL the same thing as

GL if($var1 != $var2){

GL #1 doesn't work, #2 does.
GL Thanks!


GL George Langley    Multimedia Developer    Audio/Video Editor   
GL Musician, Arranger, Composer www.georgelangley.ca

GL Too many choices, too little sleep.

Use brackets to make them the same:

if(!($var1 == $var2)) {

-- 
regards,
Tom


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



Re: [PHP] upgrade php 5.2.6 - 5.2.8 mysql problems!

2009-01-13 Thread Tom Rogers
Hi,

Tuesday, January 13, 2009, 9:25:57 AM, you wrote:
MM Hello everybody,

MM I am trying to update php 5.2.6 to 5.2.8 on a test system. Somehow it 
MM can not find the working mysql installation. With 5.2.6 I everything is
MM fine.

MM Here is the configure command that is pretty much the same as in 5.2.6:

MM './configure' '--enable-fastcgi' '--with-mysql' 
MM '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2/bin/apxs' 
MM '--enable-mbstring' '--with-pdo-mysql=/usr/local/mysql/' 
MM '--with-mysql-sock=/tmp' '--enable-soap' '--with-zlib' 
MM '--with-freetype-dir=/usr/local/lib' '--with-gd' '--with-jpeg-dir=/usr'
MM '--with-png-dir=/usr/lib' '--enable-exif' '--enable-cli'


MM PHP returns:

MM checking for MySQL UNIX socket location... /tmp
MM configure: error: Cannot find MySQL header files under yes.
MM Note that the MySQL client library is not bundled anymore!

MM According to a google search mysql-dev is not installed. So I tried to
MM get it with yast on the suse 11.0 server. No luck. So I got it via a 
MM rpm. That returns:

MM   rpm -i mysql-devel.rpm
MM error: Failed dependencies:
MM  mysql-client is needed by mysql-devel-5.0.26-21.x86_64
MM  mysql-shared = 5.0.26 is needed by mysql-devel-5.0.26-21.x86_64
MM  libc.so.6()(64bit) is needed by mysql-devel-5.0.26-21.x86_64
MM  libc.so.6(GLIBC_2.2.5)(64bit) is needed by 
MM mysql-devel-5.0.26-21.x86_64
MM  libc.so.6(GLIBC_2.3.4)(64bit) is needed by 
MM mysql-devel-5.0.26-21.x86_64
MM  libcrypt.so.1()(64bit) is needed by mysql-devel-5.0.26-21.x86_64
MM  libm.so.6()(64bit) is needed by mysql-devel-5.0.26-21.x86_64
MM  libnsl.so.1()(64bit) is needed by mysql-devel-5.0.26-21.x86_64
MM  libpthread.so.0()(64bit) is needed by mysql-devel-5.0.26-21.x86_64
MM  libpthread.so.0(GLIBC_2.2.5)(64bit) is needed by 
MM mysql-devel-5.0.26-21.x86_64
MM  libpthread.so.0(GLIBC_2.3.2)(64bit) is needed by 
MM mysql-devel-5.0.26-21.x86_64

MM Something must be wrong. I can't believe that there is so much change 
MM necessary for such a minur upgrade.

MM Any ideas? Thank you for any help,

MM Merlin


try getting rid of the trailing slash 
('--with-pdo-mysql=/usr/local/mysql/')

-- 
regards,
Tom


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



Re: [PHP] Thread Safety

2008-02-19 Thread Tom Rogers
Hi,

Wednesday, February 20, 2008, 3:00:28 AM, you wrote:
TP Not quite sure if this is the right list, but here I am...
TP  
TP I'm trying to use zend platform and it requires the Thread Safety option set
TP to off.
TP  
TP I just compiled php and I can't find what argument to build php that way,
TP what am I missing?
TP  
TP PHP 4.4.8
TP  
TP  
TP Thanks!



--disable-zts should do it

-- 
regards,
Tom

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



Re: [PHP] running cmd via php

2007-12-11 Thread Tom Rogers
Hi,

Thursday, November 29, 2007, 2:17:15 AM, you wrote:
a Hello!
a I'm trying a lot to find how I can run the cmd (command line of windows) and
a send to the cmd commands?
a Thanks. 


Here is one way to do it, its from a function to check php syntax.
it opens up php then sends it the text to check and reads the answer
back.

function checkPhpSyntax($text){
$r = false;
$cwd = getcwd();
chdir(C:\\php5);
$descriptorspec = array(
  0 = array(pipe, r), // stdin is a pipe that the child will read from
  1 = array(pipe, w),
  2 = array(file, C:\\php5\\error.txt, a));
$process = proc_open(C:\\php5\\php -c C:\\php5 -l, $descriptorspec, 
$pipes);
fwrite($pipes[0], $text);
fclose($pipes[0]);
$out = '';
while(!feof($pipes[1])) {
$out .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);
proc_close($process);
chdir($cwd);
if(!empty($out)){
  $res = split(\n,$out);
  if(preg_match('/No syntax errors/',$res[0])){
$r =true;
  }else{
$error = $res[1];
if(preg_match('/Parse error:/',$error)){
  $match = preg_split('/line/',$error);
  $line = intval(trim($match[1]));
  //show error here
}
  }
}
return $r;
}

-- 
regards,
Tom

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



Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?

2007-12-10 Thread Tom Rogers
Hi,

Tuesday, December 11, 2007, 6:42:18 AM, you wrote:
RF Hello,

RF I have a command-line PHP script--called Listener--that is designed  
RF to run indefinitely with a predictable CPU usage and memory  
RF footprint. In a nutshell, it's a multi-client socket server that  
RF waits for incoming connections, processes incoming data, stores  
RF results in a MySQL database, and basically gets on with its life. And
RF it works. No errors or serious problems to speak of. And I've been  
RF running it for a couple years on an Xserve dual-G5 2GHz w/ OS X  
RF Server 10.4.11). Six months ago, the program would run for days, even
RF a couple weeks, without a hitch. The only reason I would stop the  
RF script is for some other purpose, like a software update.

RF However, the number of socket clients connecting in the past 3-4  
RF months has steadily increased, and this seems to have exposed (if not
RF created) a strange performance issue with PHP 5.2.4, MySQL 5.0.45  
RF and/or Mac OS X Server 10.4.11. (I say and/or because I am unsure  
RF where the problem's cause really lies.) Basically, after the script  
RF has been running for a day or so (processing essentially the amount  
RF data that used to take two weeks), the CPU usage of the machine goes  
RF from 30% (normal) to 80-90%. This appears to be irrespective of the  
RF number of clients connected to the server at the time, but rather the
RF amount of time the script has been running (and therefore cumulative  
RF cycles it's operated, data processed, MySQL queries executed, etc.).  
RF And the CPU usage stays high, even when the actual load (number of  
RF clients) decreases. At this time, if I run top, I get the following  
RF info:

RF 22512 mysqld  91.6%  8:22:12  31   106   125   305M+ 3.20M
RF 260M   475M
RF 17104 php  7.2% 81:14.01   115   145  5.08M  7.80M   
RF 10.9M- 87.5M
RF 22537 Terminal 6.6%  2:59:59  22   176   240  12.3M  21.2M   
RF 18.3M-  236M
RF [...]

RF At first I thought, okay, it's MySQL's fault. Maybe a lot of slow- 
RF running queries. But the slow query log is pretty clean. So maybe  
RF it's a combination of Mac OS X and MySQL and PHP? I Googled for a  
RF similar problem, and finally ran across this article:

RF http://www.shawnhogan.com/2005/10/mysql-problems-on-mac-os-x-server.html

RF ...where the author describes a very similar CPU usage pattern. I  
RF tried his suggested fixes and they seemed to have helped a little (or
RF maybe it's my wishful thinking--hard to tell), since the high CPU  
RF load issue doesn't appear to happen as soon... But it still happens.

RF Anyway, I'm really stumped as to what to do next, where to look, etc.
RF If I stop the script, and restart it (but not the MySQL itself), CPU  
RF usage goes back to normal--for about a day or two.

RF The only thing I thought might be connected is how many short-lived  
RF PHP child processes Listener creates--around 20-30,000 per day.  
RF Sounds higher, but on average it's just one every 2-3 seconds.  
RF Anyway, although the number of child processes isn't concurrent,  
RF would there be a problem with the number of historical child  
RF processes in view of ulimits or kern.maxfilesperproc?

RF Anyway suggestions, tips, or links are much appreciated. Thanks.

RF ...Rene


Put a usleep(1000) in the listen while() loop and give the cpu a
break.

-- 
regards,
Tom

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



Re[2]: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?

2007-12-10 Thread Tom Rogers
Hi,

Tuesday, December 11, 2007, 10:01:38 AM, you wrote:
RF On 10-Dec-07, at 4:42 PM, Tom Rogers wrote:


 Put a usleep(1000) in the listen while() loop and give the cpu a
 break.

RF Good advice, but I've already been doing that. The thing is, when the
RF script first starts up, the CPU rarely exceeds 30%, even when many  
RF clients (200+) are simultaneously connected and sending data. When a  
RF few clients are connected, CPU is typically below 10%. Again, it's  
RF only after 24-48 hours that, all of a sudden, CPU usage increases by  
RF 40-50%. And it stays high until I stop the script and restart it.

RF One question I have though is, is there actually any benefit to using
RF mysql_pconnect(), since the script simply loops? My understanding is  
RF that pconnect only benefits if a script would otherwise be using  
RF mysql_connect repeatedly--and this script doesn't, since it calls  
RF mysql_[p]connect() just once, in the start tof execution.

RF ...Rene

I have found pconnect to be a problem (several years ago) and have
never tried it since, it may well be ok now. The most likely cause is
memory consumption on long running php scripts, what does top say?

I have a script which runs from cron and was hammering the system when
it ran and i have had to put the usleep() in the while($result = ..)
loop as there are a few thousand rows. Probably bad design but it
works and I'm loath to touch it :)

One way to solve the memory issue is to have the script started by
inetd, slower but more memory friendly.

Also have a look at memcached to reduce the load a bit.

-- 
regards,
Tom

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



Re[2]: [PHP] adding Back to Search results link

2007-08-16 Thread Tom Rogers
Hi,

Thursday, August 16, 2007, 6:44:46 AM, you wrote:
D Jim and Brad.

D Thanks for the feedback. I was thinking it was something simple like a back
D button. But the problem that arises when I use this method is on Form 3.

D If I go through the steps, and make a change to an item on Form 3. Then use
D the a href=javascript:history.go(-2);Return to search 
D results/a.everything works fine.
D But if I dont make any changes to Form 3. then this takes me all the way
D back to the search page.

D People in my group use this form to update database information for a number
D of items. Once they make changes, they would like to go back to the search
D results, instead of having to run the same search again and again.

Have form 3 open in a new window and they just close it when finished
leaving the original on form 2.

-- 
regards,
Tom

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



Re: [PHP] Previous and Next Month and Year

2007-06-17 Thread Tom Rogers
Hi,

Sunday, June 17, 2007, 3:54:01 PM, you wrote:
KS Hi,

KS RE:  Previous and Next Month and Year

KS This is my code:

KS   $next_month = date('F Y', time()+$month);
KS   $prev_month = date('F Y', time()-$month);

KS   echo $prev_month br / \n;  #Result June 2007
KS   echo $next_month br / \n;  #Result June 2007

KS What I am trying to do is get the month and year
KS based upon a + or - $month value.

KS The variable $month being 6 for the month of June of
KS the present year of 2007.   

KS For example ($month -7) would be December 2006,
KS and ($month +7) would be January 2006.

KS Please help...  Thank you.

KS Keith


$now = strtotime(date('Y-m-15'));
$current = date('F',$now);
$last = date('F', strtotime('-1  month', $now));
$next = date('F',strtotime('+1  month', $now));
echo Current:$current Previous:$last Next:$next\n;

-- 
regards,
Tom

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



Re: [PHP] linking to an image with document_root

2007-06-01 Thread Tom Rogers
Hi,

Friday, June 1, 2007, 6:16:34 PM, you wrote:
b May be a stupid question but can I link to images with doscument root

b $img_url= $_SERVER['DOCUMENT_ROOT'].'/images/holder.gif';

b echo img src=\$img_url\ width=\250\ height=\163\/;

b I am certain the path is correct,

b If not what are my alternatives?


b R. 


You don't need anything other than the first slash and it will be from
the root of the web site. So all you need is:
$url = '/images/holder.gif';

and it will come from http://whatever.com/images/holder.gif

-- 
regards,
Tom

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



Re: [PHP] convert numerical day of week

2007-05-22 Thread Tom Rogers
Hi,

Wednesday, May 23, 2007, 2:46:38 AM, you wrote:
BD How can I convert the numerical day of week to the string version?

BD Example, if the day of the week is 1 I would like to print out 'Sunday'.

BD  

BD Thanks,

BD Dave


?php
$day =2;
//for a Monday start
echo gmdate('l',($day + 3) * 24 * 60 * 60).\n;
// for a Sunday start
echo gmdate('l',($day + 2) * 24 * 60 * 60).\n;

-- 
regards,
Tom

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



Re[2]: [PHP] Confused about handling bytes

2007-05-21 Thread Tom Rogers
Hi,

Monday, May 21, 2007, 3:57:56 PM, you wrote:
TR Hi,

TR Monday, May 21, 2007, 10:50:27 AM, you wrote:
JV While I'm sure this is a stupid question and the solution will be 
JV obvious to everyone here, this is confusing me.

JV I'm trying to control a device over a serial port using a PHP script, 
JV and one of the things I need to do is read a 26-byte string from an 
JV EEPROM, using a command that returns two bytes at a time, and write 
JV similar strings using a similar command. For example, to read the first
JV two bytes of one such string beginning at address 0x484, I would send:

JV 04 84 00 00 BB

JV Here's the code I've written so far:

JV $string = 1; //which of 200 strings I want to read
JV $base = pack(H*,dechex((($string-1)*hexdec(0x1a))+hexdec(0x484))); 
JV //calculate the base address of the string (the first starts at 0x484)
JV for($i=0;$i  13;$i++) { //iterate 13 times (26 bytes / 2 bytes at a time)
JV dio_write($serial,$base.\x00\x00\xbb,5); //send the command
JV $output[] = dio_read($serial,1);  // read first byte
JV $output[] = dio_read($serial,1); // read second byte
JV $base = pack(H*,dechex(hexdec(bin2hex($base))+2)); //increment address
JV }

JV There are two things wrong with this. First, the final line isn't doing
JV what it's supposed to. Instead of adding 2 to the value of $base each 
JV time, It's producing a pattern like this:

JV 0x484, 0x486, 0x73, 0x73, 0x73, 0x488, 0x48a, 0x48c, 0x48e, 0x490, 0x74,
JV 0x74, 0x74

JV Second, the format of $base doesn't seem to be handled correctly in line
JV 4 of the above code. Given a value of 0x484, this line should write the
JV bytes 04 84, but it is obviously not doing so, given the response I 
JV get from the device (it sends FF FF instead of the expected value at
JV that address, which I get when I remove the variable and manually 
JV specify the address).

JV What are the solutions to these problems?

JV Thanks,
JV -Joe Veldhuis


TR Do your packing after all the calculations:

TR ?php
TR $output = array();
TR $string = 1;
TR for(
TR   $i=0, $base = (($string-1) * 26) + 0x484; 
TR   $i  26;
TR   $i++, $base += 2)
TR {
TR $binarydata = pack(nc*, $base, 0, 0, 0xBB);
TR dio_write($serial,$k=strlen($binarydata),5); //send the command
TR $output[] = dio_read($serial,1);  // read first byte
TR $output[] = dio_read($serial,1); // read second byte
TR }

TR -- 
TR regards,
TR Tom


I left some sebug in there, that should have been:

?php
$output = array();
$string = 1;
for(
  $i=0, $base = (($string-1) * 26) + 0x484; 
  $i  26;
  $i++, $base += 2)
{
$binarydata = pack(nc*, $base, 0, 0, 0xBB);
dio_write($serial,$binarydata,5); //send the command
$output[] = dio_read($serial,1);  // read first byte
$output[] = dio_read($serial,1); // read second byte
}

-- 
regards,
Tom

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



Re: [PHP] Confused about handling bytes

2007-05-20 Thread Tom Rogers
Hi,

Monday, May 21, 2007, 10:50:27 AM, you wrote:
JV While I'm sure this is a stupid question and the solution will be 
JV obvious to everyone here, this is confusing me.

JV I'm trying to control a device over a serial port using a PHP script, 
JV and one of the things I need to do is read a 26-byte string from an 
JV EEPROM, using a command that returns two bytes at a time, and write 
JV similar strings using a similar command. For example, to read the first
JV two bytes of one such string beginning at address 0x484, I would send:

JV 04 84 00 00 BB

JV Here's the code I've written so far:

JV $string = 1; //which of 200 strings I want to read
JV $base = pack(H*,dechex((($string-1)*hexdec(0x1a))+hexdec(0x484))); 
JV //calculate the base address of the string (the first starts at 0x484)
JV for($i=0;$i  13;$i++) { //iterate 13 times (26 bytes / 2 bytes at a time)
JV dio_write($serial,$base.\x00\x00\xbb,5); //send the command
JV $output[] = dio_read($serial,1);  // read first byte
JV $output[] = dio_read($serial,1); // read second byte
JV $base = pack(H*,dechex(hexdec(bin2hex($base))+2)); //increment address
JV }

JV There are two things wrong with this. First, the final line isn't doing
JV what it's supposed to. Instead of adding 2 to the value of $base each 
JV time, It's producing a pattern like this:

JV 0x484, 0x486, 0x73, 0x73, 0x73, 0x488, 0x48a, 0x48c, 0x48e, 0x490, 0x74,
JV 0x74, 0x74

JV Second, the format of $base doesn't seem to be handled correctly in line
JV 4 of the above code. Given a value of 0x484, this line should write the
JV bytes 04 84, but it is obviously not doing so, given the response I 
JV get from the device (it sends FF FF instead of the expected value at
JV that address, which I get when I remove the variable and manually 
JV specify the address).

JV What are the solutions to these problems?

JV Thanks,
JV -Joe Veldhuis


Do your packing after all the calculations:

?php
$output = array();
$string = 1;
for(
  $i=0, $base = (($string-1) * 26) + 0x484; 
  $i  26;
  $i++, $base += 2)
{
$binarydata = pack(nc*, $base, 0, 0, 0xBB);
dio_write($serial,$k=strlen($binarydata),5); //send the command
$output[] = dio_read($serial,1);  // read first byte
$output[] = dio_read($serial,1); // read second byte
}

-- 
regards,
Tom

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



Re: [PHP] [EMAIL PROTECTED]

2007-05-10 Thread Tom Rogers
Hi,

Wednesday, May 9, 2007, 11:13:50 PM, you wrote:
FJ Hello,

FJ To me this seems to be a very strange problem.

FJ I have a static html page (index.html) that shows correctly on both FF2 
FJ IE7.

FJ I splitted the website up into different sections: (header, footer, ...). To
FJ do this I have used:
FJ --
FJ ?php
FJ require(header.php);
?
FJ Some code goes here...
FJ ?php
FJ require(footer.php);
?
FJ --
FJ  and so on.
FJ When I test my page (now index.php), it shows perfect on Firefox, but in IE
FJ some stuff are not in their right place. I have checked the source code of
FJ both index.html and index.php and they seem both identical to me.

FJ Do you know why IE fails to correctly render the page?

FJ Thanks 


Could be stray carriage returns in your include files, good idea to
remove any '? in the include files as they are not needed.

-- 
regards,
Tom

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



Re[2]: [PHP] [EMAIL PROTECTED]

2007-05-10 Thread Tom Rogers
Hi,


Could be stray carriage returns in your include files, good idea to
remove any '? in the include files as they are not needed.

Perhaps I should have said:

remove any '?' at the END of the include file as they are not needed,
of course any escaping to html in the middle will still be needed. :)


-- 
regards,
Tom

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



Re: [PHP] copy file from server to shared network folder

2007-04-19 Thread Tom Rogers
Hi,

Friday, April 20, 2007, 2:04:14 PM, you wrote:
HH Hi everyone,
HH I can't seem to be able to copy a txt file from the server over to a network
HH drive.
HH Server is apache on winxp and the remote PC is also running XP.
HH Remote folder is shared with all read/write rights enabled.
HH I also tried executing a bat file where the bat file contains the copy
HH command and that didn't work either.
HH 2x clicking on the bat file works.
HH I tried
HH echo exec(c:\\test.bat);
HH and also
HH echo system (c:\\test.bat);
HH and
HH exec('c:\Windows\system32\cmd.exe /c START c:\test.bat');
HH and
HH exec('c:\\Windows\\system32\\cmd.exe /c START c:\\test.bat');
HH with no success.
HH The last 2 items did launch the cmd process.
HH Any ideas?

Apache won't have rights to access the network, you need to read:
http://httpd.apache.org/docs/1.3/win_service.html

-- 
regards,
Tom

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



Re: [PHP] Bind IP with fsockopen

2007-04-07 Thread Tom Rogers
Hi,

Sunday, April 8, 2007, 6:51:46 AM, you wrote:
cac Hi is it possible to socket_bind with fsockopen? im using this with all my 
scripts...

cac $fs = fsockopen('example.com', 2043, $errno, $errstr, 60);
cac if (!$fs) {
cac fclose($fs);

cac and I need the remote conection to see me as one of my other IP's

cac Ive read through socket_bind
cac http://uk.php.net/manual/en/function.socket-bind.php

cac but cant see how to use it with my above code

cac Thanks

You will have to do it using the socket api something like this but
with error checking:

?php
$sourceip = '192.168.1.1'; // ip you want to bind to
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $sourceip);
socket_connect($sock, 'example.com', 2043);
// Write
$request = 'GET / HTTP/1.1'.\r\n.'Host: example.com'.\r\n\r\n;
socket_write($sock, $request);
//Read reply
// Close
socket_close($sock);

? 


-- 
regards,
Tom

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



Re[2]: [PHP] Bind IP with fsockopen

2007-04-07 Thread Tom Rogers
Hi,

TR You will have to do it using the socket api something like this but
TR with error checking:

TR ?php
TR $sourceip = '192.168.1.1'; // ip you want to bind to
TR $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
TR socket_bind($sock, $sourceip);
TR socket_connect($sock, 'example.com', 2043);
TR // Write
TR $request = 'GET / HTTP/1.1'.\r\n.'Host: example.com'.\r\n\r\n;
TR socket_write($sock, $request);
TR //Read reply
TR // Close
TR socket_close($sock);

Another option using streams (php5):

?php
$opts = array(
'socket'=array(
'bindto'='192.168.1.1:0' //any port will do
)
);
$context = stream_context_create($opts);
$html = file_get_contents('http://example.com:2043', false, $context);


-- 
regards,
Tom

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



Re[2]: [PHP] symlink

2006-09-23 Thread Tom Rogers
Hi,

Saturday, September 23, 2006, 10:37:20 AM, you wrote:
RL On Mon, September 18, 2006 4:53 pm, Ross wrote:
 Can someone explain how and why you would use a symlink in php?

RL A symlink is the Un*x version of a Windows shortcut or the Mac's
RL alias

RL The difference being that a symlink actually *works* and a Windows
RL shortcut is useless for anything except their crappy desktop app...

in windows 2k and xp you can use fsutil to create hard links in the
same NTFS volume.

Usage : fsutil hardlink create new filename existing filename

fsutil hardlink create c:\foo.txt c:\bar.txt

But it probably has a few bugs of its own :) and it can't do your edit
trick as it only works on files not directories as far as I can tell.


-- 
regards,
Tom

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



Re: [PHP] Image submit with mouse over

2006-07-14 Thread Tom Rogers
Hi,

Saturday, July 15, 2006, 9:13:04 AM, you wrote:
SE Hi all,

SE Brand new to the list, so here's my question. I am 
SE   implementing a bunch of Dreamweaver templates a 
SE designer has built into a PHP app, and one thing 
SE she did is create a submit button (image) that 
SE uses mouse over JS:

SE a href=user.php?req=login target=_top 
SE 
onMouseOver=MM_swapImage('signin','','/theme/images/admin/button_signin2.gif',1)
SE onMouseOut=MM_swapImgRestore()img 
SE src=/theme/images/admin/button_signin.gif 
SE alt=Sign In name=signin width=86 height=20 
border=0/a

SE But notice this is an href, and it also needs to 
SE submit $_POST data through a couple of form fields 
SE that appear above. So what I tried to do in order 
SE to be able to retrieve the POST data on the 
SE receiving end was convert it to the following:

SE input type=image 
SE src=/theme/images/admin/button_signin.gif 
SE 
onfocus=MM_swapImage('signin','','/theme/images/admin/button_signin2.gif',1)
SE onblur=MM_swapImgRestore()

SE ...However, the onfocus and onblur are not 
SE swapping out the images, as I had hoped. (Against 
SE all odds, maybe I should add.)

SE I know the client will pout and sniffle if they 
SE don't get their mouse over affect, so I am hoping 
SE for a solution.

SE Any suggestions would be greatly appreciated.

SE Thanks!
SE -- 
SE Skip Evans
SE Big Sky Penguin, LLC
SE 61 W Broadway
SE Butte, Montana 59701
SE 406-782-2240


to the href add onClick=formname.submit();return false;

or something like that.

-- 
regards,
Tom

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



Re[2]: [PHP] GET, POST, REQUEST

2006-06-18 Thread Tom Rogers
Hi,

Sunday, June 18, 2006, 5:19:20 PM, you wrote:
S - Original Message - 
S From: Rory Browne [EMAIL PROTECTED]


 Good code won't be vulnerable to register_globals either, but having
 register_globals on is a security problem because there are security flaws
 that can only be exploited when register_globals is enabled.


S Actually, code quality cannot overcome the vulnerability of 
S register_globals.  Every program will have global variables. 
S register_globals=on may overwrite a valid global variable, one totally
S unrelated to user input, with a value coming from the request, and there is
S nothing good coding can do about it. The chances that an external user might
S hit the right variable name are slim (unless a disgruntled former 
S programmer) but they exist.

S Satyam


Just get into the habit of setting all variables to known values
before using them will take care of this problem. Set the warning
level to E_ALL and get warned when using variables that have not been
set to good values while in the development phase.

-- 
regards,
Tom

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



Re[2]: [PHP] Passing an indefinite number of parameters by reference

2006-05-08 Thread Tom Rogers
Hi,

Monday, May 8, 2006, 8:46:38 PM, you wrote:
CJ Tom Rogers wrote:
 Here is a cutdown version of a class loader I use, It works for php4 and
 php5 and with references. It should be easy to modify.

CJ [...]

CJ Sorry, this does not work with references as func_get_args() copies the
CJ arguments passed, rather than keeping them as references. This means 
CJ that the $variable1, $variable2, etc. variables are only references to
CJ the copy made with func_get_args(), rather than to the variables passed
CJ to the first function.

CJ Chris


Here is a modified version using arrays (tested php4/5)

?php
$a = 1;
$b = 1;
function test_vars($function, $array){
  $num_args = count($array);
  $vars = $function.'(';
  if($num_args  0) {
for ($i=0; $i  $num_args; $i++) {
  $vars .= ($i  0)? ',':'';
  $varname = 'variable'.$i;
  $$varname = $array[$i];
  $vars .= \$$varname;
}
  }
  $vars .= ');';
  eval($vars);
}
function test($a){
  $a++;
}
function test2($a, $b){
  $a++;
  $b++;
}
echo $a\n;
test($a);
echo $a\n;
test_vars('test',array($a));
echo $a\n;
test_vars('test2',array($a,$b));
echo $a : $b\n;

// a test on a function we have no control over
$string = This is a test;
$match = array();
test_vars('preg_match',array('/(\w+) (\w+) (\w+) (\w+)/',$string,$match));
print_r($match);

-- 
regards,
Tom

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



Re: [PHP] Passing an indefinite number of parameters by reference

2006-05-07 Thread Tom Rogers
Hi,

Monday, May 8, 2006, 4:20:11 AM, you wrote:
CJ Hi,

CJ Currently I have a function which accepts a limited number of parameters:

CJ call_function($function_name, $var_1, $var_2);

CJ I wish to modify the function to accept an indefinite number of 
CJ parameters, which may or may not be references.

CJ The function call_function() then calls the function specified in 
CJ $function_name, with the variables passed as parameters to that function.

CJ Is this possible? Thanks for any help which can be offered.

CJ Chris

Here is a cutdown version of a class loader I use, It works for php4 and
php5 and with references. It should be easy to modify.

?php
function load_class($class_name,$arg1,$arg2,$arg3){
  $num_args = func_num_args();
  $arg_list = func_get_args();
  
  $vars = '$return = new '.$class_name.'(';
  if($num_args  1) {
for ($i = 1; $i  $num_args; $i++) {
  $vars .= ($i  1)? ',':'';
  $varname = 'variable'.$i;
  $$varname = $arg_list[$i];
  $vars .= \$$varname;
}
  }
  $vars .= ');';
  eval($vars);
  return $return;
}
?

-- 
regards,
Tom

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



Re[2]: [PHP] Problems creating images

2006-04-06 Thread Tom Rogers
Hi,

Friday, April 7, 2006, 6:20:41 AM, you wrote:
AB Tom Rogers wrote:


AB There isn't. I've got the suspicion it's got to do with the UTF-8 
AB character encoding because of the characters '', I've seen this 
AB before with HTML pages. Because of this I asked the person who's having 
AB the problems to upload and test three different files versions of the 
AB php file:

AB - ANSI
AB - UTF-8
AB - ANSI UTF-8 without BOM

AB None had any effect what so ever. What else can I try?

AB Philip Hallstrom pointed out that the returning header is set to 
AB 'Content-Type: text/html; charset=iso-8859-1' instead of 'Content-type: 
AB image/jpeg'. What could be the cause of this?

AB Yours,

AB Age


put

error_reporting( E_ALL);

at the top of the script and see if any error messages show up.
The fact that the mime type is text seems to indicate some output has gone to
the client before your header call. That could be any white space outside of
?php..? and could be in an include file or prepend file as well.
-- 
regards,
Tom

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



Re: [PHP] Problems creating images

2006-04-05 Thread Tom Rogers
Hi,

Thursday, April 6, 2006, 5:42:05 AM, you wrote:
AB Hi,

AB I added image confirmation to a guestbook and even though it works 
AB greate for most people, some people have problem and I can't seem to 
AB figure out why this happens. Note that I'm not talking about the same 
AB guestbook on one server but the guestbook is on people's own hosting server.

AB The php code to create the image can't be simpler:

AB *confirm_image.php:*
AB $datekey = date(F j);
AB $rcode = hexdec(md5($_SERVER[HTTP_USER_AGENT] . $cfg_sitekey . 
AB $random_num . $datekey));
AB $code = substr($rcode, 2, 6);
AB $image = ImageCreateFromJPEG(images/code_bg.jpg);
AB $text_color = ImageColorAllocate($image, 80, 80, 80);
AB Header(Content-type: image/jpeg);
AB ImageString ($image, 5, 12, 2, $code, $text_color);
AB ImageJPEG($image, '', 75);
AB ImageDestroy($image);

AB Most people get a nice image but some people get only, what appears to 
AB be, garbage:

AB ÿØÿàJFIFÿþ;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), 
AB quality = 75 ÿÛC    $.' 
AB ,#(7),01444'9=82.342ÿÛC  
AB 2!!22ÿÀ
AB ...snip...

AB For the complete output have a look here:
AB http://www.samuel-area.de/phpbook/confirm_image.php

AB Do you know what is going wrong here?

AB Yours,

AB Age


Make sure you don't have any blank lines before the ?php

-- 
regards,
Tom

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



Re: [PHP] Multidimentional array problems

2006-04-03 Thread Tom Rogers
Hi,

Tuesday, April 4, 2006, 8:37:18 AM, you wrote:
ME Hi, 

ME I am trying to read form a database and place everything in a 
ME multi-dimentional array

ME This is what I am doing and the output (for testing) seems correct
ME while($row=mysql_fetch_array($result))
ME {
ME   $banner= array($arrayIndex = $row);

ME   echo $banner[$arrayIndex][image]. br;
ME   echo $banner[$arrayIndex][url]. br;
ME   echo $banner[$arrayIndex][display_type]. br;
ME   $arrayIndex++;
ME }


ME When I try and use
ME $value=0;
ME  while($value  $number_of_banners_db )
ME  {
ME echo $banner[$value][url]. br;
ME echo $banner[$value][image]. br;
ME echo $banner[$value][display_type]. br;
ME  }

ME I only get the last set of values that where entered into the array.  I 
ME want to be able to pull all the values out

ME $banner[0]['url']
ME $banner[1]['url']
ME $banner[2]['url']  etc.

ME I don't use arrays much and I have been going thru my books but I still 
ME can't seem to get it to work.

ME Thanks

You are creating a new $banner each time it loops.
It should be like this:

$banner = array();
$arrayIndex = 0;
while($row=mysql_fetch_array($result))
{
  $banner[$arrayIndex] = $row;

  echo $banner[$arrayIndex][image]. br;
  echo $banner[$arrayIndex][url]. br;
  echo $banner[$arrayIndex][display_type]. br;
  $arrayIndex++;
}

-- 
regards,
Tom

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



Re: [PHP] Formatting a Time field

2006-03-23 Thread Tom Rogers
Hi,

Friday, March 24, 2006, 9:51:48 AM, you wrote:
TC I have a field, Start_Time, in a MySQL DB.  Since it is not a 
TC TimeStamp, I believe I cannot use date(), correct?

TC I would like to format 09:00:00 to 9:00 AM.

TC If I convert the 09:00:00 with the strtotime(), I get a couple of 
TC extra minutes added.

TC Suggestions are welcomed

TC Todd


use gmdate() to do the formatting. in strtotime you should give a date something
like
$ftime = gmdate('h:i A',strtotime(2000-01-01 $Start_Time));

-- 
regards,
Tom

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



Re: [PHP] mysql help..

2006-02-24 Thread Tom Rogers
Hi,

Saturday, February 25, 2006, 5:53:23 AM, you wrote:
gu Hi all,

gu I installed a opensource php project, and now is working fine for me.
gu Now that project has some 40-50 MySQL tables..

gu now I want to change something in that but the I am not able to get the DB
gu flow..
gu Is any body knows any tool by which we can create/make the relationship
gu diagram like we are doing in SQLserver or Access..

gu To understand the DB is very tough... any body knows how I can create the
gu relationship diagram from that .SQL file...

gu thnx to alll...

Try DbDesigner4, it will reverse engineer an existing database as much as it 
can.

http://fabforce.net/

-- 
regards,
Tom

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



Re: [PHP] Newbie Question Can't insert values into MySQL DB via PHP

2006-02-10 Thread Tom Rogers
Hi,

Friday, February 10, 2006, 8:16:41 PM, you wrote:
DT Hi,

DT I'd like to say in advance that I am sorry about the silly and very newbie
DT question I'm asking.

DT I am having a problem with a shop system. I can't add values into the MySQL
DT DB via a PHP statement. The values are being transferred from one page to
DT another (know that from the echo statement), but the SQL statement isn't
DT working.

DT The statement is as follows:

DT $conn = mysql_connect($DBhost,$DBuser,$DBpass) or die('Unable to connect to
DT database');
DT $t = $_GET['newdvdtitle'];
DT $y = $_GET['newdvdyear'];
DT $c = $_GET['newdvdcost'];
DT $p = $_GET['newdvdpurchased'];
DT @mysql_select_db($DBName) or die(Unable to select database $DBName);
DT $sqladd = INSERT INTO 'dvd' ('id', 'title', 'year','cost','purchased')
DT VALUES (  NULL , '$t', '$y', '$c' , '$p' );
DT echo $sqladd;
DT $result = mysql_query($sqladd);


DT The information is sent from another page which has the following values:


DT form name=add method=get action=addvalue.php

DT ?php
DT echo 'tabletrtdInsert a DVD/td/tr';
DT echo 'trtdinput type=text name=newdvdtitle DVD name/td/tr';
DT echo 'trtdinput type=text name=newdvdyear DVD year/td/tr';
DT echo 'trtdinput type=text name=newdvdcost DVD cost/td/tr';
DT echo 'trtdinput type=text name=newdvdpurchased DVD date
DT purchased/td/tr';
DT echo 'trtdinput type=submit value=Insert new dvd/td/tr';
DT echo '/table';
?
DT /form


DT Thanks in advance,

DT Douglas

Don't put the table name in quotes, use the back tick `dvd`

-- 
regards,
Tom

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



Re: [PHP] REGEX query

2006-02-09 Thread Tom Rogers
Hi,

Saturday, February 4, 2006, 2:53:32 PM, you wrote:
p Hi,

p I'm still trying to get to grips with REGEX and have hit a hurdle with
p the following:

p I have this bit of text:
p (\(EX\) RV-6 )

p I want to remove the '\(EX\)' part of it
p so leaving just: ( RV-6 )

p Any suggestions would be most appreciated.

p Thanks
p Alexis


I would use preg_replace_callback() for something like this:
(untested)

?php

$string = 'some text (\(EX\) RV-6 ) and the end.';

fumction cb($data){
 $r = $data; //just in case not good format
 $parts = split(' ',$data);
 if(count($parts)  1){
   $r = '( '.$parts[1].' )';
 }
 return $r;
}


$new_string = preg_replace_callback('/\(\\\(\w+\\\)\s[\w-]+\s\)/s','cb', 
$string);

-- 
regards,
Tom

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



Re: [PHP] Missing characters

2006-02-06 Thread Tom Rogers
Hi,

Tuesday, February 7, 2006, 9:01:18 AM, you wrote:
FA I need a helping hand to solve this
  
FA Example
FA Page1.php
FA ===
FA $name_pro = VC++ V2.4
FA print td width='200' class='texto2' a 
FA href='page2.php?page=value=$name_pro' $name_pro /a /td;
FA ===

FA Page2.php
FA ===
FA echo $value ; //Prints out VC V2.4 and I need VC++ V2.4

FA Thanks in advance.


You will need to use urlencode() on the $name_pro in the href tag.

like:

$name_pro = VC++ V2.4
print td width='200' class='texto2'
a href='page2.php?page=value=.urlencode($name_pro).' $name_pro /a /td;

-- 
regards,
Tom

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



Re: [PHP] manipulating constant name as string

2006-01-01 Thread Tom Rogers
Hi,

Monday, January 2, 2006, 4:37:17 AM, you wrote:
DG Hello

DG I am trying to access the constant name as string and not the constant
DG contents. For example,

DG define('myconst', 'const text 1');

DG $myArray = array()

DG myArray['myconst'] = this is it
DG etc.

DG $xmltext=;
DG foreach ($myArray as $key = $val) {
DG echo $key = $val\n\n;
DG $xmltext .= $xmltext = $xmltext . $key $val /$key;
DG }

DG Unfortunately, $key within the string concatenation is translated into
DG the constant value. However, for the echo statement, then $key constant
DG name is displayed. Is there a way to keep the constant name rather its
DG value when manipulating it as a string?

DG thanks,

DG Daniel

drop the single quotes to use the constant:

myArray[myconst] = this is it
-- 
regards,
Tom

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



Re[2]: [PHP] regex and global vars problem

2005-10-28 Thread Tom Rogers
Hi,

Friday, October 28, 2005, 7:20:58 PM, you wrote:
RV On 10/28/05, Tom Rogers [EMAIL PROTECTED] wrote:

 I would do it with a small class like this:

RV $mactest  = new mac(there are a few gotchas for anyone using this);
print $mactest-is_valid ? valid\n : invalid\n;

RV // valid

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


It does reduce to a valid mac address (EE:AE:AF:EC:AF:AE) :)
-- 
regards,
Tom

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



Re[2]: [PHP] calling static method within class

2005-10-28 Thread Tom Rogers
Hi,

Saturday, October 29, 2005, 5:42:15 AM, you wrote:
CR If you're expecting the statement 

CR Echo Foo::getUs(); 

CR To echo me me it will not because you never returned $us from the
CR getUs() method. I'm assuming also that xxx is a variable to mean some
CR class library correct?

CR Carlo Razzeto
CR Programmer
CR Mortgage Information Services
CR Phone: (216) 514-1025 ex. 1212

CR -Original Message-
CR From: blackwater dev [mailto:[EMAIL PROTECTED] 
CR Sent: Friday, October 28, 2005 1:13 PM
CR To: php-general@lists.php.net
CR Subject: [PHP] calling static method within class

CR I have a class that won't be instantiated...so basically just a bunch
CR of static methods.

CR How do I call one of the class' static methods from within another
CR method?  Can't use this, and self doesn't work...this is php4.

CR Thanks.

CR Class Foo{

CRfunction getMe(){
CR return me;

CR   }

CR   function getUs(){
CR$us=xxx::getMe();
CR$us.= me;

CR   }
CR }

CR echo Foo::getUs();

Just use the class name Foo::getMe()

Class Foo{

   function getMe(){
return me;

  }

  function getUs(){
   $us=Foo::getMe();
   $us.= me;

  }
}

-- 
regards,
Tom

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



Re: [PHP] regex and global vars problem

2005-10-27 Thread Tom Rogers
Hi,

Thursday, October 27, 2005, 3:15:30 AM, you wrote:
JG I am having a problem with a couple of function I have written to check
JG for a type of string, attempt to fix it and pass it back to the main
JG function.  Any help is appreciated.

I would do it with a small class like this:

?php
class mac{
  var $mac='';
  var $is_valid = false;
  function mac($mac){
$mac = preg_replace('/[^0-9A-F]/','',strtoupper($mac));
if($this-is_valid = 
preg_match('/^(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})$/',$mac,$parts)){
  array_shift($parts); //lose the first bit
  $this-mac = implode(':',$parts);
}
  }
}

//test
$mac_list = 
array(00-aa-11-bb-22-cc,00:aa:11:bb:22:cc,zz:00:11:22:ff:xx,00 aa 11 bb 
22 cc);

foreach($mac_list as $mac){
  $mactest = new mac($mac);
  echo In:$mac;
  if($mactest-is_valid){
echo  valid $mactest-mac\n;
  }else{
echo  NOT valid\n;
  }
}

-- 
regards,
Tom

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



Re[2]: [PHP] Ugh, w32 anything is making me want to drink!

2005-10-21 Thread Tom Rogers
Hi,

Saturday, October 22, 2005, 6:26:57 AM, you wrote:
JB [snip]
 I just noticed that extension_dir in phpinfo is c:\php4 THAT AIN'T RIGHT!
 Why is PHP not loading the proper ini file? This is probably the source of
 my problems all along! ACK!
 

JB This is what happens when you go over to the dark side.
JB [/snip]

JB It's not my fault! How do I fix this?


I always put the php.ini file where the .exe file is, so for apache put it
where apache.exe is if loading as a module or where php.exe is if
using cgi

-- 
regards,
Tom

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



Re: [PHP] Template Security Advice (WASP - http://wasp.sourceforge.net)

2005-10-12 Thread Tom Rogers
Hi,

Tuesday, October 11, 2005, 3:37:13 PM, you wrote:
BF I'm finishing up my WASP framework 1.0 release (http:// 
BF wasp.sourceforge.net) and I'm trying to decide the best way to lay
BF out the template directories.

BF WASP uses HTML_Template_Flexy for its template system.  The templates
BF are compiled using Chunk classes that each refer to a html template.

BF The way it works now, the directory structure of applications is
BF |_ /webroot/module/templates

BF where module is where the php classes are stored, and templates is
BF where the html templates are stored.  The templates used to be stored
BF in a seperate directory outside of the web root, as such
BF |_ /templates/
BF |_ /webroot/ModuleDir

BF however it becomes cumbersome to keep track of which templates go to
BF which php classes, so for organization sake having the template  
BF directory located beneath each module directory is easier to navigate.

BF My problem is, anyone who realizes a particular application uses WASP
BF can go to a url, say http://blah/module, and look at the html files
BF in the template directory (ex. http://blah/module/templates). Is it
BF too much of a security issue to justify this useful organization?
BF Theoretically the addition of an .htaccess file in the templates  
BF directories could solve the problem, but is that compounding the  
BF issue even more?  I guess I'm asking for someone to tell me it's ok
BF to do it this way, but if nobody agrees I can change it back.

BF Thanks for the input.
BF -Brian


BF /**
BF   * Brian Fioca
BF   * Chief Scientist / Sr. Technical Consultant
BF   * PangoMedia - http://pangomedia.com
BF   * @work 907.868.8092x108
BF   * @cell 907.440.6347
BF   */

What about:

|_ /templates/ModuleDir
|_ /webroot/ModuleDir


Or even better if the modules should not be accessed directly

|_ /Modules/ModuleDir
|_ /Modules/ModuleDir/templates/
|_ /webroot/

ModuleDir
-- 
regards,
Tom

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



Re: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread Tom Rogers
Hi,

Saturday, September 3, 2005, 9:19:11 AM, you wrote:
MS hello,

MS I'm writing a socket approach to send email directly via an SMTP server
MS (since some hosts block sendmail trough php due to abuse). Now, I have
MS the code, attached below:
MS I have cut it down slightly so it would still be readable though. I'm
MS very sure that none of the stuff I removed actually matters in the
MS problem though (mostly error chechking, logging, debug stuff, etc).

MS Ok, back to the problem. If I reread my log, I see the following output:
MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2)
MS C: HELO ip
MS S:
MS C: MAIL FROM: [EMAIL PROTECTED]
MS S: 250 server OK, server2 [ip].
MS C: RCPT TO: [EMAIL PROTECTED]
MS S:
MS C: RSET

MS Now, obviously, the server sends something back (I checked, manually,
MS using telnet). So, I figured that the socket_read(socket, size, 
MS PHP_NORMAL_READ) was causing the problem. So I switched over to 
MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke
MS off eg. midways). So... after I changed that, I suddenly started getting
MS these errors:
MS Warning: socket_read() unable to read from socket [11]: Resource 
MS temporarily unavailable in /home/me/scripts/mail.php on line 27

MS This goes for each attempt to read (even the first). I'm stumped... and
MS really don't know how to proceed now...

MS Does anyone have any clues?
MS very appreciated,

Because of this line the function returns straight away.

MS socket_set_nonblock($this-socket);

You have to catch the 'not ready' error something like this:
(The error code was under windows)

function get(){
  $ret = '';
  while(1){
$sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ);
if(false === $sbuf){
  $error = socket_last_error($this-connection);
  if($error != 10035){
echo msgsock read() failed: reason:  .$error.' '. socket_strerror 
(socket_last_error($this-connection)) . \n;
return;//socket not happy
  }
}else{
  $buf_read = strlen($sbuf);
  if($buf_read === 0) break; // end of text
  $ret .= $sbuf;
}
  }
  return $ret;
}





-- 
regards,
Tom

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



Re[2]: [PHP] socket_read() trouble with PHP_BINARY_READ

2005-09-03 Thread Tom Rogers
Hi,

Saturday, September 3, 2005, 6:49:54 PM, you wrote:
MS hello,

MS thank you for the help, but I've tried your code, and it returns the
MS exact same thing :( the error #11 temporarily unavailable. If I remove
MS non-blocking, or change the error to ignore to 11 (10035 in your code
MS example) it simply hangs doing nothing *at all*...

MS I'm stumped; really.. thank you for trying though :)

Looking at your code, in the functions you have $this-connection but
the class uses $this-socket. In your application it is better not to
use blocking I think.

-- 
regards,
Tom

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



Re[2]: [PHP] mail()

2005-08-17 Thread Tom Rogers
Hi,

Thursday, August 18, 2005, 3:02:40 AM, you wrote:
GB André Medeiros wrote:
 Do you have a mail server running?
GB No, how do I get a mail server running? And does it allow me to receive
GB e-mails, or only send?


Try this, they have a free version which will do what you want.
If you have a fixed IP you can even receive your own mail.

http://mailenable.com/

-- 
regards,
Tom

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



Re[2]: [PHP] Environment Variable contamination between vhosts - 1.3.33

2005-08-08 Thread Tom Rogers
Hi,

Tuesday, August 9, 2005, 3:04:41 AM, you wrote:

MP Using --

MP #!/usr/bin/perl
MP ##
MP ##  printenv -- demo CGI program which just prints its environment
MP ##

MP print Content-type: text/plain\n\n;
MP foreach $var (sort(keys(%ENV))) {
MP $val = $ENV{$var};
MP $val =~ s|\n|\\n|g;
MP $val =~ s||\\|g;
MP print ${var}=\${val}\\n;
MP }

MP I do not see the issue. This is why the apache guys thought it was a php
MP issue.

MP --
MP Marc

MP p.s. I changed the reply-to to keep it on-list. I don't know where
MP '[EMAIL PROTECTED]' goes.

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


Do you get the same problem if you run php as a cgi?
It maybe something related to apache child processes retaining the
previous env ??
I gave up using pconnect because of something similar with it
remembering a previous unrelated db access.

-- 
regards,
Tom

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



Re: [PHP] Tracking a mobile phone

2005-07-19 Thread Tom Rogers
Hi,

Tuesday, July 19, 2005, 5:15:10 AM, you wrote:
T Hi there,

 

T I was wondering if anybody has attempted to track a mobile phone through a
T country. I know that this is usually more a case for the FBI . a friend of
T mine is going on a 4 month bike tour and I would like to 'track' him for
T locations. I thought of an sms receiving system, but if could do any other
T way would be great.

 

T Any ideas?

 

T Thomas


This may be of interest :)

http://www.aspicore.com/en/tuotteet_tracker.asp?tab=2sub=4

Funny enough it looks a php solution.

-- 
regards,
Tom

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



Re: [PHP] Find largest integer filename

2005-07-06 Thread Tom Rogers
Hi,

Wednesday, July 6, 2005, 2:43:38 PM, you wrote:
RL Suppose I have a directory with a HUGE number of filenames, all of which
RL happen to look like integers:

RL ~/nntp/1
RL ~/nntp/2
RL ~/nntp/3
RL .
RL .
RL .
RL ~/nntp/59874
RL ~/nntp/59875
RL ~/nntp/59876

RL Now, in a PHP script, what's the most efficient way to find the largest
RL filename, where largest means in the sense of an integer, not a string?

RL I could probably force the filenames to be 0-padded if that would make a
RL significant difference.

RL Is there some nifty shell command I should just exec?...

RL I don't really care which shell, but I'm a bash user generally.

RL Obviously I could loop through all the filenames, so I'm looking for
RL something faster than that. :-)

RL -- 
RL Like Music?
RL http://l-i-e.com/artists.htm


You could try:

$last = exec('ls -D /fullpath/nntp | sort -n');
echo Largest: $lastbr;

-- 
regards,
Tom

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



Re: [PHP] Currency stored as cents

2005-07-02 Thread Tom Rogers
Hi,

Saturday, July 2, 2005, 6:57:07 PM, you wrote:
S The lack of a specific type to store monetary values is something of a
S problem with commercial applications.  Be it that you have value added tax
S or sales tax to add per-item to an invoice or any other calculation like
S commissions, discounts and such, you end up with an endless number of
S insignificant decimals which cause trouble.  If you forget to round off the
S extra decimals, comparing for equality doesn't always work, if you carry a
S running total with the whole decimals, the total of the invoice might not
S always come good, as the rounding of the total might differ from the total
S of the rounded individual values. Been there, wrecked that.  I've been
S avoiding this traps out of discipline and hard work, but it is really
S tiresome.

S Thus, I was thinking, is there a better way?  Even Microsoft added a
S currency data type to its Visual Basic long ago.  Shall we wait?

S In the meantime, how about storing monetary values as integers, and storing
S them in the database as integers as well. You see, to show them in the
S screen, I always pass them through a formatting function. Whenever I read
S them from the user input, I do it through a parsing function.  If those
S functions scale the value the appropriate number of decimal places, nobody
S cares how it is used internally.  And currency values, no matter what you do
S with them, they always scale the same way.  You will never multiply two
S currency values together.  There is no such a thing as dollars-squared.  If
S you have two positions for cents, it will always be so, no matter what you
S do with them.

S I guess, it would be prudent to have a scaling factor to allow for, for
S example, tenths of cents.  Several kind of businesses express their unit
S prices in fraction of cents, because they never actually sell units and the
S difference does add up in the total.  So, you might set that factor to zero,
S for those currencies that use no cents (as was the case with the Italian
S Lira or the Spanish Peseta), two, as for the Euro or Dollar, or even three
S or four, for certain specific business.  Anyhow, the only functions that
S would care about this scaling factor would be the user input/output
S functions, internally within the application, you wouldn't care.  Actually,
S it would need to values, the scaling factor (which might be three) and the
S number of decimal places (which might be two).

S Of course, integers have a range limit, and the type of business has to be
S the kind that manages with only that.

S Now, am I missing something in all this?  Please comment.  Thanks

S Satyam


I store dollar amounts as integers and use this function to convert

function dollars2cents($value){
  $value = sprintf(%0.2f,trim($value));
  list($a,$b) = explode('.',$value);
  if(floatval($value)0) $b = $b*-1; //negative amount?
  return intval($a)*100 + intval($b);
}

-- 
regards,
Tom

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



Re: [PHP] getting a filename [with no extension] out of a url

2005-06-30 Thread Tom Rogers
Hi,

Friday, July 1, 2005, 9:54:42 AM, you wrote:
GA if  $_SERVER['SCRIPT_NAME'] give this
GA /folder/folder/Library/php/filename.php

GA what would be the proper way to strip the string until only 'filename'
GA is left
GA I'm a bit new at eregi stuff

GA any help would be appreciated
GA many thanks

GA g


I do this:
$file = '/folder/folder/Library/php/filename.php';
$ext = @substr($file, (@strrpos($file, .) ? @strrpos($file, .) + 1 : 
@strlen($file)), @strlen($file));
$fname = basename($file,$ext);

-- 
regards,
Tom

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



Re: [PHP] Breaking up data efficiently

2005-06-27 Thread Tom Rogers
Hi,

Tuesday, June 28, 2005, 9:34:28 AM, you wrote:
WK Hi All,

WK I'm working on an aircraft booking system and it has multiple
WK origin/destination data, concatenated into a single line:


WK /* BEGIN DATA */

WK Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 18:00:00|Perth,
WK AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00

WK /* END DATA */


WK As you can see, each origin/destination is separated by a pipe '|', and
WK then, each origin/destination data has its location, country and
WK datetime of departure/arrival, separated by comma ','.

WK I'm splitting them up into array of location, country and datetime using
WK the following:


WK /* BEGIN CODE */

WK $itenary = explode('|', $booking-booking_flight_details);

WK $size = count($itenary);

WK for($i=0; $i  $size; $i++) {
WK list($path[$i]['location'],
WK  $path[$i]['country'],
WK  $path[$i]['datetime']) = explode(',', $itenary[$i]);
WK }

WK /* END CODE */



WK *Question*: Is the above the code an effective way to do it? Or is there
WK a better/faster way?

WK Somehow, it feels like there's lots of things going through the above code.

WK Please advise. Thanks.

This ay work:
?
$str = 'Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 
18:00:00|Perth, AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00';
preg_match_all('/(\w+),\s*(\w+),\s*([0-9-]+)\s([0-9:]+)(?=\|)/s',$str,$match);
print_r($match);

-- 
regards,
Tom

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



Re[2]: [PHP] Breaking up data efficiently

2005-06-27 Thread Tom Rogers
Hi,

Tuesday, June 28, 2005, 10:26:12 AM, you wrote:

TR This ay work:
TR ?
TR $str = 'Melbourne, AU, 21-07-2005 14:00:00|Perth, AU,
TR 21-07-2005 18:00:00|Perth, AU, 25-07-2005 14:00:00|Melbourne, AU,
TR 25-07-2005 18:00:00';
TR 
preg_match_all('/(\w+),\s*(\w+),\s*([0-9-]+)\s([0-9:]+)(?=\|)/s',$str,$match);
TR print_r($match);

A different way that will generate what you actually need :)

function build($data){
  global $path;
  $i = count($path);
  $path[$i]['location'] = $data[1];
  $path[$i]['country'] = $data[2];
  $path[$i]['datetime'] = $data[3];
}
$path = array();
$str = 'Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 
18:00:00|Perth, AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00';
preg_replace_callback('/(\w+),\s*(\w+),\s([0-9-]+\s[0-9:]+)(?=\|)/s','build',$str);
print_r($path);




-- 
regards,
Tom

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



Re[2]: [PHP] Best way to use other objects within classes?

2005-06-25 Thread Tom Rogers
Hi,

Here it is for anyone that would like to try it.


?php

if(preg_match('/^win/i',PHP_OS)){
  define('OS_SEP','\\');
  define('OS_JOIN',';');
}else{
  define('OS_SEP','/');
  define('OS_JOIN',':');
}
class classLoader {
  function loadLib($library=''){
if(!empty($library)){
  $file = $GLOBALS['class_dir'].$library.'.lib'; 
  if(!file_exists($file)){
$paths = split(OS_JOIN,ini_get('include_path'));
$found = false;
while(!$found  list($key,$val) = each($paths)){
  $file = $val.OS_SEP.$library.'.lib';
  $found = file_exists($file);
}
  }
  if($found) include($file);
}
$array = get_declared_classes();
foreach($array as $classname){
  if(!isset($GLOBALS['loaded_classes'][$classname])) 
$GLOBALS['loaded_classes'][$classname] = array();
}
if(isset($start_classes)  is_array($start_classes)){
  foreach($start_classes as $class=$info){
$class_name = strtolower($class);
$name = $info['name'];
$hash = mhash(MHASH_TIGER,serialize($info['vars']));
if(isset($GLOBALS['loaded_classes'][$class_name])){
  $varcount = count($info['vars']);
  $vars = '$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\'] 
= new '.$class.'(';
  if($varcount  0){
for ($i = 0; $i  $varcount; $i++) {
  $vars .= ($i  0)? ',':'';
  $varname = 'variable'.$i;
  $$varname = $info['vars'][$i];
  $vars .= \$$varname;
}
  }
  $vars .= ');';
  eval($vars);
  $GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
  if(!empty($info['global'])) $GLOBALS[$info['global']] = 
$GLOBALS['loaded_classes'][$class_name][$name]['class'];
}
  }
  unset($start_classes);
}
  }
  function load($class,$name=''){
$class_name = strtolower($class);
$name = (empty($name))? $class:$name;
$num_args = func_num_args();
$arg_list = func_get_args();
$hash = mhash(MHASH_TIGER,serialize($arg_list));
if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
  if($num_args  2  
$GLOBALS['loaded_classes'][$class_name][$name]['hash'] != $hash){
$vars = 
'$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\']-'.$class.'(';
for ($i = 2; $i  $num_args; $i++) {
  $vars .= ($i  2)? ',':'';
  $varname = 'variable'.$i;
  $$varname = $arg_list[$i];
  $vars .= \$$varname;
}
$vars .= ');';
eval($vars);
$GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
  }
  return $GLOBALS['loaded_classes'][$class_name][$name]['class'];
}elseif(!isset($GLOBALS['loaded_classes'][$class_name])){
  $file = $GLOBALS['class_dir'].$class.'.inc'; 
  if(!file_exists($file)){
$paths = split(OS_JOIN,ini_get('include_path'));
$found = false;
while(!$found  list($key,$val) = each($paths)){
  $file = $val.OS_SEP.$class.'.inc';
  $found = file_exists($file);
}
  }else $found = true;
  if($found){
include($file);
classLoader::loadLib();
  }
}
if(isset($GLOBALS['loaded_classes'][$class_name])){
  $vars = '$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\'] = 
new '.$class.'(';
  if($num_args  2) {
for ($i = 2; $i  $num_args; $i++) {
  $vars .= ($i  2)? ',':'';
  $varname = 'variable'.$i;
  $$varname = $arg_list[$i];
  $vars .= \$$varname;
}
  }
  $vars .= ');';
  eval($vars);
  $GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
  return $GLOBALS['loaded_classes'][$class_name][$name]['class'];
}
return false;
  }
  function remove($class,$name=''){
$r = false;
$class_name = strtolower($class);
$name = (empty($name))? $class:$name;
if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
  unset($GLOBALS['loaded_classes'][$class_name][$name]);
  $r = true;
}
return $r;
  }
  function find($class,$name){
$class_name = strtolower($class);
if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
  return $GLOBALS['loaded_classes'][$class_name][$name]['class'];
}else{
  return false;
}
  }
}
//Usage
// not tested in php5
// all class files end in .inc
// all library files end in .lib
// I don't instanciate the class so uou just
// need to set 2 global variables them call loadLib()
// without any args to get a list of already loaded classes.

$class_dir = '/usr/local/apache/phpinc';
$loaded_classes = array();
classLoader::loadLib();

// The load a class giving it a name and any args that it needs,
// it can pass references without problem
// for example I have a Mysql table class I use just about everywhere
// which needs the db and table to use


$table = classLoader::load('tableClass','members','testdb','test_table');

// now I can get that same 

Re[3]: [PHP] Best way to use other objects within classes?

2005-06-25 Thread Tom Rogers
Hi,

Sunday, June 26, 2005, 12:27:44 PM, you wrote:
TR Hi,

TR Here it is for anyone that would like to try it.


TR ?php

TR if(preg_match('/^win/i',PHP_OS)){
TR   define('OS_SEP','\\');
TR   define('OS_JOIN',';');
TR }else{
TR   define('OS_SEP','/');
TR   define('OS_JOIN',':');
TR }
TR class classLoader {
TR   function loadLib($library=''){
TR if(!empty($library)){
TR   $file = $GLOBALS['class_dir'].$library.'.lib'; 
TR   if(!file_exists($file)){
TR $paths = split(OS_JOIN,ini_get('include_path'));
TR $found = false;
TR while(!$found  list($key,$val) = each($paths)){
TR   $file = $val.OS_SEP.$library.'.lib';
TR   $found = file_exists($file);
TR }
TR   }
TR   if($found) include($file);
TR }
TR $array = get_declared_classes();
TR foreach($array as $classname){
TR   if(!isset($GLOBALS['loaded_classes'][$classname]))
TR $GLOBALS['loaded_classes'][$classname] = array();
TR }
TR if(isset($start_classes)  is_array($start_classes)){
TR   foreach($start_classes as $class=$info){
TR $class_name = strtolower($class);
TR $name = $info['name'];
TR $hash = mhash(MHASH_TIGER,serialize($info['vars']));
TR if(isset($GLOBALS['loaded_classes'][$class_name])){
TR   $varcount = count($info['vars']);
TR   $vars =
TR '$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\'] =
TR new '.$class.'(';
TR   if($varcount  0){
TR for ($i = 0; $i  $varcount; $i++) {
TR   $vars .= ($i  0)? ',':'';
TR   $varname = 'variable'.$i;
TR   $$varname = $info['vars'][$i];
TR   $vars .= \$$varname;
TR }
TR   }
TR   $vars .= ');';
TR   eval($vars);
TR  
TR $GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
TR   if(!empty($info['global']))
TR $GLOBALS[$info['global']] =
TR $GLOBALS['loaded_classes'][$class_name][$name]['class'];
TR }
TR   }
TR   unset($start_classes);
TR }
TR   }
TR   function load($class,$name=''){
TR $class_name = strtolower($class);
TR $name = (empty($name))? $class:$name;
TR $num_args = func_num_args();
TR $arg_list = func_get_args();
TR $hash = mhash(MHASH_TIGER,serialize($arg_list));
TR if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
TR   if($num_args  2 
TR $GLOBALS['loaded_classes'][$class_name][$name]['hash'] != $hash){
TR $vars =
TR '$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\']-'.$class.'(';
TR for ($i = 2; $i  $num_args; $i++) {
TR   $vars .= ($i  2)? ',':'';
TR   $varname = 'variable'.$i;
TR   $$varname = $arg_list[$i];
TR   $vars .= \$$varname;
TR }
TR $vars .= ');';
TR eval($vars);
TR
TR $GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
TR   }
TR   return
TR $GLOBALS['loaded_classes'][$class_name][$name]['class'];
TR }elseif(!isset($GLOBALS['loaded_classes'][$class_name])){
TR   $file = $GLOBALS['class_dir'].$class.'.inc'; 
TR   if(!file_exists($file)){
TR $paths = split(OS_JOIN,ini_get('include_path'));
TR $found = false;
TR while(!$found  list($key,$val) = each($paths)){
TR   $file = $val.OS_SEP.$class.'.inc';
TR   $found = file_exists($file);
TR }
TR   }else $found = true;
TR   if($found){
TR include($file);
TR classLoader::loadLib();
TR   }
TR }
TR if(isset($GLOBALS['loaded_classes'][$class_name])){
TR   $vars =
TR '$GLOBALS[\'loaded_classes\'][$class_name][$name][\'class\'] =
TR new '.$class.'(';
TR   if($num_args  2) {
TR for ($i = 2; $i  $num_args; $i++) {
TR   $vars .= ($i  2)? ',':'';
TR   $varname = 'variable'.$i;
TR   $$varname = $arg_list[$i];
TR   $vars .= \$$varname;
TR }
TR   }
TR   $vars .= ');';
TR   eval($vars);
TR   $GLOBALS['loaded_classes'][$class_name][$name]['hash'] = $hash;
TR   return
TR $GLOBALS['loaded_classes'][$class_name][$name]['class'];
TR }
TR return false;
TR   }
TR   function remove($class,$name=''){
TR $r = false;
TR $class_name = strtolower($class);
TR $name = (empty($name))? $class:$name;
TR if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
TR   unset($GLOBALS['loaded_classes'][$class_name][$name]);
TR   $r = true;
TR }
TR return $r;
TR   }
TR   function find($class,$name){
TR $class_name = strtolower($class);
TR if(isset($GLOBALS['loaded_classes'][$class_name][$name])){
TR   return
TR $GLOBALS['loaded_classes'][$class_name][$name]['class'];
TR }else{
TR   return false;
TR }
TR   }
TR }
TR //Usage
TR // not tested in php5
TR // all class files end in .inc
TR // all library files end in .lib
TR // I don't instanciate the class so uou just
TR // need to set 2 global variables them call loadLib()

Re[2]: [PHP] comparing two texts

2005-06-23 Thread Tom Rogers
Hi,

Thursday, June 23, 2005, 9:42:34 PM, you wrote:
.
.
.

JM whereas I'll happily spend an hour writing up and contemplating someone
JM else's problem - I don't have five minutes for people who are expecting to 
be
JM spoonfed (go learn ASP and get a support contract, thanks ;-).

Perhaps I missed it but could you point out the bit where the original
poster asked to be spoon fed??

-- 
regards,
Tom

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



Re: [PHP] Problems with header()

2005-06-17 Thread Tom Rogers
Hi,

Saturday, June 18, 2005, 7:55:10 AM, you wrote:
MM I have to send a PDF file after a submit on a form. The PDF is well created,
MM and I'm sending it to the client with this:

MM $fpdfName = /tmp/ . session_id() . .pdf;

MM // Vamos a mandar el PDF
MM header('Content-type: application/pdf');
MM // El archivo se va a llamar libreDeuda.pdf
MM header('Content-Disposition: attachment; filename=libreDeuda' . 
MM'.pdf');
MM // El PDF fuente va a ser $ftexName.
MM readfile($fpdfName);

MM The problem is that the PDF file that is sent is corrupted for acroread 
(xpdf
MM reads it like a charme), because, after the end of file (%%EOF) of PDF there
MM is an HTML page add to the file.

MM Is there anyway I can solve this? Is the sintaxis I used for sending a file
MM correct?

Here is a script I use to send pdfs which also handles caching
information. It may just be you are missing the content-length header?

?php
$cache_time = false;
$requested_time = false;

$filename = /tmp/ . session_id() . .pdf;
$len = filesize($filename);

$mtime = filemtime($filename);
$cache_time = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
header('Last-Modified: '.$cache_time);

$rt = (empty($_SERVER['HTTP_IF_MODIFIED_SINCE']))? false : 
$_SERVER['HTTP_IF_MODIFIED_SINCE'];
if($rt) $requested_time = strtotime($rt);

if($requested_time  $cache_time){
if($requested_time == $cache_time){
Header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
exit;
}
}
header(Accept-Ranges: bytes);
header('Cache-Control: no-cache, must-revalidate');
header(Content-type: application/pdf);
header(Content-Length: $len);
readfile($filename);

-- 
regards,
Tom

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



Re: [PHP] possible jscript/php/frames question!!

2005-06-17 Thread Tom Rogers
Hi,

Saturday, June 18, 2005, 8:47:58 AM, you wrote:
b hi...

b i've got a problem where i'm trying to play with imagemaps. i created a test
b image map, but when i select inside the image map, i 'see' the ?x,y from
b the imagemap, appended to the url in the browser address bar... i get
b http://foo.com?3,5 etc...

b is there a way to prevent this from occuring??

b i'd like to be able to select the imagemap, get the coordinate, and not have
b the x,y mouse coordinate show up in the address bar...

b i thought i could use an onClick, and go to a javascript function, but i
b couldn't figure out how to get the mouse coordinates within the jscript
b function.

b if i slammed all this inside a frame, would that prevent the url-x,y
b information from being displayed??

b my sample code is below...

b thanks

b -bruce
b [EMAIL PROTECTED]


b 
b ---
b [EMAIL PROTECTED] site]# cat map.php
b ?
b   /*
b  test for image maps...
b   */
?
b ?
b  $_self = $_SERVER['PHP_SELF'];
?

b html
b body
b script language=javascript type=text/javascript
b !--

b function foo1(q)
b {
b //   str = window.location.search
b //   document.write(fff +q+br);
b // location.href=map.php;
b // return true;
b }
b function foo(e)
b {
b //q = q+1;
b  mX = event.clientX;
b  mY = event.clientY;
b //   str = window.location.search
bdocument.write(fff +mX+ y= +mY+br);
b  location.href=map.php;
b  return true;
b }
// --
b /script

b !--
b centera href=?=$_self;?img
--

b center
b !--
b a href=?=$_self;? onclick =alert(self.location.search); return false
--
b a href=ff.php onclick=
b img src=imagemap.gif ISMAP/a/center
b p
b script language=javascript type=text/javascript
b !--

b str = location.search
b  if(str)
b  {
bdocument.write(fff +str+br);
b//location.href=map.php;
b  }

// --
b /script


b /body
b /html

A PHP solution to your problem is to save the x y co-ordinates in a
session and do a refresh, then get the values fom session.

Do something like

?php
session_start();
if(isset($_SESSION['x'])  isset($_SESSION['y'])){
  //do your thing here
  unset($_SESSION['x'];
  unset($_SESSION['y'];
}else{
  //get x and y from request variables here
  if($x  $y){
$_SESSION['x'] = $x;
$_SESSION['y'] = $y;
header('location: '.$_SERVER['PHP_SELF']);
exit;
  }else{
//show start page
  }
}
-- 
regards,
Tom

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



Re[2]: [PHP] Re: Converting [and] to XML format- help/advise requested

2005-06-14 Thread Tom Rogers
Hi,

Wednesday, June 15, 2005, 4:42:24 AM, you wrote:
DC On 6/14/05, Sebastian Mendel [EMAIL PROTECTED] wrote:
 Dotan Cohen wrote:
  Hi gurus. I'm having fun replacing the text within [ and ] to XML
  format on 4000+ files on a windows XP machine. I installed php (and an
  apache server) on the machine because it is the only language the I am
  remotely familiar with.
 
  I want and text that is with [ and ] to be enclosed with note and
  /note. Going through the archives I found this nice regex (I changed
  it a bit- I hope that I didn't break anything important) that fits
  into str_replace:
 
  str_replace(/[([a-zA-Z]+?)]/, note.$what
  was_inside_the_parethesis./note, $string);
 
 str_replace doesnt support regular expressions
 
 http://www.php.net/str_replace
 
 what you need is preg_replace()
 
 http://www.php.net/preg_replace
 
  But how on sweet mother Earth do I get the $what
  was_inside_the_parethesis variable to stick into the note tags? I
  tried functions that would remove the [ and ], then do
  $new_str=note.$what was_inside_the_parethesis./note;
  and then replace the whole [$what was_inside_the_parethesis] with
  $new_str. I did get that far.
 
 preg_replace( '/\[([^\]]+)\]/', 'note\1/note', $string);
 
  Now the catch! If $what_was_inside_the_parethesis contains the word
  'algebra' then I want nothing returned- in other words [$what
  was_inside_the_parethesis] should be cut out and nothing put in it's
  place. I added an if function in there that checked the presence of
  the word algebra, but it ALWAYS returned blank.
 
 preg_replace( '/\[(algebra|([^\]]+))\]/', 'note\2/note', $string);
 
 just to mention, you need only the second example, the first ist just to
 explain the step toward the final ocde.
 
 Sebastian Mendel
 
 www.sebastianmendel.de
 www.sf.net/projects/phpdatetime | www.sf.net/projects/phptimesheet
 

DC Thank you very much Sebatian! I can't believe that you got that out of
DC one line of code! I often feel that i have a lot to learn, but now I
DC see that I also have a lot to improve...

DC The code works great for [] tags that do not contain the word algebra.
DC If the word algebra is alone between the tags then it returns
DC note/note, which I can easily remove with one more line of code.
DC But if the word algebra appears with another word, then it is
DC converted to a note just as if it did not contain the word.

DC I tried adding asterisks and plus-signs at stratigec places within the
DC regex, but I am not succeeding in getting them to do what I want. I
DC suppose that I would be overstaying my welcome if I asked just where
DC to put them?

DC Dotan
DC http://lyricslist.com/lyrics/artist_albums/402/pink_floyd.php
DC Pink Floyd Lyrics

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


You can use preg_replace_callback to give you a bit more control, so
using Sebastions first expression you could do

function check_string($matches){
  if(preg_match('/algebra/i',$matches[0])) return '';
  return 'note'.$matches[0].'/note';
}

preg_replaec_callback('/\[([^\]]+)\]/','check_string',$string);

-- 
regards,
Tom

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



Re: [PHP] form inside an email

2005-06-14 Thread Tom Rogers
Hi,

Wednesday, June 15, 2005, 4:11:26 AM, you wrote:
R Hi,

R I would like to send a form to customers to get some information.

R The form will be a HTML email and collect a few bits of data...name. age
R etc.

R Can I put this inside an html email so customers do not have to open an
R external webpage to fill in the fields. How can this then be processed?

R If this can be done in php then great. If not any other suggestions are
R welcome.

R Ross 


I think you will find as a security measure most e-mail clients will
not submit a web form.

-- 
regards,
Tom

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



Re: [PHP] Problems escaping apostrophe, please help

2005-06-10 Thread Tom Rogers
Hi,

Friday, June 10, 2005, 12:05:48 AM, you wrote:
LL Hello all,

LL I hope this hasn’t been answered a zillion times already, I've tried
LL everything I know and nothing has worked. The following is the PHP statement
LL and the HTML rendering.  The apostrophe is displayed as is and breaks the
LL browser.  May be I am wrong but I was under the impression that escaping
LL special characters with one of the these, htmlspecialchars, htmlentities,
LL and addslashes would replace them with encoded (hex?) value so they wont
LL break the browser. But it hasn’t worked that way.  I am using
LL charset=iso-8859-1.  This is my PHP:

LL === This is the PHP ===
LL li
LL a href=#
LL onclick='document.form1.how.value=?=htmlentities($row['how'])?;
LL document.form1.factor.value=?=addslashes($row['factor'])?;document.form1
..submit();'?= addslashes($row['factor'])?
LL   /a
LL /li

LL == This is the rendering ===
LL == (note the heart's apostrophe breaks IE and firefox) ===
LL li
LL  a href=# onclick='document.form1.how.value=Pulmonary edema is a
LL condition in which fluid accumulates in the lungs, usually because the
LL heart's left ventricle does not pump adequately. In cases of severe
LL pulmonary edema, the symptoms will worsen and include A drop in blood
LL pressure resulting in a thready pulse.;
LL document.form1.factor.value=Pulmonary
LL edema;document.form1.submit();'Pulmonary edema
LL /a
LL /li

What I do to overcome this is in PHP do:

$content = rawurlencode($content);

and in the html javascript:

unescape($content);

-- 
regards,
Tom

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



Re[2]: [PHP] Problems escaping apostrophe, please help

2005-06-10 Thread Tom Rogers
Hi,

TR What I do to overcome this is in PHP do:

TR $content = rawurlencode($content);

TR and in the html javascript:

TR unescape($content);


I didn't do that very well, your code would look something like:

li
  a href=# 
onclick='document.form1.how.value=unescape(?php 
rawurlencode($row['how'])?);
document.form1.factor.value=unescape(?php 
rawurlencode($row['factor']))?);
document.form1.submit();'?php htmlentities($row['factor'])?
  /a
/li




-- 
regards,
Tom

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



Re: [PHP] Best way to use other objects within classes?

2005-06-03 Thread Tom Rogers
Hi,

Friday, June 3, 2005, 5:16:19 AM, you wrote:
MP Hi All,

MP I'm using the MDB2 object to access my MySQL database. I have a number
MP of classes that perform page-building activities that need db access,
MP and I'm wondering what the best way to expose the MDB2 object to them is?

MP (Note: my development environment is PHP 5.0.3, but the production
MP environment is 4.3.10. This is my first project built with 5.x local and
MP 4.1.x remote, so if anyone with more experience spots any fatal flaws
MP where I'm using 5.x specific methods etc, I'd appreciate knowing about them)

MP Currently, I'm instantiating the MDB2 class in my main page, then 
MP passing it as an object reference to each of the other classes that
MP require it.

MP A simple representation of my main page and a class would be:

MP ?
MP   $db = connectMDB2(); // function that returns instantiated MDB2 object

MP   $comments = new displayComments(); // class that performs displaying
MP of comments
MP   $comments-set_db($db); // passing the MDB2 object to the class
MP   $comments-doSomethingElse();
?

MP The displayComments() class might then look something like:

MP class displayComments{
MP private $db;

MP public function set_db($db){
$this-db = $db;
MP }

MP public function doSomethingElse(){
MP $sql = SELECT something FROM sometable;
$rs = $this-db-query($sql);
MP while ($row = $rs-fetchRow(MDB2_FETCHMODE_OBJECT)){
echo $row-something.br /;
MP }
$rs-free();
MP }   
MP }

MP My main page calls on at least 8 or 9 such classes as it is being built,
MP and I'm concerned that I may not be handling the MDB2 object in respect
MP to them in the most efficient way possible. In a way, I guess this isn't
MP   specifically about the MDB2 package, but more about how to handle
MP objects when they are required within classes.

MP I'd very much appreciate any comments or advice anyone might be able to
MP give.

MP Much warmth,

MP Murray

My solution to this problem was to write a class loader and to call it
whenever I needed a particular class. I give each instance a name and
the loader checks if an instance of that class, that name exists. If
it does it returns a  reference directly, if not it loads the class
and then returns the reference. This way I don't have to worry about
passing references around. It is a little more complex than that as I
also check if the class was passed the same variables, if not it calls
the constructor again. Let me know if you want to try the code (only
tested on php4)

-- 
regards,
Tom

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



Re: [PHP] Dummy question about knowing marked checkboes

2005-05-29 Thread Tom Rogers
Hi,

Sunday, May 29, 2005, 5:50:13 PM, you wrote:
MG Hi,

MG First of all, my apologies to all list members for this dummy question.
MG I've made my home work before posting here, but the truth is that i
MG didn't found an answer for such a simple question.
MG Only examples of more sophisticated related things.

MG I have this piece of code that produces various checkboxes inside a form:
MG ---
MG // select interesses names and values to build the chekboxes
MG $recordSet = $conn-Execute('SELECT interesses FROM interesses ORDER BY
MG interesses ASC');

MG // build the checkboxe's list
MG if (!$recordSet)
MG  print $conn-ErrorMsg();
MG else {
MG  while (!$recordSet-EOF) {
MG   print($recordSet-fields[0] . 'input name=\'interesses\'
MG type=\'checkbox\' id=\'interesses\' value=' . $recordSet-fields[0] .
'\'');
MG echobr /;
$recordSet-MoveNext();
MG }
$recordSet-Close();
$conn-Close();
MG }
MG -


MG Here's the correspondent HTML output:
MG -
MG Alojamentoinput name='interesses' type='checkbox' id='interesses'
value=Alojamento'br /
MG Artesanatoinput name='interesses' type='checkbox' id='interesses'
value=Artesanato'br /
MG Eventosinput name='interesses' type='checkbox' id='interesses'
value=Eventos'

MG (etc.)

MG -

MG My dummy question, for which i apologise once more is: after submitting
MG the form, how can i know which chekboxes were checked ?

MG Thanking you in advance.

MG Warm Regards,
MG Mário Gamito

Make them an array by adding [] at the end of the name. Also you are
missing a quote at the start of the value=  (double quotes makes it
easier to print in my opinion)

It should be like this:

while (!$recordSet-EOF) {
  print($recordSet-fields[0] . 'input name=interesses[]
  type=checkbox id=interesses value=' . $recordSet-fields[0].''
);

Then any checkboxes checked  will be in an array called interesses

$interesses = (isset($_POST['interesses']))? $_POST['interesses'] :
array();
if(count($interesses)  0){
  //checkboxes have been ticked
}else{
  //none ticked
}

-- 
regards,
Tom

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



Re: [PHP] problem with multiple fields

2005-05-19 Thread Tom Rogers
Hi,

Thursday, May 19, 2005, 6:07:53 PM, you wrote:
V sorry for my poor english, i'll try to be understood
V  so i want to represent an informatic parc but have a problem
V  for example a pc can have 2 or more memory slot filled how to stock
V the different id in a list in my database and how extract it
V for the moment i just have an external key referencing one memory.
V  Have you an idea to help me please?

It is probably best to put the individual items in a separate table
and link their keys, as an example with 3 tables

table items
itemid
name

table item_list
pcid
itemid

table pc
pcid
location


then these could contain
items
itemid  name
1   memory module
2   floppy drive

pc
pcid location
1reception

item_list
pcid itemid
11
11
12

so reception pc contains 2 memory modules and 1 floppy

Hope that helps

-- 
regards,
Tom

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



Re[2]: [PHP] problem with multiple fields

2005-05-19 Thread Tom Rogers
Hi,

Thursday, May 19, 2005, 8:12:45 PM, you wrote:
V but in fact for example:
V pc reception have two memory module but i do the gestion of the individual
V pieces too
V  for example in a table i have
V  id name ref hs? 
V 1 sdram256 22055 True 
V 2 sdrram512 22056 True
V  so i need to keep the informations of the reference too 


V 2005/5/19, Tom Rogers [EMAIL PROTECTED]: 


In that case use the reference as the key to the item

id name hs
22055 sdram256 true
22056 sdram512 true

then the item list table would be

pc id
1  22055
1  22056

--
regards,
Tom

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



Re: [PHP] Unknown column 'peterspeters' in 'where clause'

2005-05-18 Thread Tom Rogers
Hi,

Wednesday, May 18, 2005, 4:27:34 PM, you wrote:
MS Hi All,

MS the below code generates this error,

MS Unknown column 'peterspeters' in 'where clause'

MS mysql_select_db(status, $db);
MS $username = $_POST[username];
MS $password = $_POST[password];
MS $result = mysql_query(SELECT customer_id FROM Customers WHERE 
MS customer_username = $username AND customer_password = $password) or die
MS (mysql_error());
MS $myrow = mysql_fetch_row($result);
MS $customer_id = $myrow[0];
MS $_SESSION['customer_id'] = $customer_id;
?
MS /head
MS body
MS ?php
MS echo 'SQL Query: '.$result.'br';
MS echo CustomerID = $customer_id;
?

MS Cheers.

MS Mark Sargent.


You need to put the variables in single quotes, otherwise mysql treats
it as a column name. You should also escape the strings to be safe if
magic_quotes are turned off in php.ini

A bit like this:

mysql_select_db(status, $db);
$username = mysql_escape_string($_POST[username]);
$password = mysql_escape_string($_POST[password]);
$result = mysql_query(
SELECT customer_id 
FROM Customers 
WHERE customer_username = '$username' 
AND customer_password = '$password') or die (mysql_error());
$myrow = mysql_fetch_row($result);
$customer_id = $myrow[0];
$_SESSION['customer_id'] = $customer_id;

-- 
regards,
Tom

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



Re: [PHP] Seeking decent domain registrar

2005-05-12 Thread Tom Rogers
Hi,

Thursday, May 12, 2005, 8:40:26 PM, you wrote:
MB Somewhat OT - I've had almost entirely poor experiences with domain
MB registrars, so I'm looking for recommendations. I need:

MB .com, .net, .org domains (easy enough!)
MB .co.uk support
MB Multilingual domain support e.g. café.com
MB Online control of DNS server assignment
MB Specification of external DNS at registration time (so you don't have
MB to change it unnecessarily afterwards)
MB Multiple admin accounts (I run domains for other people in their  
MB names and I want to keep them separate)
MB Don't need any forwarding, web hosting, email or anything beyond  
MB registration
MB Low-cost would help of course!

MB I've been googling for registrars, but as yet I've not found anyone
MB that offers all this. Can anyone recommend a registrar that has a
MB clue and a decent web interface?

MB Thanks,

MB Marcus

I have been using bulkregister.com for a few years and no complaints,
you will have to check yourself if they meet your particular needs :)

-- 
regards,
Tom

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



Re: [PHP] yet another php templating question

2005-05-10 Thread Tom Rogers
Hi Ryan,

Tuesday, May 10, 2005, 11:48:39 PM, you wrote:
RA Hey,
RA Since we are caught up in the templating season, I think its time for this
RA one;

RA We have just finished designing the software blueprint for a new PHP
RA product,
RA we usually used the include() method :-) to template U/I's for the
RA clients but
RA this one seems a bit bigger...
RA I really like Smarty we and use it for our templating needs, but it just
RA seems a bit
RA too much to bundle Smarty  with our software to the end user/client (esp
RA since
RA Smarty would be many times bigger than our scripts)

RA I have searched google and the classes site to find templating solutions,
RA fast template looks good but from the forums i have seen its not extremly
RA dependableany suggestions?

RA Links to would be appreciated, I have no plans of writing a new templating
RA system
RA just for this.

RA Thanks,
RA Ryan

You are quite welcome to have a look at my template processor, there
is the start of some documentation at http://kwiktemplates.com/

The actual code is very small and it runs pretty quick, so no need to
cache anything for most sites. I have been using it now for a couple
of years and it hasn't let me down :)

-- 
regards,
Tom

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



Re: [PHP] number format?

2005-05-10 Thread Tom Rogers
Hi,

Wednesday, May 11, 2005, 1:34:10 AM, you wrote:
DW I have a number like -56.98
 
DW I need to convert it to -5698. I tried 

DW ---
DW Outgoing mail is certified Virus Free.
DW Checked by AVG anti-virus system (http://www.grisoft.com).
DW Version: 6.0.859 / Virus Database: 585 - Release Date: 2/14/2005
 
Here is a little function I use to take care of all combination of
inputs:

function dollars2cents($value){
  $value = sprintf(%0.2f,trim($value));
  list($a,$b) = explode('.',$value);
  if(floatval($value)0) $b = $b*-1;
  return intval($a)*100 + intval($b);
}

-- 
regards,
Tom

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



Re: [PHP] Count totals (might be 0T)

2005-04-21 Thread Tom Rogers
Hi,

Friday, April 22, 2005, 8:03:06 AM, you wrote:
RA Hi again,
RA Am faced with a new problem (either that or working straight 10 hours is
RA catching up!)

RA Heres my table (easy to figure out so i wont waste your time explaining the
RA fields):
RA cno,
RA date_added,
RA pic_name,
RA pic_size_kb,
RA pic_desc_text,
RA pic_category

RA the way i am displaying the data is like this (thanks to Phillip and Andy
RA from this list)

RA  __
RA  category here   2pics, 90kb  |
RA  -
RA  | pic-here | pic_desc_text |
RA  | pic-here | pic_desc_text |
RA  __
RA  category here  2pics, 160kb  |
RA  -
RA  | pic-here | pic_desc_text |
RA  | pic-here | pic_desc_text |
RA  -

RA When I sql the DB I call it like this: select picture_name,more
 fields from table where cno=x order by category.

RA Any ideas as to how i get how many pics per category and size per category?
RA I'm not sure if its a PHP thing or a MySql thing...

RA Last problem for the day...then i hit the sack!
RA Thanks in advance,
RA Ryan


Something like

SELECT COUNT(pic_name) as pic_count, SUM(pic_size_kb) as pic_total
FROM pic_table GROUP BY pic_category

-- 
regards,
Tom

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



Re[2]: [PHP] Images - Converting TIFF Format?

2005-04-20 Thread Tom Rogers
Hi,

Thursday, April 21, 2005, 3:15:31 AM, you wrote:
TDJ I searched through my server's system (I'm not running it, it's my ISP) and
TDJ finally found that TIFF isn't compiled into GD. I can get them to do it, 
but
TDJ I need to know what functions to use! Are they under a different file type?
TDJ I'm pretty sure I searched through thoroughly for the function. Did I miss
TDJ something?
TDJ  Thanks for all your help!

As far as I know gd does not support tiffs directly.

-- 
regards,
Tom

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



Re: [PHP] Why is the default value for arg_separator.output ''?

2005-04-19 Thread Tom Rogers
Hi,

Wednesday, April 20, 2005, 5:56:44 AM, you wrote:
DD For documents to conform to the XHTML recommendation, ampersand characters
DD much be encoded as amp;. The documentation for PHP recognises this. The
DD same applies to HTML (with some exceptions that the session code will never
DD encounter), although the PHP documentation makes no mention of this.

DD Given this, why is the default value of arg_separator.output '' and not
DD 'amp;'?

DD -- 
DD David Dorward   http://blog.dorward.me.uk/   http://dorward.me.uk/
DD  Home is where the ~/.bashrc is


You can set this with arg_separator.output  in php.ini

-- 
regards,
Tom

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



Re[2]: [PHP] Why is the default value for arg_separator.output ''?

2005-04-19 Thread Tom Rogers
Hi,

Wednesday, April 20, 2005, 9:05:39 AM, you wrote:
RBAK On Wed, 20 Apr 2005, Tom Rogers wrote:
 You can set this with arg_separator.output  in php.ini

RBAK That doesn't really answer why the choice was made to default to what
RBAK not only shouldn't be the default, but should probably be illegal
RBAK altogether.


Well it would appear that '' is the correct one to use and it is PHP
that gets it wrong when using it in a url reference such as a
href= where it should by convert it to be amp;.
But it doesn't so I guess we have to force it in the ini file.

-- 
regards,
Tom

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



Re: [PHP] Images - Converting TIFF Format?

2005-04-19 Thread Tom Rogers
Hi,

Wednesday, April 20, 2005, 12:39:54 AM, you wrote:
TDJ Is there a quick way to convert a TIFF format picture to a GIF quickly? I
TDJ can only find support for GIFs in PHP, but maybe I'm missing something. I
TDJ have a client running a photography business, and I have designed an image
TDJ watermark and resizing engine, and a server to check the request, serve the
TDJ file, and then delete it. I mainly made this to help him run the site
TDJ himself, since he isn't very good with Photoshop, and can't watermark the
TDJ images (I shouldn't say that...he probably could, but not very fastbut
TDJ anyway...).
TDJ  This is all working fine and dandy, but the system will only accept GIF
TDJ format. His images are all raw scans in TIFF format. This means that he has
TDJ to open the image in Photoshop, resize it, and convert it to a GIF. I think
TDJ he can do this himself, but I'd like to make it even simpler, which is why
TDJ I'm writing.
TDJ  I need a quick way, preferably in PHP, but it doesn't have to be, to
TDJ convert large batches of TIFF format images to GIF. Does anyone know of a
TDJ way to do this?
TDJ  Thanks for reading, and for your responses in advance...


I use netpbm for conversion to png from tiffs and windows bitmaps like this:

//$tempname from fileupload tmpname
//$file from fileupload name
$jobpath = '/wherever/you/want/files/stored';
if($im = getimagesize($tempname)){
  if($im[0]  0){
//cleanup filename  
$file = ereg_replace(',,$file);
$file = ereg_replace(%20,_,$file);
$file = ereg_replace( ,_,$file);
$ext = @substr($file, (@strrpos($file, .) ? @strrpos($file, .) + 1 : 
@strlen($file)), @strlen($file));
$fname = basename($file,$ext);
switch(intval($im[2])){
  case 7:
  case 8:
//force a tif extension for netpbm
$tfilename = $jobpath.'/'.$fname.'tif';
move_uploaded_file($tempname, $tfilename);
$file = $fname.'png';
$filename = $jobpath.'/'.$file;
shell_exec (/path/to/netpbm/bin/tifftopnm -quiet $tfilename | 
/path/to/netpbm/bin/pnmtopng  $filename);
  break;
  case 6:
//force a bmp extension for netpbm
$tfilename = $jobpath.'/'.$fname.'bmp';
move_uploaded_file($tempname, $tfilename);
$file = $fname.'png';
$filename = $jobpath.'/'.$file;
shell_exec (/path/to/netpbm/bin/bmptoppm -quiet $tfilename | 
/path/to/netpbm/bin/pnmtopng  $filename);
  break;
  default:
$filename = $jobpath.'/'.$file;
move_uploaded_file($tempname, $filename);
  break;
}
  }
}

-- 
regards,
Tom

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



Re: [PHP] RegEx help

2005-04-14 Thread Tom Rogers
Hi,

Thursday, April 14, 2005, 11:47:13 PM, you wrote:
BD I wanted to create a regex that force a PHP form text field to meet the
BD following requirements:

BD a. Must contain an 1 uppercase letter. [A-Z]

BD b. Must contain 1 digit. [0-9]

BD c. Must be a minimum of 7 characters in length. {7}

 

BD I'm not sure of how to build the correct syntax for using all 3
BD requirements together.

BD Any help?

 

BD Thanks,

BD Dave

 

 



BD HTC Disclaimer:  The information contained in this message
BD may be privileged and confidential and protected from disclosure.
BD If the reader of this message is not the intended recipient, or an
BD employee or agent responsible for delivering this message to the
BD intended recipient, you are hereby notified that any
BD dissemination, distribution or copying of this communication is
BD strictly prohibited.  If you have received this communication in
BD error, please notify us immediately by replying to the message and
BD deleting it from your computer.  Thank you.

easier done seperately I think
if(
  strlen($text)  6 
  preg_match('/\d+/',$text) 
  preg_match('/[A-Z]+/',$text)
) { echo 'OK br';

-- 
regards,
Tom

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



Re[2]: [PHP] mcrypt_generic_init(): Iv size incorrect

2005-04-12 Thread Tom Rogers
Hi,

Wednesday, April 13, 2005, 5:14:25 AM, you wrote:
MH Do you do this on the encryption or the decryption section or both?

I do it on both, here is a class I use that may help:


class encryptClass{
  var $secret;
  function encryptClass(){
$this-secret = 'put secret here';
  }
  Function encode($id){
$eid = $iv = 0;
$len = strlen($id);
$id = $len.'-'.$id;
$td = mcrypt_module_open(MCRYPT_TripleDES, , MCRYPT_MODE_ECB, );
$key = substr($this-secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack(a.mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$eid = base64_encode(mcrypt_generic ($td, $id));
mcrypt_generic_deinit($td);
return $eid;
  }
  Function decode($eid){
$id = $iv = 0;
$td = mcrypt_module_open (MCRYPT_TripleDES, , MCRYPT_MODE_ECB, );
$key = substr($this-secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack(a.mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$id = mdecrypt_generic ($td, base64_decode($eid));
$len = strtok($id,'-');
$id = substr($id,(strlen($len)+1),$len);
mcrypt_generic_deinit($td);
return $id;
  }
}


( I encode the length of the original string so I can trim the extra
rubbish that deinit leaves behind as packing)

-- 
regards,
Tom

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



Re[2]: [PHP] mcrypt_generic_init(): Iv size incorrect

2005-04-12 Thread Tom Rogers
Hi,

Wednesday, April 13, 2005, 6:04:05 AM, you wrote:
MH I get the following error when I try your suggestion:

MH Unknown error type: [8] Undefined variable:  iv

MH Code:

$key = md5($this-_cypherkey);
MH $key = substr($key, 0, mcrypt_enc_get_key_size($this-td));
MH $iv_size = mcrypt_enc_get_iv_size($this-td);
MH #$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
MH $iv = pack(a.$iv_size,$iv);

Yes I forgot to put $iv = 0; before that line.
-- 
regards,
Tom

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



Re: [PHP] Re: Limiting Cpu usage

2005-04-12 Thread Tom Rogers
Hi,

Wednesday, April 13, 2005, 8:20:46 AM, you wrote:
z Yeahh! i have made it
z i can slow down a php script , as i edited the zend engine source to usleep
z every 1000 low-level instructions
z now, is there a way to determine to check my cpu load and adjust it by that
z so if nothing (or very low cpu usage) is running on the system he'll get
z extra power? 


On Linux you can cat /proc/loadavg to get the current load (3rd number
in)

-- 
regards,
Tom

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



Re: [PHP] Creating INSERT INTO statement from dbf file

2005-04-11 Thread Tom Rogers
Hi,

Tuesday, April 5, 2005, 6:33:31 AM, you wrote:

RSJ Ave,

RSJ I¹ve written a code that is able to extract the Column names and Records
RSJ from a simple dbf (foxpro) file and create an INSERT INTO sql statement
RSJ which can be used to insert all those records with their corresponding 
field
RSJ names in an existing mySQL table. (A CREATE TABLE code I wrote is able to
RSJ create the table from the dbf file information).

RSJ Following is the code I wrote for creating the INSERT INTO sql:

RSJ ?php
RSJ $db_path = $DATABASEFILE;
RSJ $dbh = dbase_open($db_path, 0) or die(Error! Could not open
RSJ dbase database file '$db_path'.);
RSJ if ($dbh) {

RSJ #Get the Information
RSJ $column_info = dbase_get_header_info($dbh);
RSJ $record_numbers = dbase_numrecords($dbh);

RSJ #Run the loop for all the records in the Table
RSJ for ($i = 1; $i = $record_numbers; $i++) {
RSJ $row = dbase_get_record_with_names($dbh, $i);

RSJ echo INSERT INTO
RSJ .substr($DATABASEFILE_name,0,-4). (;

RSJ #Run the loop for all the fields in the Table
RSJ foreach ($column_info as $v1) {echo $v1[name],;}

RSJ echo ) VALUES (;

RSJ #Run the loop for all the values corresponding to fields in the
RSJ Table
RSJ foreach ($column_info as $v1) {echo
RSJ '.trim($row[$v1[name]]).',;}
   
RSJ echo '); br;
   
RSJ }
RSJ }
RSJ dbase_close($dbh);
? 

RSJ It works fine, except for one problem. It¹s able to create the INSERT INTO
RSJ sql statement, with all the fields and corresponding values, but as I¹m
RSJ running a loop for both the fields names, and the values corresponding to
RSJ fields names, it leaves a comma after the records are over.

RSJ So instead of having this : INSERT INTO tblname (c1,c2,c3) VALUES
RSJ (Œv1¹,¹v2¹,¹v3¹);
RSJ I achieve this : INSERT INTO tblname (c1,c2,c3,) VALUES (Œv1¹,¹v2¹,¹v3¹,¹);

RSJ Notice an additional Comma after column names, and an additional ,¹ after
RSJ the values. I¹m not quite sure what to do to get rid of those. I¹ve tried
RSJ some different combinations using different kind of logic with the echo
RSJ statements, but it¹s not working out. Would love some help.

RSJ Thanks,

RSJ Rahul S. Johari
RSJ Coordinator, Internet  Administration
RSJ Informed Marketing Services Inc.
RSJ 251 River Street
RSJ Troy, NY 12180

RSJ Tel: (518) 266-0909 x154
RSJ Fax: (518) 266-0909
RSJ Email: [EMAIL PROTECTED]
RSJ http://www.informed-sources.com

I would do it this way:

?php
$db_path = $DATABASEFILE;
$dbh = dbase_open($db_path, 0)
  or die(Error! Could not open dbase database file '$db_path'.);
if ($dbh) {
  #Get the Information
  $column_info = dbase_get_header_info($dbh);
  $record_numbers = dbase_numrecords($dbh);
  $table = substr($DATABASEFILE_name,0,-4);
  $fields = ''; //we will fill this on the first pass
  $first = true; //flag to generate field names
  #Run the loop for all the records in the Table
  for ($i = 1; $i = $record_numbers; $i++) {
$values = ''; //start off null values
$row = dbase_get_record_with_names($dbh, $i);
#Run the loop for all the fields in the Table
foreach ($column_info as $v1) {
  $field = $v1['name'];
  if($first) $fields .= (empty($fields))? $field : ,$field;
  $val = mysql_escape_string(trim($row[$field]));
  $values .= (empty($values))? '$val' : ,'$val';
}
$first = false; // we have a field list now
echo INSERT INTO $table ($fields) VALUES ($values) br;
  }
  dbase_close($dbh);
}
?

-- 
regards,
Tom

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



Re: [PHP] mcrypt_generic_init(): Iv size incorrect

2005-04-08 Thread Tom Rogers
Hi,

Saturday, April 9, 2005, 3:35:21 AM, you wrote:
MH I have an odd php issue with mcrypt.
MH I'm getting a lot of this type of error, but only sometimes:

MH mcrypt_generic_init(): Iv size incorrect; supplied length: 0, needed: 32

MH (note, the supplied length: 0 is not always the same.  sometimes it is
MH 1, 16, etc).

MH It doesn't seem to affect the decoding of the file, but it is throwing a
MH notice in to my error log. I've tried doing this:

MH @mcrypt_generic_init($this-td, $key, $iv)

MH but that doesn't stop it from throwing an error.

MH The only thing I can think is that I have
MH mcrypt_module_close($this-td) 
MH commented out because my code was dying with it...

MH System:
MH Linux w/ Apache 1.3.31
MH PHP Version 4.3.4
MH libmcrypt version 2.5.7


MH Suggestions?


I do this to set a zero iv

$td = mcrypt_module_open(MCRYPT_TripleDES, , MCRYPT_MODE_ECB, );
$key = substr($secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack(a.mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);

-- 
regards,
Tom

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



Re: [PHP] Multiple Select Field

2005-04-03 Thread Tom Rogers
Hi,

Monday, April 4, 2005, 2:58:36 AM, you wrote:
RK Please excuse the length and complexity of this post. I am facing a
RK complicated problem and need to find a solution. Also, I have posted this
RK on both PHP and MySQL boards so please overlook the possibly slightly
RK off-topic subject.

RK I have got one table that contains personal information about users.
RK Another table consists of a list of many interests. This table is composed
RK of simply 2 fields  an ID and the interest. (see below)

RK I can build an HTML form which includes a multiple select list out of which
RK the user can select their interests. I have the list configured so that it
RK displays the interest while the value stored is the ID. PHP stores 
this
RK entry as an Array which I can easily turn into a comma delimited list
RK before storing in the database.

RK Heres my problem. If I store a comma-delimited list in a text field in the
RK Users table, how do I query to determine anyone that has selected specific
RK interests? If I use a full-text search and someone selects 1 for their
RK search criteria, the query will return anyone who selects 1, 10, 11, 12,
RK 13, 14, etc. as their interest.

RK This problem has surely occurred for others. It would affect how you store
RK newsletters for which one might subscribe, keywords in a clipart system,
RK interests the user has, anything from which you want your users to select
RK multiple entries from a long list of choices.

RK Table = Interests
RK Fields = ID, int, auto-increment
RK Interests, text

RK Table = Users
RK Fields = ID, int, auto-increment
RK Name, text
RK Address, text
RK Interests, text

RK Thanx in advance for any help you might provide. If anyone knows of
RK anything written on configuring this type of system, please include a link.

RK Robb
RK Digital IGUANA


Create a third table which links the other two, it will make life
easier for searches and stats and be a lot quicker.

table = user_interests
fields userid int, interestsid int

primary index would be on both fields

-- 
regards,
Tom

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



Re: [PHP] Session in two servers

2005-04-01 Thread Tom Rogers
Hi,

Friday, April 1, 2005, 10:59:13 PM, you wrote:
SS Hi,
SS  I am using sessions in my web application which is installed in two
SS pawns. So the request is randomly picked by one of the two servers. I
SS am using files in php session but not database. My problem is, if the
SS first request go to one server and the session is created there, then
SS for the following request going to other server will not have session.
SS How can we manage the session simultaniously in two servers? Please
SS help me in this regard.

SS S.Srinadh


msession is designed for just your situation.

http://www.mohawksoft.com/

-- 
regards,
Tom

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



Re: [PHP] text editor

2005-03-28 Thread Tom Rogers
Hi,

Tuesday, March 29, 2005, 9:17:42 AM, you wrote:
TT Hi all,

TT ok, I have created my own php text editor that allows a user to edit
TT files from local(server) disk.

TT I use a basic html textarea to show the contents of the file, and let
TT them edit it, and then save it to disk.

TT I've just realized that when editing an html file, that everything is
TT ok, unless the file has a textarea tag in it. Then the editing textarea
TT tag gets closed, and you end up not getting all of the data to save.

TT Any way to work around this and still use simple forms ?

TT Thanks,

TT Tim.

What I have done in the past is convert textarea to text_area and
then do the reverse when the form is submitted

-- 
regards,
Tom

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



Re: [PHP] SQL statement - please help

2005-03-24 Thread Tom Rogers
Hi,

Thursday, March 24, 2005, 6:50:38 PM, you wrote:
J Dear all

J Please, I realy need your help.  I am trying to extract only those records
J that were entered during the past hour from my MySQL database.  The
J following SQL statement extracts all the records. As soon as I change the
J INTERVAL  to 1 HOUR I see all the records in my database. When I change
J CURDATE() to CURTIME() no records are extracted from the database. The
J cgtimeposted field is a time data type.

J Please advise me as to how I can formulate my SQL statement so that only
J those records entered within the past hour displays on my page.

J Here is my current SQL statement - this statement displays all the records:

J $sql = Select tblchatglobal.cgid, tblchatglobal.cgdateposted, 
J tblchatglobal.cgtimeposted, tblchatglobal.uid, tblchatglobal.cgmsg,
J tblusers.uid, tblusers.uusername from tblchatglobal, tblusers where
J (tblchatglobal.uid = tblusers.uid) and
J (DATE_SUB(CURDATE(),INTERVAL 1 HOUR) 
J =  tblchatglobal.cgtimeposted) order by
J tblchatglobal.cgtimeposted desc;

J Jacques 

You cannot do this with just a time field as what happens at midnight
and now() becomes 00:00:00, you will need to work with a full date_time
field.

The other problem is CURDATE has no time component, it is just a date
so subtracting 1 hour will always return 23:00:00.

So change the time field to a timestamp and try

... AND  tblchatglobal.cgtimeposted  (DATE_SUB(NOW(),INTERVAL 1 HOUR))

-- 
regards,
Tom

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



Re: [PHP] Listing directory, return none if only one file

2005-03-24 Thread Tom Rogers
Hi,

Thursday, March 24, 2005, 8:15:11 PM, you wrote:
AM I have a script that lists the files in a directory, but when i have
AM only ONE file , it won't display it ( here is the code : 
AM http://www.pastebin.com/262050 )


After you sort the $filename array its index changes from 1 to 0 so
your $i is 1 ahead of the array.

-- 
regards,
Tom

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



Re: [PHP] image problem

2005-03-24 Thread Tom Rogers
Hi,

Friday, March 25, 2005, 3:27:41 AM, you wrote:
WS Hello,

WS I really can't figure this out. Can someone help please. I've wasted hours
WS already with this one.

WS I'm trying to print image to a web page using fpassthru. Here's the code:

WS $name = path/to/the/image/folder/img1.jpeg;
WS  $fp = fopen($name, 'rb');

WS  // send the right headers
WS  header(Content-Type: image/jpeg); //also tested with type pjpeg
WS  header(Content-Length:  . filesize($name));

WS  // dump the picture
WS  fpassthru($fp);

WS Help Appeciated. Thanks.
WS -Will

Make sure you don't have any whitespace after the trailing ? if there
is one, better still get rid of it.
Also I use readfile($name); ... can't remember why


Here is a bit of code I use for passing PDF files which also handles
caching control you can adapt easily for images.


?php
$cache_time = false;
$requested_time = false;
$filename = $_REQUEST{'filename'];
if(file_exists($filename)){
  $len = filesize[$filename);
  $mtime = filemtime($filename);
  $cache_time = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
  header('Last-Modified: '.$cache_time);
  $rt = false;
  if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
$rt = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
  }
  if($rt) $requested_time = strtotime($rt);
  if($requested_time  $cache_time){
if($requested_time == $cache_time){
  Header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
  exit;
}
  }
  header(Accept-Ranges: bytes);
  header('Cache-Control: no-cache, must-revalidate');
  header(Content-type: application/pdf);
  header(Content-Length: $len);
  readfile($filename);
}

-- 
regards,
Tom

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



Re: [PHP] OR statement

2005-03-24 Thread Tom Rogers
Hi,

Friday, March 25, 2005, 11:27:30 AM, you wrote:
MD Hello,

MD I would like to first thank everyone for their help with the last few
MD questions I have had. I really appreciate it.

MD Here is my question:

MD  if ($audio == Cool){

MD Do this

MD }else{

MD Do that

MD }

MD This work fine, however, I would like to add to the criteria above. I would
MD like to say:

MD  if ($audio == Cool or junk or funky){

MD ...

MD I have tried to look for something in the manual, and am still looking, but
MD a little help on this would be appreciated.

MD Thank you again,

MD --
MD Steve Marquez

The most easily expandable way is with a switch statement

switch($audio){
  case 'Cool':
  case 'junk':
  case 'funky':
Do this
  break;
  default:
Do that
  break;
}

-- 
regards,
Tom

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



Re: [PHP] GIF instead of JPG..

2005-03-23 Thread Tom Rogers
Hi,

Wednesday, March 23, 2005, 11:30:53 PM, you wrote:
RA Hi,
RA I found this beautiful piece of code on the php site which make a
RA proportional thumbnail, problem is its only working with JPEG files...and
RA not with GIFs, can someone please help me convert it to GIF too?

RA I tried but got a bit confused as there are no functions that are equal to
RA imagecreatetruecolor that is in the below script.
RA The below script works perfectly for jpgs:

Here is a function I use for scaling that you can use as an example,it
also handles transparent gifs.

You can set $x or $y leaving the other at 0 to maintain aspect ratio
or set both to force a fixed box.


function Scale($input,$out,$x,$y){
  $info = getimagesize($input);
  $width = $info[0];
  $height = $info[1];
  $colors = array();
  if($width  0  $height  0){
if($x  0){
  $w2 = $x;
  if($width  $w2){
$scale = $width/$w2;
$h2 = intval($height/$scale);
  }else{
$scale = $w2/$width;
$h2 = intval($height * $scale);
  }
}elseif($y  0){
  $h2 = $y;
  if($height  $h2){
$scale = $height/$h2;
$w2 = intval($width/$scale);
  }else{
$scale = $sw2/$height;
$w2 = intval($width * $scale);
  }
}
switch($info[2]){
  case 1:
$im = ImageCreateFromGif($input);
$t = ImageColorTransparent($im);
$itype = gif;
if($t != -1){
 $colors = imagecolorsforindex($im, $t);
}
$im2 = ImageCreate($w2,$h2);
  break;
  case 2:
$itype = jpeg;
$im = ImageCreateFromJpeg($input);
$im2 = ImageCreateTrueColor($w2,$h2);
  break;
  case 3:
$itype = png;
$im = ImageCreateFromPng($input);
$t = ImageColorTransparent($im);
if($t != -1){
  $colors = imagecolorsforindex($im, $t);
}
$im2 = ImageCreateTrueColor($w2,$h2);
  break;
  default:
return;
  break;
}
if(count($colors)  0){
  $transp = ImageColorAllocate($im2, $colors[red],$colors[green], 
$colors[blue]);
}
imagecopyresampled($im2, $im, 0, 0, 0, 0, $w2, $h2, $width, $height);
if(count($colors)  0){
  ImageColorTransparent($im2,$transp);
}
if(eregi(\.gif$,$out)){
  ImageGif($im2,$out);
}elseif(eregi(\.jpe?g,$out)){
  ImageJpeg($im2,$out,90);
}elseif(eregi(\.png$,$out)){
  ImagePng($im2,$out,20);
}
  }
}




-- 
regards,
Tom

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



Re[2]: [PHP] incrementing a number from a text file

2005-03-11 Thread Tom Rogers
Hi,

Friday, March 11, 2005, 6:30:52 PM, you wrote:

KM -Original Message-
KM From: Richard Lynch [mailto:[EMAIL PROTECTED] 
KM Sent: Thursday, March 10, 2005 10:14 PM
KM To: Ross Hulford
KM Cc: php-general@lists.php.net
KM Subject: Re: [PHP] incrementing a number from a text file

 I want to read a number from an external (txt) file and increment it.then
 save the number back on the text file.
 I know this is possible but want a simple amd economical way to do this.

 That's what you *THINK* you want to do :-)

 But what happens when *TWO* users hit that same script at exactly the same
 time.

KM snip

 This is why so many early hit counter scripts back in the day were
 always getting messed up and reset to 0.

KM Don´t increase if counter is not read?

 What you really want, almost for sure, is an SQL database with sequences

KM I try NOT to use databases if not nessecary

 You *can* use http://php.net/flock, but even that is a Bad Idea, because
 flock under Un*x is self-imposed -- If some *other* program/script/user
 decides not change that file and doesn't use flock, well, they're not
 STOPPED from doing that.

KM Poor programming?

 flock is therefore all too subject to human fallibility when you re-work,
 re-write, or add more code to your system.

KM Every code is... if You don´t use Your head, the outcome will be...?

KM If U no nothing about SQL, I use a database to a counter, I
KM get a piece of code from a friend alter table counter
KM auto_increment = 1; and I´m curious to see, what it does? 

KM Or better: I put my query in a link like a
KM href=db.php?q=select+*+from+customersshow customers/a and
KM I´ve got NO clue about the settings in the mysql db, so this gets
KM funny
KM a href=db.php?q=delete+from+customersshow customers/a
KM a href=db.php?q=drop+table+customersshow customers/a

KM *whistle*

KM This _was_ an issue in a company I worked for, along with queries like:

KM Select blablabla FROM t1,t2,t3
KM WHERE customers LIKE '%$s%'
KM OR name LIKE '%$s%'
KM OR domain LIKE '%$s%'
KM OR email LIKE '%$s%'
KM OR log LIKE '%$s%'
KM AND t1.id = t2.t1_id
KM AND t1.id = t3.t1_id

KM Horror!

KM Kind regards
KM Kim Madsen

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


Sorry to get in late here, try these scripts (probably unix only):

//count.php

?php
//wait if another process has results.new
$x = 5; //5 seconds
while($x  0  file_exists('results.new')){
  sleep(1);
  clearstatcache();
  $x--;
}
if($x == 0) echo Hung process detected br;
if(file_exists('results')){
  $count = intval(trim(file_get_contents('results')));
  $count ++;
}else{
  $count = 1;
}
$fp = fopen(results.new, w);
if($fp) {
  fwrite($fp,$count.\n);
  exec(ln -f results results.old); //incase it is being read
  exec(mv results.new results);
  echo done count=$count\n;
  fclose($fp);
}


//testing script count.html

html
head
titleCounter Test/title
/head
frameset cols=150,150,150,* rows=*
  frame src=count.php name=c1 frameborder=1
  frame src=count.php name=c2 frameborder=1
  frame src=count.php name=c3 frameborder=1
  frame src=count.php name=c4 frameborder=1
  noframes
body bgcolor=#FF
  pneed frames/p
/body
  /noframes
/frameset
/html


In theory no 2 frames should have the same number
-- 
regards,
Tom

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



Re[2]: [PHP] SOLVED: Re: [PHP] Document root, preferred way to find it???

2005-03-07 Thread Tom Rogers
Hi,

Tuesday, March 8, 2005, 12:03:54 AM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 11:20:04 PM, you wrote:
T I do this for security as I have things in include that I don't
T want to be avaiable directly to the browser Also you don't need a
T path for include files you can just do:

LG Don't necessarily disagree with you there other than if you place the
LG includes outside the web accessible folders how do you address the
LG managers of virtual hosts for the ability to modify, delete or add to
LG their particular include file? Additionally, how do you address
LG the naming convention of the include file.

LG i.e.
LG Site 'A' is using config.php
LG Site 'B' is using config.inc.php
LG Site 'C' wants to use config.php



T include('somefile.php');
T and it will be found regardless of where the script is located.

LG That's true enough..

LG BTW, good to see another TheBat! user here.

LG Thanks again.

I only do stuff for my own server which actually creates a couple
 of server variables called:

 SERVER[DOMAIN_ROOT] and SERVER[PHPINCDIR] which have the same
 values as the script we just cobbled together for each virtual
 domain.
 I don't suffer from the problem of lack of access to the
 include directory, So all my domains follow this layout:

/usr/local/apache/domains/domain1.com //root and chroot for ftp
 access
/usr/local/apache/domains/domain1.com/www web document root

/usr/local/apache/domains/domain1.com/include for all include files

If a hosting provider locks you in to the document root it's time to
change provider :)
As for naming convention I use .inc and stop apache from serving .inc
files.

-- 
regards,
Tom

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



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-06 Thread Tom Rogers
Hi Leif,

Monday, March 7, 2005, 10:03:48 AM, you wrote:
LG Hello Tom,

LG Friday, March 4, 2005, 9:13:41 PM, you wrote:
TR This will set the include path just before the document root:

LG H. Not quite what I'm looking for. I set up some test folders and
LG files on a development machine to play with your script.

LG Here's how it was laid out:

LG The document root for the test site:
LG c:\sambar\docs\test

LG A subfolder of the doc root
LG folder1

LG A subfolder of the above folder1
LG folder2

LG Placing a file called test.php (containing your script) in all three
LG places (doc root, folder1, folder1/folder2) gives you the following
LG respectively. 

LG Root: c:\sambar\docs\test\test.php
LG Document root: c:\sambar\docs\test\test.php this is wrong
LG Base: test.php
LG Include: c:\cambar\docs\test\include
LG OS: winnt
LG Include: c:\cambar\docs\test\include;.;C:\php5\pear

Try running this one:

?php
if(isset($_SERVER[SCRIPT_FILENAME])){
$file_name = $_SERVER['SCRIPT_FILENAME'];
echo File name: $file_namebr;

$script = $_SERVER['SCRIPT_NAME'];
echo Script: $scriptbr;

$document_root = str_replace($script,'',$file_name);
echo Document root: $document_rootbr;

$base = basename($document_root);
echo Base: $basebr;

$include = str_replace($base,'include',$document_root);
echo Include: $includebr;

$os = strtolower(PHP_OS);
echo OS: $osbr;

$lk = ':';
$org_include = ini_get(include_path);
if(preg_match('/^win/i',$os))   $lk = ';';

ini_set(include_path,$include.$lk.$org_include);
echo Include: .ini_get(include_path).br;
}

and let me see what it prints

-- 
regards,
Tom

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



Re: [PHP] error from 4.3.10: The specified procedure could not be found.

2005-03-06 Thread Tom Rogers
Hi,

Monday, March 7, 2005, 4:55:01 AM, you wrote:
JM Forgive me if this has been answered before, but all I was able to find
JM was a bogus bug report on this issue that did not contain any useful
JM information.  When installing php 4.3.10 on a Win2k3 machine I'm getting
JM the The specified procedure could not be found. Error from any php
JM page I attempt to execute.  I don't have any extensions enabled and this
JM is a completely vanilla install of 4.3.10.  Followed the installation
JM procedure to a tee.  It works with 4.3.6 but 4.3.6 has other
JM show-stopper bugs.  It looks like other people are having this problem
JM as well, though it doesn't appear (at least, not to Google) that anyone
JM has been able to solve it.

JM Any information is greatly appreciated, including links to any FAQs that
JM might be helpful since I haven't found any that contain *any* useful
JM information on this problem.

JM Thanks,
JM -Javier

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


Make sure php4ts.dll is where windows can find it, put it in the same
directory as apache or in the windows directory.
(If your not using apache .. you should be :)

-- 
regards,
Tom

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



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-06 Thread Tom Rogers
Hi,

Monday, March 7, 2005, 1:08:27 PM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 6:18:54 PM, you wrote:
TR and let me see what it prints

LG Still not quite there.

LG Site root
LG **
LG File name: C:\Sambar\docs\test\test.php
LG Script: /test.php
LG Document root: C:\Sambar\docs\test\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\include
LG OS: winnt
LG Include: C:\Sambar\docs\test\include;.;C:\php5\pear

LG **

LG Site root/folder1
LG ***
LG File name: C:\Sambar\docs\test\folder1\test.php
LG Script: /folder1/test.php
LG Document root: C:\Sambar\docs\test\folder1\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\folder1\include
LG OS: winnt
LG Include: C:\Sambar\docs\test\folder1\include;.;C:\php5\pear

LG ***

LG Site root/folder1/folder2
LG ***
LG File name: C:\Sambar\docs\test\folder1\folder2\test.php
LG Script: /folder1/folder2/test.php
LG Document root: C:\Sambar\docs\test\folder1\folder2\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\folder1\folder2\include
LG OS: winnt
LG Include:
LG C:\Sambar\docs\test\folder1\folder2\include;.;C:\php5\pear

LG ***

LG Thanks.

LG Cheers,
LG Leif Gregory 

LG -- 
LG TB Lists Moderator (and fellow registered end-user)
LG PCWize Editor  /  ICQ 216395  /  PGP Key ID 0x7CD4926F
LG Web Site http://www.PCWize.com


Ok I see where is is going wrong, try this:

?php
if(isset($_SERVER[SCRIPT_FILENAME])){
$file_name = str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
echo File name: $file_namebr;

$script = str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
echo Script: $scriptbr;

$document_root = str_replace($script,'',$file_name);
echo Document root: $document_rootbr;

$base = basename($document_root);
echo Base: $basebr;

$include = str_replace($base,'include',$document_root);
echo Include: $includebr;

$os = strtolower(PHP_OS);
echo OS: $osbr;

$lk = ':';
$org_include = ini_get(include_path);
if(preg_match('/^win/i',$os))   $lk = ';';

ini_set(include_path,$include.$lk.$org_include);
echo Include: .ini_get(include_path).br;
}

-- 
regards,
Tom

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



Re: [PHP] SOLVED: Re: [PHP] Document root, preferred way to find it???

2005-03-06 Thread Tom Rogers
Hi,

Monday, March 7, 2005, 3:57:50 PM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 10:00:17 PM, you wrote:
TR Ok I see where is is going wrong, try this:

LG Oh, very close. Although you have it at $document_root and all
LG that needs to be added is '/include' like below:

LG $include = $document_root . '/include';

LG Otherwise it's one directory too far up because you're replacing the
LG site root 'test' (in this case) with 'include'.

LG We wanted: 'C:/Sambar/docs/test/include'

LG Here's from your script.

LG Site root:
LG **

LG File name: C:/Sambar/docs/test/test.php
LG Script: /test.php
LG Document root: C:/Sambar/docs/test
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/include;.;C:\php5\pear

LG **

LG Site root/folder1
LG **

LG File name: C:/Sambar/docs/test/folder1/test.php
LG Script: /folder1/test.php
LG Document root: C:/Sambar/docs/test
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/include;.;C:\php5\pear

LG **

LG Site root/folder1/folder2
LG **

LG File name: C:/Sambar/docs/test/folder1/folder2/test.php
LG Script: /folder1/folder2/test.php
LG Document root: C:/Sambar/docs/test
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/include;.;C:\php5\pear

LG **



LG After my change:

LG File name: C:/Sambar/docs/test/folder1/folder2/test.php
LG Script: /folder1/folder2/test.php
LG Document root: C:/Sambar/docs/test
LG Base: test
LG Include: C:/Sambar/docs/test/include
LG OS: winnt
LG Include: C:/Sambar/docs/test/include;.;C:\php5\pear

LG The other two folders moving back up the tree are the same result.

LG So the final looks like:
LG 

LG if(isset($_SERVER[SCRIPT_FILENAME])){
LG $file_name =
LG str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
LG echo File name: $file_namebr;

LG $script = str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
LG echo Script: $scriptbr;

LG $document_root = str_replace($script,'',$file_name);
LG echo Document root: $document_rootbr;

LG $base = basename($document_root);
LG echo Base: $basebr;

LG //$include = str_replace($base,'include',$document_root);
LG $include = $document_root . '/include';
LG echo Include: $includebr;

LG $os = strtolower(PHP_OS);
LG echo OS: $osbr;

LG $lk = ':';
LG $org_include = ini_get(include_path);
LG if(preg_match('/^win/i',$os))   $lk = ';';

LG ini_set(include_path,$include.$lk.$org_include);
LG echo Include: .ini_get(include_path).br;
LG }

LG 

LG It's a great effort and looks bulletproof. Can you shoot any holes in
LG mine? A full explanation at:
LG http://www.devtek.org/tutorials/dynamic_document_root.php

LG I only throw mine back out there because it's shorter. I think it's
LG solid, but only because I haven't broken it yet. :-)

LG Both our solutions suffer the same problem. They have to be on every
LG page that requires an include, because we can't rely on a new host
LG having our code in their auto_prepend file

LG **

LG function dynRoot()
LG {
LG   $levels = substr_count($_SERVER['PHP_SELF'],/);

LG   for ($i=0; $i  $levels - 1; $i++)
LG   {
LG $relativeDir .= ../;
LG   }

LG   return $relativeDir;
LG }

LG include(dynRoot() . 'includes/somefile.php')

LG **

LG Thanks again!


LG Cheers,
LG Leif Gregory 

LG -- 
LG TB Lists Moderator (and fellow registered end-user)
LG PCWize Editor  /  ICQ 216395  /  PGP Key ID 0x7CD4926F
LG Web Site http://www.PCWize.com

I do this for security as I have things in include that I don't want
to be avaiable directly to the browser Also you don't need a path for include
files you can just do:

include('somefile.php');

and it will be found regardless of where the script is located.


-- 
regards,
Tom

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



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-04 Thread Tom Rogers
Hi,

Saturday, March 5, 2005, 5:47:07 AM, you wrote:
LG Hello Richard,

LG Friday, March 4, 2005, 11:41:29 AM, you wrote:
R http://php.net/set_include_path


LG Ok... Maybe I should put all this together in one e-mail so that all
LG the issues can be looked at...

LG The problem:

LG Finding a reliable method to include files, keeping in mind the
LG following:

LG 1. The site could be moved to a completely new host which could be of
LGa different OS, and/or web server software, and could either be the
LGone and only site on that host (dedicated server), or could be a
LGvirtual host (shared server).

LG 2. The site could remain on the same host but is required to move to a
LGnew path. i.e. from htdocs/mysite to htdocs/mynewsite

LG 3. The web host may or may not allow the use of .htaccess (Some Sambar
LGconfigurations for example).

LG 4. The method used would not affect any other virtual hosts. Meaning,
LGthe method used must be independent for each virtual host.

LG 5. The method used would not utilize a folder where other virtual
LGhosts could gain access to the included file (php.ini
LGinclude_path).

LG 6. The method (and this is the important one IMHO) would not require
LGediting x number of pages in a site to change some static path
LGthat was set on each page.

LG 7. The method used would not require a dedicated include file in
LGevery single folder of the site that could be included because it's
LGin the same folder as the page needing it, because those would all
LGhave to be edited to fix the path if condition 1 or 2 was met.


LG Previously proposed solutions:

LG 1. PHP.ini include_path
LGThis affects all virtual hosts and would require administrative
LGoverhead to prevent the owners of each virtual host from gaining
LGaccess to other virtual host's include files. I suppose you could
LGset it to something like: include_path=/php/includes and have a
LGseparate subfolder under that for each virtual host. But since that
LGfolder is outside the web folder, there would have to be some
LGmechanism (additional FTP account) for each person to gain access
LGto their own include folder to add/edit/delete files in that
LGfolder. Then if the site is moved and they aren't using an
LGinclude_path, you have to fix all your pages.

LG 2. set_include_path
LGThis means if your site moves, you must edit x number of pages in
LGthe site to correct the path.

LG 3. An include file in every directory to set the include path.
LGYou'd have to edit x number of these files to correct the path if
LGthe site moves. This would be much less work than the previous
LGitem, but it could be a lot of work on very big sites where you
LGdon't have shell accounts to do some scripted find/replace with.

LG 4. Use the full URL to the file in the include statement.
LGSee item 2.

LG 5. $_SERVER[DOCUMENT_ROOT] and $_SERVER['PATH_TRANSLATED']
LGNot always available or incorrect see
LGmid:[EMAIL PROTECTED]


LG I may have missed some things, and if I've misunderstood how something
LG should work, then please let me know. I'm just looking for a more or
LG less foolproof method which doesn't require fixing code if the site is
LG moved. The closest I can come to it is the function I wrote but is a
LG pain because you have to put it in every page where you need an
LG included file. Granted, you only have to do it once, and then you're
LG done and a site move wont affect it, but it's still kludgy if you ask
LG me.

LG ***
LG ?php
LG function dynRoot() 
LG { 
LG   $levels = substr_count($_SERVER['PHP_SELF'],/); 

LG   for ($i=0; $i  $levels - 1; $i++) 
LG   { 
LG $relativeDir .= ../; 
LG   } 

LG   return $relativeDir; 
LG }
?
LG ***

LG and then calling it as such:

LG include(dynRoot() . 'includes/db_connect.php');


LG I've had to move client sites between Sambar, Apache, IIS and Windows,
LG Linux. Most times I've had to go in and fix include paths because one
LG of the above solutions were originally used and wasn't viable on the
LG new host.

LG Thanks.
   

LG -- 
LG Leif (TB lists moderator and fellow end user).

LG Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
LG Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB


This will set the include path just before the document root:

if(isset($_SERVER[SCRIPT_FILENAME])){
$root = $_SERVER['SCRIPT_FILENAME'];
//echo Root: $rootbr;

$script = $_SERVER['SCRIPT_NAME'];
$document_root = str_replace($script,'',$root);
//echo Document root: $document_rootbr;

$base = basename($document_root);
//echo Base: $basebr;

$include = str_replace($base,'include',$document_root);
//echo Include: $includebr;

$os = strtolower(PHP_OS);
//echo OS: $osbr;

$lk = ':';
$org_include = ini_get(include_path);

Re[3]: [PHP] Document root, preferred way to find it???

2005-03-04 Thread Tom Rogers
Hi,

TR This will set the include path just before the document root:

TR if(isset($_SERVER[SCRIPT_FILENAME])){
TR $root = $_SERVER['SCRIPT_FILENAME'];
TR //echo Root: $rootbr;

TR $script = $_SERVER['SCRIPT_NAME'];
TR $document_root = str_replace($script,'',$root);
TR //echo Document root: $document_rootbr;

TR $base = basename($document_root);
TR //echo Base: $basebr;

TR $include = str_replace($base,'include',$document_root);
TR //echo Include: $includebr;

TR $os = strtolower(PHP_OS);
TR //echo OS: $osbr;

TR $lk = ':';
TR $org_include = ini_get(include_path);
TR if(preg_match('/^win/i',$os))   $lk = ';';

TR ini_set(include_path,$include.$lk.$org_include);
TR //echo Include: .ini_get(include_path).br;
TR }

TR -- 
TR regards,
TR Tom


Forgot to tell you to put it in the auto_prepend file and it will work
for all files :)

-- 
regards,
Tom

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



Re: [PHP] line feed

2005-03-04 Thread Tom Rogers
Hi,

Saturday, March 5, 2005, 12:38:20 AM, you wrote:
BS Hello.

BS How do i print a line return using the echo command, for when i see the
BS page source,
BS i get the code line by line and not all in the same line.

BS using double quotes (  ), i can put \n at the end and i get the result
BS i want,
BS but, using sinle quotes ( ' ), \n doesnt work.

BS if i use double quotes, in a simple html comand i need to use \  and i
BS dont want that.

BS is any way i could use single quotes, and getting the line feed ??
BS example:
BS Double quotes:
BS echo table border=\1\ width=\800px\\n;

BS single quotes:
BS echo 'table border=1 width=800px';


BS cheers

BS Bruno Santos

BS -- 
BS Say no to software patents
BS www.nosoftwarepatents.com/
BS --
BS [EMAIL PROTECTED]
BS --
BS Divisao de Informatica
BS [EMAIL PROTECTED]
BS Tel: +351 272 000 155
BS Fax: +351 272 000 257
BS --
BS Hospital Amato Lusitano
BS [EMAIL PROTECTED]
BS Tel: +351 272 000 272
BS Fax: +351 272 000 257


you could do:
define('LF',\n);
echo 'table border=1'.LF;

-- 
regards,
Tom

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



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-03 Thread Tom Rogers
Hi,

Thursday, March 3, 2005, 11:54:48 AM, you wrote:

A If I'm reading you correctly, then a truly transportable include might look 
like
A this:

A $doc_root= (isset($_SERVER['path_translated'])?
A $_SERVER['path_translated'] : 
A  $_SERVER['document_root'];


Exactly

-- 
regards,
Tom

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



  1   2   3   4   5   6   7   8   9   >