[PHP] PHP5 release HTTP Authentication not working on FreeBSD.

2004-07-15 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Guys,
I've just upgraded from 5.0 rc3 to 5.0 release on freeBSD (using the
ports) and now find that HTTP Authentication dosent work.
Here is the test script that i am using:
?php
~  error_reporting(E_ALL);
~  ini_set('display_errors', true);
~  if (! (isset($_SERVER['PHP_AUTH_USER']) ||
isset($_SERVER['PHP_AUTH_PW']) )) {
~   header('WWW-Authenticate: Basic realm=My Realm');
~   header('HTTP/1.0 401 Unauthorized');
~   echo 'Text to send if user hits Cancel button';
~   exit;
~  } else {
~   echo pHello '{$_SERVER['PHP_AUTH_USER']}'./p;
~   echo pYou entered {$_SERVER['PHP_AUTH_PW']} as your password./p;
~  }
?
And here is the output that i get:
Notice: Undefined index: PHP_AUTH_USER in test.php on line 10
Hello ''.
You entered pass as your password.
As you can see PHP_AUTH_USER is on longer being set. Does anybody else
have this issue or know of a fix?   
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA9o3ZzSfrYDJMXmERAmZqAKCunk+xl2w+RRIKOvbDTQEWjXbGCgCgxXsw
DknafWhfiwLTYrusTzHl0gE=
=IMNL
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] How does one get strtotime() real NOW now that the function behaves according to GNU date syntax?

2004-06-15 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi All,
Now that the strtotime() function behaves in according to GNU date
syntax (which i feel should not have changed in a minor php version bump
but thats a different issue) how does one implement something like the
old system?
Lets say, for example, that i want to get the timestamp for 2 seconds
in the future, before i could have just done:
$t = strtotime('NOW + 2 seconds');
But since the change this will no longer work as you will get the
correct day but with a time of 00:00:02.
I have tried the following but this fails and results in -1:
$t = strtotime('@'.time().' + 2 seconds')
p.s. I know that for the example posted i could just do:
$t = time() +2
But i also want situations where i could have 'next thursday + 3 hours'
etc.
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAzslDzSfrYDJMXmERAqS2AJ4obr0gKSuarYLPvk8pC+abGeG+ywCfV1lj
Q24x2yOTjPzWG+rILSQD/CA=
=EIr6
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Request database_queryf() functions.

2004-05-20 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi All,
After having been talking to lots of people in irc lately who are
haveing problems with SQL injection etc i think that haveing a
*_queryf() function would be really useful to help people esp when it
comes to integers and the id=$id where $id = 1 OR and name='$name'
where $name = name' OR issues for example.
Most of the sprintf formatting would take care of itself but any %s
would automatically have addslashes() applied.
I have a php implementation below for the mysql database.
Let me know what you think or if i have missed anything.
?php
/*
~ * MySQL queryf() function example.
~ */
define('DEBUG', true);
// usage:
// mysql_queryf($query, $link_identifier = NULL, $arg1, $arg2$argN);
function mysql_queryf() {
~$args = func_get_args();
~if(!isset($args[0]) || !(is_null($args[1]) || is_resource($args[1])
) ){
~return false;
~}
~$formatString = array_shift($args);
~$linkIdentifier = array_shift($args);
~$parts = preg_split('/%([
0]|\'.)?-?[0-9]*(\\.[0-9]*)*[%abcdufosxX]/', $formatString, -1,
PREG_SPLIT_OFFSET_CAPTURE);
~$newString = ;
~for($i = 0; $i  count($parts); $i++){
~$start = $parts[$i][1] + strlen($parts[$i][0]);
~if(isset($parts[$i + 1][1])){
~$length = $parts[$i + 1][1] - $start;
~}else{
~$length = strlen($formatString) - $start;
~}
~$formatCode = substr($formatString, $start, $length);
~$newString .= $parts[$i][0].sprintf($formatCode,
(isset($args[$i]) ? ((substr($formatCode, -1, 1) == 's') ?
addslashes($args[$i]) : $args[$i]) : NULL));
~}
~if(DEBUG === true){
~print(Query is:\n.$newString.\n);
~}else{
~if(is_resource($linkIdentifier)){
~return mysql_query($newString, $linkIdentifier);
~}else{
~return mysql_query($newString);
~}
~}
}
mysql_queryf('SELECT * FROM blah WHERE id=%d AND name=\'%\'.-34s\' AND
account=\'%0.2f\' AND blah=%06d AND value  \'30%%\'', NULL, '1 OR',
'name\'s');
?
Output:
Query is:
SELECT * FROM blah WHERE id=1 AND
name='name\'s...' AND account='0.00' AND
blah=00 AND value  '30%'
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFArKwGzSfrYDJMXmERAlTAAJ9NMfOG3nLlsU4kPGPDB0UekYh70QCfYBqS
8FDg6oC1MtUWgaK6A/GYmsg=
=MtCS
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: [PHP-DB] Request database_queryf() functions.

2004-05-20 Thread William Bailey
If you need a better source example/layout goto:
http://nopaste.php-q.net/59720
William Bailey wrote:
Hi All,
After having been talking to lots of people in irc lately who are
haveing problems with SQL injection etc i think that haveing a
*_queryf() function would be really useful to help people esp when it
comes to integers and the id=$id where $id = 1 OR and name='$name'
where $name = name' OR issues for example.
Most of the sprintf formatting would take care of itself but any %s
would automatically have addslashes() applied.
I have a php implementation below for the mysql database.
Let me know what you think or if i have missed anything.
?php
/*
~ * MySQL queryf() function example.
~ */
define('DEBUG', true);
// usage:
// mysql_queryf($query, $link_identifier = NULL, $arg1, $arg2$argN);
function mysql_queryf() {
~$args = func_get_args();
~if(!isset($args[0]) || !(is_null($args[1]) || is_resource($args[1])
) ){
~return false;
~}
~$formatString = array_shift($args);
~$linkIdentifier = array_shift($args);
~$parts = preg_split('/%([
0]|\'.)?-?[0-9]*(\\.[0-9]*)*[%abcdufosxX]/', $formatString, -1,
PREG_SPLIT_OFFSET_CAPTURE);
~$newString = ;
~for($i = 0; $i  count($parts); $i++){
~$start = $parts[$i][1] + strlen($parts[$i][0]);
~if(isset($parts[$i + 1][1])){
~$length = $parts[$i + 1][1] - $start;
~}else{
~$length = strlen($formatString) - $start;
~}
~$formatCode = substr($formatString, $start, $length);
~$newString .= $parts[$i][0].sprintf($formatCode,
(isset($args[$i]) ? ((substr($formatCode, -1, 1) == 's') ?
addslashes($args[$i]) : $args[$i]) : NULL));
~}
~if(DEBUG === true){
~print(Query is:\n.$newString.\n);
~}else{
~if(is_resource($linkIdentifier)){
~return mysql_query($newString, $linkIdentifier);
~}else{
~return mysql_query($newString);
~}
~}
}
mysql_queryf('SELECT * FROM blah WHERE id=%d AND name=\'%\'.-34s\' AND
account=\'%0.2f\' AND blah=%06d AND value  \'30%%\'', NULL, '1 OR',
'name\'s');
?
Output:
Query is:
SELECT * FROM blah WHERE id=1 AND
name='name\'s...' AND account='0.00' AND
blah=00 AND value  '30%'
--
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] SimpleXML node detection.

2004-03-24 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Morning all,

Hopefully a quick question i need to check if a node exists for a
SimpleXML object but no matter how i try i simple cant find a way to do
this as it always creates a new object even if the node dosen't exist in
the xml document.
	My peoblem is that i have something like the following xml...

~section
~namefoo/name
~contentfoo/content
~ignore /
~/section
~section
~nameblah/name
~contentblah/content
~/section
	Where there is an ignore tag to specify that i ignore that item

	Any ideas on how i can check to see it the ignore node exists or not?

- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAYV7azSfrYDJMXmERAlSQAJ40wLIRmbSy0vKy0bdLSqU/JGnqbACfd/Hc
114wFBzKu+Z6JvsosvuRKBA=
=lhbH
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PHP5 simpleXML bug or am i just being silly :)

2004-02-27 Thread William Bailey
To follow up my question from yesterday i have made a test script that 
will produce the problem that i am seeing.

The attached script will produce the following output on both my windows 
box (which runs a 2 day old php5 snapshot) and my FreeBSD box which uses 
a version out of the ports. The php version below is from the freeBSD 
installation...

[[::OUTPUT START::]]

Current PHP version is : 5.0.0a4-alexdupre

$xml is:
simplexml_element Object
(
[user] = Array
(
[0] = simplexml_element Object
(
[login] = user1
[password] = letMeIn
[site] = Array
(
[0] = www.pro-net.co.uk
[1] = www.example.com
)
)

[1] = simplexml_element Object
(
[login] = user2
[password] = myPassword
[site] = www.pro-net.co.uk
)
)

)

Trying to authenticate user1 with password letMeIn.

$user is:
simplexml_element Object
(
[login] = user1
[password] = letMeIn
[site] = Array
(
[0] = www.pro-net.co.uk
[1] = www.example.com
)
)

$user-site is:
Array
(
[0] = simplexml_element Object
(
)
[1] = simplexml_element Object
(
)
)

$user-site[0] is:
simplexml_element Object
(
)
[[::OUTPUT END::]]


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

Re: [PHP] PHP5 simpleXML bug or am i just being silly :)

2004-02-27 Thread William Bailey
OK sonce the php example code attachment go nuked here it is...

[[::PHP START::]]
?php
header('Content-type: text/plain');
$xmlstr = '?xml version=1.0?
access
user
loginuser1/login
passwordletMeIn/password
sitewww.pro-net.co.uk/site
sitewww.example.com/site
/user
user
loginuser2/login
passwordmyPassword/password
sitewww.pro-net.co.uk/site
/user
/access';
$nl  = \r\n;
$xml = simplexml_load_string($xmlstr);
print('Current PHP version is : '.phpversion().$nl.$nl);

print('$xml is:'.$nl);
print_r($xml);
print($nl.$nl);
// Test authentication to get the correct user information
$login = 'user1';
$password = 'letMeIn';
print($nl.$nl.'Trying to authenticate '.$login.' with password 
'.$password.'.'.$nl.$nl);
$isAuth = false;
foreach($xml-user as $user){
if(utf8_decode($user-login) == $login  
utf8_decode($user-password) == $password){
$isAuth = true;
break;
}
}
if(!$isAuth){
print($nl.$nl.'Invalid User.'.$nl);
die();
}

// So lets output the variables to see what we have...
print('$user is:'.$nl);
print_r($user);
print($nl.$nl);
print('$user-site is:'.$nl);
print_r($user-site);
print($nl.$nl);
print('$user-site[0] is:'.$nl);
print_r($user-site[0]);
print($nl.$nl);
?
[[::PHP END::]]


William Bailey wrote:

To follow up my question from yesterday i have made a test script that 
will produce the problem that i am seeing.

The attached script will produce the following output on both my windows 
box (which runs a 2 day old php5 snapshot) and my FreeBSD box which uses 
a version out of the ports. The php version below is from the freeBSD 
installation...

[[::OUTPUT START::]]

Current PHP version is : 5.0.0a4-alexdupre

$xml is:
simplexml_element Object
(
[user] = Array
(
[0] = simplexml_element Object
(
[login] = user1
[password] = letMeIn
[site] = Array
(
[0] = www.pro-net.co.uk
[1] = www.example.com
)
)

[1] = simplexml_element Object
(
[login] = user2
[password] = myPassword
[site] = www.pro-net.co.uk
)
)

)

Trying to authenticate user1 with password letMeIn.

$user is:
simplexml_element Object
(
[login] = user1
[password] = letMeIn
[site] = Array
(
[0] = www.pro-net.co.uk
[1] = www.example.com
)
)

$user-site is:
Array
(
[0] = simplexml_element Object
(
)
[1] = simplexml_element Object
(
)
)

$user-site[0] is:
simplexml_element Object
(
)
[[::OUTPUT END::]]


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


[PHP] PHP5 simpleXML bug or am i just being silly :)

2004-02-26 Thread William Bailey
Hi All,

	I am currently working with PHP5 beta and have found something strange 
with the simplexml objects. It seems to be forgetting its values. Below 
is an example..



[[the PHP5 code]]
snip
print('pre');
print('p$this-user::/p');
print_r($this-user);
print('p$this-user-site::/p');
print_r($this-user-site);
print('p$this-user-site[0]::/p');
print_r($this-user-site[0]);
die('/pre');
snip
[[END]]
[[the PHP5 Browser Output]]
$this-user::
simplexml_element Object
(
[login] = wb
[password] = 3c1175c6cdf614fb006cee10fdc325e3aa0f1894
[site] = Array
(
[0] = www.pro-net.co.uk
[1] = www.example.com
)
)

$this-user-site::
Array
(
[0] = simplexml_element Object
(
)
[1] = simplexml_element Object
(
)
)

$this-user-site[0]::
simplexml_element Object
(
)
[[END]]
	Shouldn't $this-user-site return the Array displayed in the output 
for $this-user or even shouldn't the simplexml_element Objects for 
$this-user-site have a value or something. Basically they shouldn't be 
blank otherwise how to you get the data?

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


[PHP] Issue with 'W' in the date() function?

2004-02-03 Thread William Bailey
Hi all,

	Can somebody please explain this for me...

[EMAIL PROTECTED]:/usr/home/wb [11]- php
?php
$time = strtotime('now -5 weeks');
printf(\n\n%s is in week %d of the year %d\n\n, date('Y-m-d', $time), 
date('W', $time), date('Y', $time));
?
^D

2003-12-30 is in week 1 of the year 2003

[EMAIL PROTECTED]:/usr/home/wb [12]-

	Why does it return 1 as the week of the year for that date?

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


Re: [PHP] Re: Issue with 'W' in the date() function?

2004-02-03 Thread William Bailey
Hi Mike,

Because week 1 is defined as the first week with four or more days in 
the new year.  Therefore, working backwards, the 29th-31st are also in 
week 1 in 2004.
Thanks, So now i will just have to check the year and then work out from 
that what the correct year should be. (i need to get a YW value).

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


Re: [PHP] Re: Issue with 'W' in the date() function?

2004-02-03 Thread William Bailey
Ok. Its been a long day and my brain is starting to shut down so...

How would i work out which year the 'W' relates to?

I have a unix timestamp value and want to end up with the correct 'YW' 
value.



William Bailey wrote:

Hi Mike,

Because week 1 is defined as the first week with four or more days in 
the new year.  Therefore, working backwards, the 29th-31st are also in 
week 1 in 2004.


Thanks, So now i will just have to check the year and then work out from 
that what the correct year should be. (i need to get a YW value).

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


Re: [PHP] Re: Issue with 'W' in the date() function?

2004-02-03 Thread William Bailey
I really have to stop replying to myself :) Anyway i think that i have 
the solution...

function timestamp2YearWeek ($time) {
if (date('z', $time)  360  date('W', $time) == 1) {
return sprintf('%d%02d', date('Y', $time)+1, date('W', $time));
}else{
return sprintf('%d%02d', date('Y', $time), date('W', $time));
}
}


William Bailey wrote:

Ok. Its been a long day and my brain is starting to shut down so...

How would i work out which year the 'W' relates to?

I have a unix timestamp value and want to end up with the correct 'YW' 
value.



William Bailey wrote:

Hi Mike,

Because week 1 is defined as the first week with four or more days in 
the new year.  Therefore, working backwards, the 29th-31st are also 
in week 1 in 2004.


Thanks, So now i will just have to check the year and then work out 
from that what the correct year should be. (i need to get a YW value).


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


[PHP] PHP5 XSLT how to.

2003-12-05 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hello again.

I am currently testing the php5 beta and really like the new DOM
objects but i am haveing trouble finding out how i can apply a XSLT
template to a DOM document. Does anybody know how i can do this?
I have tried looking at the DOM documentation in the online php manual
but am finding it to be all out of date in respect to the php5
implementation so if anybody could also point me to the correct
information i would be very happy.
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/0JaxzSfrYDJMXmERAqxMAKCaScLStKA/0+TMMZRONmVHlVy14ACgw4l6
TkqlC7o1M7mu0cJxbJLVaCo=
=evdC
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PHP5 XSLT how to.

2003-12-05 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Ok Just incase anybody else would like to know how to do it i found that
the following works:
PHP Code 

$dom = new DomDocument();
$aboutNode = $dom-appendChild($dom-createElement('about'));
$aboutNode-setAttribute('name', 'My Application');
$versionNode = $aboutNode-appendChild($dom-createElement('version'));
$versionNode-setAttribute('major', 0);
$versionNode-setAttribute('minor', 1);
$versionNode-setAttribute('revision', 5);
$versionNode-appendChild($dom-createTextNode('Its a test'));
$xsl = new domDocument();
$xsl-load('loading.xsl');
$proc = new xsltprocessor;
$proc-importStylesheet($xsl);
print($proc-transformToXml($dom));

loading.xsl ---

?xml version=1.0 encoding=ISO-8859-1?
xsl:stylesheet version=1.0
xmlns:xsl=http://www.w3.org/1999/XSL/Transform;
xsl:template match=/
html
head
titleAbout/title
/head
body
~h1 style=text-align:center; margin: 0; padding: 0;
xsl:value-of select=/about/@name/
~vxsl:value-of select=/about/version/@major/.xsl:value-of
select=/about/version/@minor/.xsl:value-of
select=/about/version/@revision/ (xsl:value-of
select=/about/version/)/h1
/body
/html
/xsl:template
/xsl:stylesheet
- ---

Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/


| William Bailey wrote:
|
| Hello again.
|
| I am currently testing the php5 beta and really like the new DOM
| objects but i am haveing trouble finding out how i can apply a XSLT
| template to a DOM document. Does anybody know how i can do this?
|
| I have tried looking at the DOM documentation in the online php manual
| but am finding it to be all out of date in respect to the php5
| implementation so if anybody could also point me to the correct
| information i would be very happy.
|
| --
| Regards,
| William Bailey.
| Pro-Net Internet Services Ltd.
| http://www.pro-net.co.uk/
|
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/0MLkzSfrYDJMXmERAuTIAKCXEXZz/du+27Gvs8H5AYlOnA8zPgCfYjdb
W4hfTj5ah+a57Cn9kp01rLQ=
=MUEY
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Getting the required GD Memmory Usage.

2003-11-27 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Sorry but thats not what i'm after. I want to know the available memory
needed to load the image. The default php memory limit is 8M and if the
image is large php is not able to load it because the 8M limit is
reached and therefore causes php to error out.
Is there a way to calculate the memory required to load the image
without haveing to load it? Would the following work...
	$memSize = $imageWidth * $imageHeight * 4

	This assumes that gd uses 32bits per pixel.

Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
Vail, Warren wrote:
| actually what you probably need is
|
| http://www.zend.com/manual/function.getimagesize.php
|
| Warren Vail
|
| -Original Message-
| From: William Bailey [mailto:[EMAIL PROTECTED]
| Sent: Wednesday, November 26, 2003 10:01 AM
| To: [EMAIL PROTECTED]
| Subject: [PHP] Getting the required GD Memmory Usage.
|
|
| Hi All,
|
|   I have a site that loads images with the built in GD functions. Most
| of
| the images are small and load fine however there are a few images that
| are large and when trying to load them causes php to exit with the
| unable to allocate memory message. I was wondering if anybody knows of a
| way to look at a file (in this case a JPEG) and then calculate the
| memory requirements required for GD to load it.
|
|   I know that i can just set the memory limit value to a higher value
| but
| i don't want to load these large images anyway so if i could work out
| the GD memory requirement without having to load the image it would be
| most useful.
|
| --
| Regards,
|   William Bailey.
|   Pro-Net Internet Services Ltd.
|   http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/xmOQzSfrYDJMXmERAsixAKCoEDRd4JSXHuWvLtXA19zuZiBSJgCeMvJ+
7cp6i4j3YM0n3FVAzMIQFfg=
=CIC2
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Getting the required GD Memmory Usage.

2003-11-26 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi All,

I have a site that loads images with the built in GD functions. Most of
the images are small and load fine however there are a few images that
are large and when trying to load them causes php to exit with the
unable to allocate memory message. I was wondering if anybody knows of a
way to look at a file (in this case a JPEG) and then calculate the
memory requirements required for GD to load it.
I know that i can just set the memory limit value to a higher value but
i don't want to load these large images anyway so if i could work out
the GD memory requirement without having to load the image it would be
most useful.
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/xOpKzSfrYDJMXmERAgcoAJ4werLQZqzEIoopAnmsUu0Xaz098QCdGv/N
C7QxkYlaoya1To4PH76gmd0=
=ffjB
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP5 interfaces

2003-11-12 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi all,

I am currently starting a new personal project and thought that i would
start to implement it in PHP5. Now the new object model in PHP5 is
really nice and haveing objects bassed by reference by default saves a
lot of head aches :)
My question however probably comes from my lack of OO understanding.
Lets say i have the following class:
Final class Statistic {
~function __construct ($min, $max, $initValue=0) {
~}
~public function setValue ($value, $strict = false) {
~}
~public function applyDelta ($delta, $strict = false) {
~}
~public function getValue () {
~}
}
I want to implement some kind of onChange function and from what  i can
see that i have 2 options:
1. Create an OnChange object and make Statistic a child class.
2. Create an OnCHange interface and make Statistic implement it.
The problem is that nither are fully what i'm after. I want to be able
to use the onChange functionality on a number of other classes (all
implemented in the same way) and i also want to create a few other
onBlah functions that i also want to apply to objects along side if
required the onChange functionality.
So from this i can see that an interface would be the best way to go as
a class can implement any number of interfaces but can only be extend
from one parent. However using the example given all the onChange
functions for each object function exactly the same and will therefore
give me a lot of repeated code.
Is there any way to get around this. Something like an interface with a
fully defined function is what i'm really after.
The onChange function is currently...

~public function onChange ($object=null, $method=null) {
~if($object == null){
~$method = null;
~}
~if($object != null  !is_object($object)){
~$this-onChange();
~}else{
~$this-onChangeObject = $object;
~$this-onChangeMethod = $method;
~}
~}
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/shN6zSfrYDJMXmERAhv6AJ9a9D6D7C295Skefsi8HtInDiq9AgCgvLUa
DZiQJni5w0VqZOjfOdQ1xhc=
=b6B3
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP5 interfaces

2003-11-12 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi all,

I am currently starting a new personal project and thought that i would
start to implement it in PHP5. Now the new object model in PHP5 is
really nice and haveing objects bassed by reference by default saves a
lot of head aches :)
My question however probably comes from my lack of OO understanding.
Lets say i have the following class:
Final class Statistic {
~function __construct ($min, $max, $initValue=0) {
~}
~public function setValue ($value, $strict = false) {
~}
~public function applyDelta ($delta, $strict = false) {
~}
~public function getValue () {
~}
}
I want to implement some kind of onChange function and from what  i can
see that i have 2 options:
1. Create an OnChange object and make Statistic a child class.
2. Create an OnCHange interface and make Statistic implement it.
The problem is that nither are fully what i'm after. I want to be able
to use the onChange functionality on a number of other classes (all
implemented in the same way) and i also want to create a few other
onBlah functions that i also want to apply to objects along side if
required the onChange functionality.
So from this i can see that an interface would be the best way to go as
a class can implement any number of interfaces but can only be extend
from one parent. However using the example given all the onChange
functions for each object function exactly the same and will therefore
give me a lot of repeated code.
Is there any way to get around this. Something like an interface with a
fully defined function is what i'm really after.
The onChange function is currently...

~public function onChange ($object=null, $method=null) {
~if($object == null){
~$method = null;
~}
~if($object != null  !is_object($object)){
~$this-onChange();
~}else{
~$this-onChangeObject = $object;
~$this-onChangeMethod = $method;
~}
~}
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/shU0zSfrYDJMXmERAr8OAJ9L1lQ5VUkNuHTJLP7jUpHAtSWheQCdF12b
XYoWdVBKzf4eYF3cBaKRamk=
=n8KJ
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP5 interfaces

2003-11-12 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi all,

I am currently starting a new personal project and thought that i would
start to implement it in PHP5. Now the new object model in PHP5 is
really nice and haveing objects bassed by reference by default saves a
lot of head aches :)
My question however probably comes from my lack of OO understanding.
Lets say i have the following class:
Final class Statistic {
~function __construct ($min, $max, $initValue=0) {
~}
~public function setValue ($value, $strict = false) {
~}
~public function applyDelta ($delta, $strict = false) {
~}
~public function getValue () {
~}
}
I want to implement some kind of onChange function and from what  i can
see that i have 2 options:
1. Create an OnChange object and make Statistic a child class.
2. Create an OnCHange interface and make Statistic implement it.
The problem is that nither are fully what i'm after. I want to be able
to use the onChange functionality on a number of other classes (all
implemented in the same way) and i also want to create a few other
onBlah functions that i also want to apply to objects along side if
required the onChange functionality.
So from this i can see that an interface would be the best way to go as
a class can implement any number of interfaces but can only be extend
from one parent. However using the example given all the onChange
functions for each object function exactly the same and will therefore
give me a lot of repeated code.
Is there any way to get around this. Something like an interface with a
fully defined function is what i'm really after.
The onChange function is currently...

~public function onChange ($object=null, $method=null) {
~if($object == null){
~$method = null;
~}
~if($object != null  !is_object($object)){
~$this-onChange();
~}else{
~$this-onChangeObject = $object;
~$this-onChangeMethod = $method;
~}
~}
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/shpezSfrYDJMXmERAoQlAJ9VpDbsy85ID6gvdQ1WP2qN92NXYgCeOx4l
Ncl/xFGmYVvmftXRIgLbrew=
=tcFs
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] seems like magic_quotes_gpc is turning itsself on!

2003-10-21 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi All,

I have a strange problem with one of the sites i work on and provide
support for. I the following block of code that checks to see if
magic_quotes_gpc is enabled and if it is it dies with an error message:
if((integer)ini_get('magic_quotes_gpc')!=0){
~debug('Magic Quotes GPC is currently active. Please disable.');
}
The debug functoin just displays a sorry message on the browser and
emails the description and the serialized $GLOBALS variable back to me.
in the php.ini i have the following:

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
Now every so often say at most 1 in 100 hits a user will see the sorry
screen and i get a call back email and every time its the same issue
'Magic Quotes GPC is currently active. Please disable.'
Anybody have any ideas on where to look?

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/lP+zzSfrYDJMXmERAsiiAJ47tIqPJAnleJ8IuWNqsiStD7lOwgCfcO2n
ooo0+PKIf5T96UoWcqIQVWc=
=hIFY
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] seems like magic_quotes_gpc is turning itsself on!

2003-10-21 Thread William Bailey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
It can be on any page.

The magic_quotes_gpc check takes place in a settings.php file which is
always the first thing included for every php page for this site. It has
a number of define statements and a few other includes and thats about
it. No database connections or anything else apart from class and
function declarations have taken place.
CPT John W. Holmes wrote:

| From: William Bailey [EMAIL PROTECTED]
|
|I have a strange problem with one of the sites i work on and provide
|support for. I the following block of code that checks to see if
|magic_quotes_gpc is enabled and if it is it dies with an error message:
|
|if((integer)ini_get('magic_quotes_gpc')!=0){
|~debug('Magic Quotes GPC is currently active. Please disable.');
|}
|
|The debug functoin just displays a sorry message on the browser and
|emails the description and the serialized $GLOBALS variable back to me.
|
|in the php.ini i have the following:
|
|; Magic quotes for incoming GET/POST/Cookie data.
|magic_quotes_gpc = Off
|
|Now every so often say at most 1 in 100 hits a user will see the sorry
|screen and i get a call back email and every time its the same issue
|'Magic Quotes GPC is currently active. Please disable.'
|
|
| Is it only for certain pages or random ones? Examing $GLOBALS doesn't give
| any clues, I presume? Nothing strange in the query string, etc?
|
| ---John Holmes...
|
|
- --
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/lR68zSfrYDJMXmERArIOAKCW7GgGw1+tp6q+mNNEY3tBtA0hAACgx0mD
8YVju4wwttUPFJtBz+EBwJk=
=xVnS
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] How can one find out what Headers have been sent by a script.

2003-09-18 Thread William Bailey
Hello all,

Does anybody know of a way that i can check to see if a header has already 
been sent by a script?

I am currently finishing a class that has a few functions registered with 
register_shutdown_function(). They take care of database updates and general 
clean up for that object and i want to be able to perform a different action 
depending on if, for example, a 'Location:' header has been sent.

Is there any way i can get a list of headers already sent from a script?

I know i could write a custom myHeader() type function that stores the sent 
headers in a variable and then read it back but i want something that i can 
add to my class and not have to make any changes to other scripts. The class 
im currently working on is just supposed to be dropped in and is then 
expected to run without the need to update anything else.

Thanks in advance.

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/

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



Re: [PHP] How can one find out what Headers have been sent by a script.

2003-09-18 Thread William Bailey
I have found something that seems to work:

?php
header('Location: woof.html');
$h = apache_response_headers();
if(isset($h['Location'])){
header('Location: moo.html');
}
die();
?

Typical i get stuck on something for ages and then as soon as i post to the 
list i figure something out :) oh well hope it helps somebody else.

:)

On Thursday 18 September 2003 15:10, William Bailey wrote:
 Hello all,

   Does anybody know of a way that i can check to see if a header has already
 been sent by a script?

   I am currently finishing a class that has a few functions registered with
 register_shutdown_function(). They take care of database updates and
 general clean up for that object and i want to be able to perform a
 different action depending on if, for example, a 'Location:' header has
 been sent.

   Is there any way i can get a list of headers already sent from a script?

   I know i could write a custom myHeader() type function that stores the
 sent headers in a variable and then read it back but i want something that
 i can add to my class and not have to make any changes to other scripts.
 The class im currently working on is just supposed to be dropped in and is
 then expected to run without the need to update anything else.

   Thanks in advance.

 --
 Regards,
   William Bailey.
   Pro-Net Internet Services Ltd.
   http://www.pro-net.co.uk/

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk/

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



[PHP] Adding to md5 checksums.

2003-04-02 Thread William Bailey
Hi all,

Just wondering if it is possiable to add or combine 2 or more md5 checksums 
togeather?

Basically i've got a value/file that i can get the md5 checksum for but want 
to be able to padd the input value/file with nulls to a specific length 
example:

value is   : abcdef
block size : 4 chars

Therefore i want to get the md5 value of abcdef\x00\x00.

The above example is very small and i could just recreate the string in 
memmory but i will need to do this with much bigger values/files and don't 
want to have to use silly amounts of memmory.

Maybe it would be an idea to add another parameter to the built in md5() 
function that specifies the starting md5 example:

$checksum=md5(\x00\x00, md5(adcdef));

would return the same checksum as:

$checksum=md5(abcdef\x00\x00);

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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



Re: [PHP] Zip to postcode

2003-04-02 Thread William Bailey
Hi Andy,

The following function seems to work for me:

function split_postcode ($postcode) {
if(eregi('(^[A-Z]{1,2})([0-9|A-Z]{1,2}).*([0-9][A-Z]{2}$)', str_replace(' 
', '', $postcode), $parts)){
$outcode=strtoupper(sprintf('%s%s%s', $parts[1], @str_repeat(' ', 
4-strlen($parts[1])-strlen($parts[2])), $parts[2]));
$incode=strtoupper($parts[3]);
return array($outcode, $incode);
}else{
return False;
}
}

On Wednesday 02 April 2003 12:54, Andy wrote:
 Can someone please tell me how i change the following code:
 if (!ereg(^[0-9]{5,5}(\-[0-9]{4,4})?$,$postcode))

 to a UK postcode QQ1 1QQ
 When i fill out the form it tells me that the postcode is not valid and i
 think it is because it is in zip code format.

 Thank you

 Andy

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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



[PHP] Problem: Only 1 fsockopen() connection for apache at a time.

2002-12-03 Thread William Bailey
Hello all.

I have a script that uses fsockopen() to connect to a remote server/port and 
from what i am seeing mod_php4 with apache only allows 1 fsockopen connection 
at a time and will que the other fsockopen calls and then process them when 
the one before it has closed. Is there a way round this?

What i am after is for somebody to be able to goto the php page which will 
then connect via fsockopen to the other server do its send/read stuff and 
then produce the output. At the moment if one pages takes a bit of time to 
finish the remote connection then all the other apache processes just sit 
there and wait for it. The remote server only ever gets 1 connection at a 
time even though there are free connections available.

Has anybody else seen this or know of a way around it.


-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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




Re: [PHP] date

2002-12-03 Thread William Bailey
On Tuesday 03 December 2002 13:57, Shaun wrote:
 Hi,

 please could someone tell me how i can return a month in text from an int
 ie

 getMonth(12)

 returns Decmber. Is this possible?

 Thanks for your help

have a look at the mktime() function. Use this along with the date() function 
to get what you need.

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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




Re: [PHP] php and file uploads/downloads

2002-12-03 Thread William Bailey
On Tuesday 03 December 2002 15:02, Beau Hartshorne wrote:
 Hi,

 I'm working on a system that allows users to upload and then download
 pdf files. Each file is related to a mySQL database entry. To keep
 things simple and consistent, I'd like to store the pdf files like this
 on the server:

 [PRIMARY_KEY].pdf

 But when a user downloads the file, I'd like them to receive something
 like:

 [TITLE].pdf

 Is there a way to get php to rename the file when a user tries to
 download it?

This is all done via HTTP headers.

example:

header('Content-type: application/octet-stream');
header(sprintf('Content-disposition: inline; filename=%s', $fileName));
header(sprintf('Content-length: %d', $fileLength));
// Output file now.

Hope this helps.



 TIA,

 Beau

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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




Re: [PHP] Problem: Only 1 fsockopen() connection for apache at a time.

2002-12-03 Thread William Bailey
On Tuesday 03 December 2002 15:46, Roedel, Mark wrote:
  -Original Message-
  From: William Bailey [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, December 03, 2002 6:04 AM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Problem: Only 1 fsockopen() connection for
  apache at a time.
 
 
  I have a script that uses fsockopen() to connect to a
  remote server/port and from what i am seeing mod_php4
  with apache only allows 1 fsockopen connection at a time
  and will que the other fsockopen calls and then process
  them when the one before it has closed. Is there a way
  round this?

 Not true here...what operating system are you running?  (I know some
 versions of Windows in particular have a limit as to how many
 simultaneous connections the tcp/ip layer can support...)


Ah ha! Ok. I have found the issue, about a min before your email came in. It 
was mozilla :( I had the page loaded in two tabs and was refreshing each tab. 
I tried opening one in mozilla and one in ie and it did work as expected. The 
server made 2 calls to the other server via its fsockopen connection.


 ---
 Mark Roedel   | Blessed is he who has learned to laugh
 Systems Programmer|  at himself, for he shall never cease
 LeTourneau University |  to be entertained.
 Longview, Texas, USA  |  -- John Powell

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


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




[PHP] Help needed with speading up a function.

2002-03-06 Thread William Bailey

Hello again.

I have the following function that generates a prime number of x
bits. It seems to work but i am just trying to see if i can make it any
faster as generateing 1024 bit prime can take a while. so i thoought i
would ask here to see if anybody has any ideas or suggestions.

The function is as follows:

mt_srand((double)microtime()*1);

function generate_prime ($bits) {
$number=gmp_init('0');
for($i=$bits; $i=0; $i--){
$rand=mt_rand()%2;
gmp_setbit($number, $i, $rand);
}
while(gmp_prob_prime($number)1){
$number=gmp_add($number, 1);
}
if(strlen(gmp_strval($number, 2))!=$bits){
$number=generate_prime($bits);
}else{
return (string)gmp_strval($number);
}
}

At the moment im generating a random number of the required length and
then +1ing it untill it is a prime. I suppose i really want to know if
their is some way of knowing how close you are to a possiable prime so
that if the random number is too far away then it could call itself again
and try a different random start location.

I look forward to any ideas that you might have.

Regards,
William.

--
William Bailey.
http://wb.pro-net.co.uk


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




[PHP] RSA Encryption with PHP (code attached)

2002-03-05 Thread William Bailey

Hi all,

I currently trying to get RSA encryption working in PHP and have
came up against a few issues that i hope somebody on here will be able to
help me with.

Basicly i have it mostly working and am able to generate keys OK
and i can also encrypt/decrypt data that will fit into one message 'block'
(their is currently no code to split a message up into blocks for
encryption). The problem i have it that sometimes the encryption dosent
seem to work correctly. I think that it is do to with me converting data
back and forth between different bases and am 'losing' information
somewhere along the line.

Well if anybody on this list knows a bit about encryption or if
you just want to help i would be very great full if you could look at the
attached code and comment on where my problem might be coming from.

I am making use of the gpm library so you will need that
installed before you are able to run my code.

Also please cc me directly on a any responses as they will get to
me quicker then by just emailing the list alone.

Regards,
William.

--
William Bailey.
http://wb.pro-net.co.uk


?php
/*
 * RSA Encryotion in PHP v0.1 :)
 *By William Bailey.
 *   [EMAIL PROTECTED]
 *
 * This code is still in its infancy so it will probably not work
 * correctly. If you make any bug fixes/improvements or just have
 * any random comments then please send them my way.
 *
 */
set_time_limit(300);

mt_srand((double)microtime()*1);

function generate_prime ($bits) {
$number=gmp_init('0');
for($i=$bits; $i=0; $i--){
$rand=mt_rand()%2;
gmp_setbit($number, $i, $rand);
}
while(gmp_prob_prime($number)1){
$number=gmp_add($number, 1);
}
if(strlen(gmp_strval($number, 2))!=$bits){
$number=generate_prime($bits);
}else{
//printf('preturning %s (%sbit)br', gmp_strval($number), 
strlen(gmp_strval($number, 2)));
return (string)gmp_strval($number);
}
}

function gen_RSA_keys ($bits=512, $e=17) {
/*
 * $bits us the length desired for $n
 *   ($p and $q will be half as long)
 * ($e, $n) is the public key
 * ($d, $n) id the provate key
 *
 * It seems that sometimes php forgets the resource id
 * for p and q therefore i have added the while(empty())
 * condition to this script so that if php forgets the
 * resource id it will just loop and try agian.
 *
 * This might be because im running the cvs version of
 * php. :)
 *
 * Hopefull this will be resolved soon and should make
 * this code fastar as it will not have to generate
 * waisted prime numbers.
 */
$e=gmp_init((string)$e);
$p=Null;
while(empty($p)){
do {
$p=gmp_init((string)generate_prime($bits/2));
$t=gmp_sub($p, 1);
} while (gmp_gcd($t, $e)==1);
}
//printf('p is %s and has a value if %s br', $p, gmp_strval($p));
//flush();
$q=Null;
while(empty($q)){
do {
$q=gmp_init((string)generate_prime($bits/2));
$t=gmp_sub($q, 1);
} while (gmp_gcd($t, $e)==1);
}
//printf('q is %s and has a value if %s br', $q, gmp_strval($q));
//flush();

$n=gmp_mul($p, $q);
//printf('n is %sbr', gmp_strval($n));

$t=gmp_add(gmp_sub(gmp_sub($n, $p), $q), 1);
//printf('t is %sbr', gmp_strval($t));

//printf('e is %sbr', gmp_strval($e));

$d=mod_inverse((string)gmp_strval($e), (string)gmp_strval($t));
//printf('d is %sbr', gmp_strval($d));
if(gmp_strval($d)=='1'){
/*
 * We dont want d to be 1 so if it is then we
 * generate another RSA key.
 */
return gen_RSA_keys ($bits, gmp_strval($e));
}else{
return(array((string)gmp_strval($n), (string)gmp_strval($e), 
(string)gmp_strval($d)));
}
}


function gen_RSA_keys2 ($bits=512) {
/*
 * $bits us the length desired for $n
 *   ($p and $q will be half as long)
 * ($e, $n) is the public key
 * ($d, $n) id the provate key
 *
 */
$p=Null;
while(empty($p)){
$p=gmp_init((string)generate_prime($bits/2));
}
$q=Null;
while(empty($q)){
$q=gmp_init((string)generate_prime($bits/2));
}
$n=gmp_mul($p, $q);
$t=gmp_add(gmp_sub(gmp_sub($n, $p), $q), 1);
$e=find_e($t, $q, $q);
$d=mod_inverse((string)gmp_strval($e), (string)gmp_strval($t));
if(gmp_strval($d)=='1'){
/*
 * We dont want d to be 1 so if it is then we
 * generate another RSA key.
 */
return gen_RSA_keys2 ($bits, gmp_strval($e));
}else{
return(array((string)gmp_strval($n), (string)gmp_strval($e), 
(string)gmp_strval($d)));
}
}

function find_e ($t, $p, $q) {
$great=gmp_init(0);
$e=gmp_init(2);
while (gmp_strval($great

[PHP] variable variables and eval

2001-08-13 Thread William Bailey

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi All,

i have come across a strange problem with variable variables. Basicly i'm
doing the following and its not working:

$section = 'data[SITE][0][NAME][0]';
$pData = 'My Site.';
${sprintf('$%s', $section)}.=$pData;

but it is not working. But if i do this:

eval('$'.$section.'.='.addslashes($pData).';');

it works and all is well. I don't really want to use eval() and just
wanted to see if anybody has any ideas why the above doesn't work.


Thanks,
William.


-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBO3foS639EoU2VrU1EQIPZgCcCg643+F0xDUXdsBSYAYInFStaJ0An2ID
AKL4hMIktbRsQpyVgkoeKsDo
=w0ei
-END PGP SIGNATURE-



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Seg fault when returning True from shutdown function.

2001-08-06 Thread William Bailey

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,
I am just playing with the the register_shutdown_function()
function and have found a way to cause php to seg fault. Can somebody else
please test the code below this to see if they have the same problem.

Code (8 Lines):

#!/usr/local/bin/php -q
?php
error_reporting(E_ALL);
function seg_fault(){
return True;
}
register_shutdown_function(seg_fault());
?

Thanks,
William.


-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBO258MK39EoU2VrU1EQLsuACgwA0egpooR3AeRBbZMwp0rqKyCIkAn00U
CDtlVoWinKYPAJgq+JjbEyh1
=FupR
-END PGP SIGNATURE-



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] UDP Port listening, can it be done?

2001-08-02 Thread William Bailey

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi All,

I'm currently just playing around with a few things and want to
write a script that will listen on a UDP port and then log/process the
information. The problem i have it that i don't know if php can do this. I
know that you can connect to a UDP port but can you listen on one? And if
you cant then does anybody know if this is planned in a future version?

Thanks,
William.

-BEGIN PGP SIGNATURE-
Version: PGPfreeware 5.0i for non-commercial use
Charset: noconv

iQA/AwUBO2lqeq39EoU2VrU1EQL9sQCffH2muCquVf0z7RxZXMICeJrQ1LIAnAnr
i/a5lvWWWHnwUozPHP+r8QP1
=Divy
-END PGP SIGNATURE-



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Help: 'php in free(): warning: recursive call'

2001-05-17 Thread William Bailey

Hi,

I just created a script that imports data from one data base,
reformats  it and then saves the data to csv files. Now when i run the
script it sometimes outputs the following error:

php in free(): warning: recursive call

I tried searching the php web site but have had no luck in finding out
what this means. So if anybody on this list knows then can you please tell
me.

Thanks,
William.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Variables in 'friendly' urls

2001-01-16 Thread William Bailey

Hi,
Is there a way to pass variables as 'friendly' urls? So instead of
haveing a url like www.blah.co.uk/profile.php?team=tigers i could have 
www.blah.co.uk/profile.php/team/tigers which would call profile.php and set
team to tigers.
I've been playing with it but i can't seem to get it to set the
variables. It will run the script (profile.php) but the variable $team if
still unset.

Thanks,
William.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] include include_once, how do they work?

2001-01-10 Thread William Bailey

I have just been playing around with include and include_once with one of
my classes, basicly there are a lot of functions inside this class so we
have put the contance of the function into its own file (so that different
people can work  on it) and are useing the include function to call it.

example:
...
function getCategorys ($id=0) {
return include($this-functionDirectory
."getCategorys.inc.php");   
}
function listItemsByCategory ($id,$start=0,$dynamic=FALSE) {
return include($this-functionDirectory
."listItemsByCategory.inc.php");
}
...

At one point I was useing include_once thinking that it would load the file
once and then keep it in memmory untill the script exited, but this dosen't
seem to be the case. What happens it that you call the function once and it
works fine but if you call it again it returns nothing so I have therefore
had to use include, which will load the file every time and it works.

Anyway to my question: Is there a way to keep code in different files and
have php load the file once and then keep the code in memmory once it has
been called?

Thanks,
William.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]