Re: [PHP] MySQL close connection, what's the purpose?

2006-04-03 Thread Jasper Bryant-Greene

tedd wrote:

chris said:

Just out of interest, could you re-run the test using persistent 
connections?


change mysql_connect to mysql_pconnect..



[snip]


Thanks -- does the persistent connection thing hold the server up 
until released? How does that work?


MySQL is threaded so will not be held up by any connection. Obviously 
the more connections the more of certain resources it will be using, but 
it doesn't block for every connection.


The exception, of course, being if you have something going on at the 
MySQL protocol level such as LOCK TABLES or a transaction. That will 
hold up certain other queries. But that's at a whole other layer.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] MySQL close connection, what's the purpose?

2006-04-01 Thread Jasper Bryant-Greene

tedd wrote:

I always close the connection right after my

   query -- force of habit. It's like leaving the
   toilet seat up, it's only going to get you into
   trouble.
 
  So you close it after every query and then re-open it later for the
  next query? I don't see that as a good idea.

  
  No, you leave it open until you're done with the database.

Reading Ted's post didn't give this impression. I wanted to make sure
he wasn't doing it that way.


Chris et al:

Actually I am. When I need something from the dB, I open it, get the 
information and close it. It's like opening a drawer, getting what you 
need, and then closing the drawer. Where's the problem?


Uh, what if you want to do more than one query in a single request? You 
aren't seriously suggesting you would connect and disconnect from the 
same database multiple times within the same request?


In my experience, connecting to the database takes up more than half of 
the execution time of the average database-driven PHP script (I said 
*average*, there are exceptions). You don't want to be doing it multiple 
times if you don't have to.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] MySQL close connection, what's the purpose?

2006-04-01 Thread Jasper Bryant-Greene

Robert Cummings wrote:

On Sat, 2006-04-01 at 20:15, tedd wrote:
It would be interesting to actually run a script that opens, 
retrieves, and inserts data -- let's say 50k times. What's the time 
difference between one open, 50k retrieves/inserts, and one close-- 
as compared 50k opens retrieve/insert closes?

[snip]

Everyone has their own way.


I'm not going to advocate either style since both have their merits
depending on where and what you are doing. My input is to advocate a
database wrapper layer such that the database connection semantics are
remove from general development. In this way you might have the
following:

[snip]

Yeah, e.g. I have a database objects layer that means I only write SQL 
in classes, everything else is just calling object methods. I create the 
database object at the start of every script but that doesn't 
necessarily open the database connection. The database connection is 
opened when I make my first query.


That way if a page does no queries (I use APC caching so it is fairly 
common for a page to do no queries) then no database connection is opened.


I never close connections; PHP does that for me and has never caused any 
problems doing that. I don't see it as sloppy programming, it is a 
documented feature that PHP closes resources such as database 
connections at the end of the script.


But, as has been said, each to their own.

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] MySQL close connection, what's the purpose?

2006-04-01 Thread Jasper Bryant-Greene

Robert Cummings wrote:

On Sat, 2006-04-01 at 20:48, Jasper Bryant-Greene wrote:
Yeah, e.g. I have a database objects layer that means I only write SQL 
in classes, everything else is just calling object methods. I create the 
database object at the start of every script but that doesn't 
necessarily open the database connection. The database connection is 
opened when I make my first query.


That way if a page does no queries (I use APC caching so it is fairly 
common for a page to do no queries) then no database connection is opened.


I never close connections; PHP does that for me and has never caused any 
problems doing that. I don't see it as sloppy programming, it is a 
documented feature that PHP closes resources such as database 
connections at the end of the script.


But, as has been said, each to their own.


There's smart lazy programming, and sloppy lazy programming. I don't
trust anything magical in PHP. Most of us are familiar with the magic
quotes and global vars fiascos *LOL*. But hey, if you can squeeze a
rewrite of an application out of a client for relying on dirty
techniques, who am I to critique your forward thinking manipulative
methods -- not to say that's your intent -- but I'd sure question your
motives and judgement if it comes around ;)


I very much doubt PHP will ever enforce the closing of resources such as 
database connections at the end of every script. That would be a 
needless BC break.


Also, I do it this way because some projects that use my framework want 
persistent connections. If my framework closed connections automatically 
then that wouldn't be possible.


Of course, it wouldn't exactly be a rewrite to make it close the 
connection at the end of every script before PHP did, if I'm proven 
wrong and it one day is necessary. I'd only need to change the database 
objects layer.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] MySQL close connection, what's the purpose?

2006-04-01 Thread Jasper Bryant-Greene

Robert Cummings wrote:

On Sat, 2006-04-01 at 21:39, Jasper Bryant-Greene wrote:

Robert Cummings wrote:


There's smart lazy programming, and sloppy lazy programming. I don't
trust anything magical in PHP. Most of us are familiar with the magic
quotes and global vars fiascos *LOL*. But hey, if you can squeeze a
rewrite of an application out of a client for relying on dirty
techniques, who am I to critique your forward thinking manipulative
methods -- not to say that's your intent -- but I'd sure question your
motives and judgement if it comes around ;)
I very much doubt PHP will ever enforce the closing of resources such as 
database connections at the end of every script. That would be a 
needless BC break.


I'm sure that was the thought on magic quotes and register globals also.


If PHP didn't close connections at the end of scripts we'd either have 
just about every script in the world throwing errors when they finished, 
or lots of memory leaks. Neither is particularly favourable, so I don't 
think it will happen any time soon...


Also, I do it this way because some projects that use my framework want 
persistent connections. If my framework closed connections automatically 
then that wouldn't be possible.


Your database layer should handle whether a connection is really freed.
Just because the developer calls the close() method on your DB object,
doesn't mean you need to close the connection. But if they don't call a
close() method, then in the future if you do need that functionality...
it's not there.

Of course, it wouldn't exactly be a rewrite to make it close the 
connection at the end of every script before PHP did, if I'm proven 
wrong and it one day is necessary. I'd only need to change the database 
objects layer.


Wrong, you would just be doing the same thing PHP does... closing the
connection at the end of the script. What happens if you need to open 20
connections to 20 different databases... are you going to keep them all
open? I guess you would since it sounds like you don't have a facility
to close them. I don't think what you're doing is incredibly obscene, I
mean 90% of PHP developers are doing the same thing. 90% of the coding
population can't be wrong... but one that same line of thought... when
you open an image file or text file for reading or writing... do you
close it? Or just leave it open for PHP to close at the end? I mean PHP
will magically close all resources for you, there's obviously no need to
close it... or maybe there are valid times when you need to close a
resource yourself, I dunno, I feel like I'm out on a limb here ;)


Yeah, I can see your point. Simple answer though: my framework isn't 
designed for connecting to 20 different databases :) It's designed for 
normal database-driven websites -- where there usually a maximum of two 
connections (master and slave), and often only one connection, open.


I guess I'm just gambling the time-saving benefits of not having to call 
$db-close() or whatever all the time, against the slim possibility that 
I might one day have to write a new framework to deal with apps that do 
20+ DB connections at once. The framework is fairly light anyway as it's 
built on top of PDO, so a rewrite is not a huge deal.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] MySQL close connection, what's the purpose?

2006-04-01 Thread Jasper Bryant-Greene

John Nichel wrote:

Jasper Bryant-Greene wrote:
snip
I never close connections; PHP does that for me and has never caused 
any problems doing that. I don't see it as sloppy programming, it is a 
documented feature that PHP closes resources such as database 
connections at the end of the script.




It's extremely sloppy programming.  You're assuming that a) PHP will 
continue to be a forgiving language when it comes to items like this and 
b) your script is going to exit normally.  The reason this is a 
'documented feature' is because PHP is trying to make up for sloppy 
programming.  You shouldn't rely on the language to clean up your toys 
for you.


If the script exits abnormally the connection is still closed. Test it.

I'm happy to gamble on a) as because I have said in earlier posts I am 
very confident this behaviour will not change in the forseeable future.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Overloading Limitation- Can Someone Confirm?

2006-03-31 Thread Jasper Bryant-Greene

Jim Lucas wrote:

Jasper Bryant-Greene wrote:

Jochem Maas wrote:

[snip]

you guess wrong :-)  .. I couldn't resist testing it:

php -r '
class T { private $var = array();
function __set($k, $v) { $this-var[$k] = $v; }
function __get($k) { var_dump($k); }
}
$t = new T;
$t-arr = array();
$t-arr[a] = 1;
echo OUTPUT: \n; var_dump($t-arr); var_dump($t-arr[a]); 
var_dump($t);

'




[snip]

Code:

?php

class T {

private $array = array();

public function __get( $key ) {
return $this-array[$key];
}

public function __set( $key, $value ) {
$this-array[$key] = $value;
}

}

$t = new T;

$t-insideArray = array();
$t-insideArray['test'] = 'testing!';

var_dump( $t );

?

Output:

object(T)#1 (1) {
  [array:private]=
  array(1) {
[insideArray]=
array(1) {
  [test]=
  string(8) testing!
}
  }
}

Dont know if you guys see the MAJOR difference between your code, so I 
will point it out.


Jasper did this

function __get($k) {
   var_dump($k);
}


Uhm, no I didn't. Jochem did :)


Jochem did this

public function __get( $key ) {
  return $this-array[$key];
}


No, I did that.

First off, the required public before the function call was not 
included, secondly, Jasper is var_dumping the key of the array, not the 
array it self.


Public is not required. I always put it regardless, but if you leave it 
off then PHP defaults to public for compatibility reasons.


Jochem's code, which behaves incorrectly, does var_dump. Mine just 
returns the array key as you would expect. That's why Jochem's doesn't 
behave correctly with arrays.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] preg_match

2006-03-31 Thread Jasper Bryant-Greene

Benjamin D Adams wrote:

I'm trying to check a string for ../
?php
if(preg_match(/..//i, $string)){
echo string has ../;
}
?

Can't get it to work can anyone help?


That's terrible overkill. Regex is not designed for simple substring 
matching. You want:


if( strpos( $string, '../' ) !== false )
echo 'string has ../';

By the way, your problem is that . is a special character in regular 
expressions, so needs escaping with a backslash, and you have used / as 
your delimiter but also use it inside the pattern. You should use a 
different delimiter (also, there's no point in using the 'i' 
case-insensitive flag, since there's no characters in your pattern).


The strpos() solution above is much better and faster in this case, though.

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Outputting text ? how to?

2006-03-30 Thread Jasper Bryant-Greene

Merlin wrote:

Hi there,

I would like to output following text with php:
?xml version=1.0 encoding=ISO-8859-1 ?

How can I do that? I tried to escape the ? with \? but this did
not help.


Either:

1. Turn off short tags (good idea if you plan on distributing your code).

2. Just echo or print that text. Like:

?php
echo '?xml version=1.0 encoding=ISO-8859-1?' . \n;
?

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] PHP4: calling method on returned object

2006-03-30 Thread Jasper Bryant-Greene

Karl Glennon wrote:
[snip]
I expected to have the ability to get the url of a location's map with 
the floowing statement:


print $this-Location-GetMap()-GetUrl();

[snip]
Is there any other syntax in PHP4 to allow me to concisely call a method 
on a return object? eg. ($this-Location-GetMap())-GetUrl() .. which 
doens't work.


In short, no. That syntax was introduced in PHP5. For OO work, I would 
strongly recommend upgrading to PHP5 as there are many other important 
OO features that simply are not available in PHP4.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Overloading Limitation- Can Someone Confirm?

2006-03-30 Thread Jasper Bryant-Greene

Chris wrote:

class testClass
{
public $vars = array();

public function __get($key)
{
return array_key_exists($key, $this-vars) ? $this-vars[$key] : 
null;

}

public function __set($key, $value)
{
$this-vars[$key] = $value;
}

public function __isset($key)
{
return array_key_exists($key, $this-vars);
}

public function __unset($key)
{
unset($this-vars[$key]);
}
}


$tc = new testClass();

$tc-arr = array();


here you store an empty array in the $vars member array, under the key 
'arr' (due to your magic methods). is that what you intended?



$tc-arr['a'] = 'A';
$tc-arr['b'] = 'B';


now you are adding elements to this array under the 'arr' key in the 
$vars member array.



if (isset($tc-arr['b'])) {
unset($tc-arr['b']);
}


you just removed b from the array under 'arr' in the $vars member array.


//var_dump is only to see results of above
var_dump($tc);


this should show something equiv. to:

array(
'arr'   = array(
'a' = 'A'
)
)

what does it actually show?

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Overloading Limitation- Can Someone Confirm?

2006-03-30 Thread Jasper Bryant-Greene

Jochem Maas wrote:
I think its a misunderstanding on the one side and a limitation on the 
other,

you can't use overloading directly on items of an overloaded array e.g:

echo $tc-arr['a']

this is triggers a call to __get() with the $key parameter set to 
something like

(I'm guessing) arr['a']


No, I'm pretty sure (too lazy and tired right now to test...) that if 
things work as they should, it will look up __get() with the key 
parameter set to 'arr', and treat the return value of that as an array, 
looking for the 'a' key inside that array. Or at least it should, dammit.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Overloading Limitation- Can Someone Confirm?

2006-03-30 Thread Jasper Bryant-Greene

Jochem Maas wrote:

Jasper Bryant-Greene wrote:

Jochem Maas wrote:

I think its a misunderstanding on the one side and a limitation on 
the other,

you can't use overloading directly on items of an overloaded array e.g:

echo $tc-arr['a']

this is triggers a call to __get() with the $key parameter set to 
something like

(I'm guessing) arr['a']



No, I'm pretty sure (too lazy and tired right now to test...) that if 


you guess wrong :-)  .. I couldn't resist testing it:

php -r '
class T { private $var = array();
function __set($k, $v) { $this-var[$k] = $v; }
function __get($k) { var_dump($k); }
}
$t = new T;
$t-arr = array();
$t-arr[a] = 1;
echo OUTPUT: \n; var_dump($t-arr); var_dump($t-arr[a]); var_dump($t);
'



That's weird, because I did get around to testing it before I saw your 
mail, and in my test it works as *I* expect (PHP 5.1.2)...


My comments earlier were based on the fact that it would not be good to 
limit what can be put in an object through __get and __set effectively 
to scalar variables, and I would expect the engine developers to realise 
that. I think they have (unless I've done something stupid in my test 
code...):


Code:

?php

class T {

private $array = array();

public function __get( $key ) {
return $this-array[$key];
}

public function __set( $key, $value ) {
$this-array[$key] = $value;
}

}

$t = new T;

$t-insideArray = array();
$t-insideArray['test'] = 'testing!';

var_dump( $t );

?

Output:

object(T)#1 (1) {
  [array:private]=
  array(1) {
[insideArray]=
array(1) {
  [test]=
  string(8) testing!
}
  }
}

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Outputting text ? how to?

2006-03-30 Thread Jasper Bryant-Greene

tedd wrote:

Merlin:

First the syntax should be:

?xml version=1.0 encoding=ISO-8859-1 ?/  -- note the close /


No, that is invalid XML. The specification is available at 
http://www.w3.org/TR/XML11 (and makes riveting reading! ;)


[snip]

If you want to print it to a web page, try:

?php
$a=EOD
lt;?xml version=1.0 encoding=ISO-8859-1 ?/
EOD;
echo($a);


echo 'lt;?xml version=1.0 encoding=ISO-8859-1 ?';

would work just as well and is a hell of a lot easier to look at. That's 
assuming you actually want it to appear on the page for the user to see, 
if you want the browser to interpret it you'll have to change the lt; 
at the start to a 


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] HTTP status code

2006-03-30 Thread Jasper Bryant-Greene
In other words, if you want Firefox/Opera/etc to display something, you 
have to output something. Strange, that. :P


Jasper

Anthony Ettinger wrote:

Then it's workingFireFox, et. al. show you the server 404, IE on
the otherhand has it's own 404 error page (for those newbies who don't
know what a 404 is). You can disable it under IE options.

On 3/30/06, Bronislav Klucka [EMAIL PROTECTED] wrote:

Yes, I do...
B.

Anthony Ettinger wrote:

Are you seeing the IE-specific 404 page? The one that looks like this:

http://redvip.homelinux.net/varios/404-ie.jpg



On 3/30/06, Bronislav Klucka [EMAIL PROTECTED] wrote:


Hi,
I'm using following construction to send http status code
--
header('HTTP/1.1 404 Not Found');
header(Status: 404 Not Found);
exit;
--

MSIE displays Page not found, but FireFox and Opera don't display
anything. Just blank page with no text...

full headers sent by this script (and server itself) are:

--
Date: Thu, 30 Mar 2006 18:02:49 GMT
Server: Apache/2.0.55 (Debian) PHP/4.4.0-4 mod_ssl/2.0.55 OpenSSL/0.9.8a
X-Powered-By: PHP/5.1.2
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

404 Not Found
--

can anyone tell me, why those two browsers are not affected?

Brona

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






--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html


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






--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html



--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] HTTP status code

2006-03-30 Thread Jasper Bryant-Greene
The default Apache error handler is not called when PHP sends a 404 
header. The code that does Apache error handling happens *before* PHP 
gets in the loop, and checks to see if the script being referenced 
exists, which it indeed does, whether it sends a 404 header or not.


Tested on Apache 2.2 with PHP 5.1.

If you really want to get the default Apache error handler to appear 
then either readfile() it or redirect to it.


Jasper

Anthony Ettinger wrote:

well, you typically would redirect 404 to something like foo.com/404.html

Otherwise, it's whatever your server (apache/IIS) has as the default
404 handler...

Default is something like this:

  Not Found

  The requested URL /asdf was not found on this server.
  Apache Server at foo.org Port 80


On 3/30/06, Jasper Bryant-Greene [EMAIL PROTECTED] wrote:

In other words, if you want Firefox/Opera/etc to display something, you
have to output something. Strange, that. :P

Jasper

Anthony Ettinger wrote:

Then it's workingFireFox, et. al. show you the server 404, IE on
the otherhand has it's own 404 error page (for those newbies who don't
know what a 404 is). You can disable it under IE options.

On 3/30/06, Bronislav Klucka [EMAIL PROTECTED] wrote:

Yes, I do...
B.

Anthony Ettinger wrote:

Are you seeing the IE-specific 404 page? The one that looks like this:

http://redvip.homelinux.net/varios/404-ie.jpg



On 3/30/06, Bronislav Klucka [EMAIL PROTECTED] wrote:


Hi,
I'm using following construction to send http status code
--
header('HTTP/1.1 404 Not Found');
header(Status: 404 Not Found);
exit;
--

MSIE displays Page not found, but FireFox and Opera don't display
anything. Just blank page with no text...

full headers sent by this script (and server itself) are:

--
Date: Thu, 30 Mar 2006 18:02:49 GMT
Server: Apache/2.0.55 (Debian) PHP/4.4.0-4 mod_ssl/2.0.55 OpenSSL/0.9.8a
X-Powered-By: PHP/5.1.2
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

404 Not Found
--

can anyone tell me, why those two browsers are not affected?

Brona

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





--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html


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





--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334





--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html



--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Visa / MasterCard security compliance

2006-03-30 Thread Jasper Bryant-Greene

Dan Harrington wrote:

One of these requirements is cardholder data encryption -- is anyone aware
of a 
PHP/MySQL/Linux/Apache solution for end-to-end cardholder data encryption

that satisfies the Visa / MasterCard requirements?


Apache supports SSL/TLS. Therefore the credit card data can be encrypted 
in transit to you (you'll probably need to shell out for an SSL cert).


Your credit-card processing gateway will provide SSL/TLS encryption for 
your connection to them (be it via SOAP, REST, whatever).


If you really have to store the data for any reason, PHP's mcrypt 
extension allows you to encrypt it before storing it in the database. 
But avoid storing it if you can.


There you have it, end-to-end data encryption. That's basically the way 
I do it (I don't store card information so only the first two paragraphs 
apply), and I satisfy Visa and Mastercard's requirements. :)


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] Database connections

2006-03-30 Thread Jasper Bryant-Greene

Chris wrote:
If they're accessing the same database you don't need to 
disconnect/reconnect. Different db's - well, yeh you don't have a choice.


Of course you do. mysql_select_db() or whatever it's called. Or just 
issue a USE [databasename] query. No need to reconnect!


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] setting the same value to multiple variables

2006-03-30 Thread Jasper Bryant-Greene

charles stuart wrote:

if ( 1 == 1 )


^^ what is the point of this?


{
$goodToGo = 0; $errorArray[] = You must declare some goals on 
Activity 1.;


// this block of code does not set each variable to class=\errorHere\;

$readingGoalsEnjoymentLabelClass
$readingGoalsInformationLabelClass 
$readingGoalsAlphabeticLabelClass
$readingGoalsPrintLabelClass
$readingGoalsPhonologicalLabelClass 
$readingGoalsPhoneticLabelClass
$readingGoalsComprehensionLabelClass 
$readingGoalsVocabularyLabelClass
$readingGoalsInstructionsLabelClass 
$readingGoalsCriticalLabelClass
$readingGoalsCommunicateLabelClass = class=\errorHere\;

}


While this seems like excessively ugly code (have you considered an 
array? what is the point of all those variables if they all hold the 
same value?), replace all of those '' with '=' and you will be fine. 
PHP evaluates right-to-left and the result of an assignment is the value 
that was assigned, so that will work.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

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



Re: [PHP] addslashes()

2006-03-29 Thread Jasper Bryant-Greene

From http://php.net/addslashes :

Having the PHP directive  magic_quotes_sybase set to on will mean ' is 
instead escaped with another '.


Jasper

Chris Boget wrote:

Can someone explain something to me:

script language=php
 $string = Bob's carwash's door;
 echo 'addslashes(): ' . addslashes( $string ) . 'br';
 echo 'mysql_escape_string(): ' . mysql_escape_string( $string ) . 'br';
/script

Outputs:

addslashes(): Bob''s carwash''s door
mysql_escape_string(): Bob\'s carwash\'s door

According to the documentation 
(http://us2.php.net/manual/en/function.addslashes.php), addslashes() 
should be doing exactly what mysql_escape_string is doing above (namely, 
add backslashes in front of each apostrophe).  However, it's merely 
adding an additional apostrophe.  Why?


I'm running 4.3.11 on Windows NT 5.2 build 3790.

thnx,
Chris


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



Re: [PHP] parent constructor

2006-03-29 Thread Jasper Bryant-Greene

SLaVKa wrote:
Hey guys just a general question... if you have a 
parent::__constructor() call in your constructor function, should that 
call ideally be placed before or after the code inside the current 
constructor? or it doesnt really matter


That depends on which code you want to run first. Seriously.

Jasper

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



Re: [PHP] private $foo

2006-03-28 Thread Jasper Bryant-Greene

Anthony Ettinger wrote:


private $foo; cannot be accessed directly outside the script.

print $f-foo; #fails

Fatal error: Cannot access private property Foo::$foo in
/x/home/username/docs/misc/php/client.php on line 11


Did you define the __get and __set functions in your class as in the 
previous post? Are you running a version of PHP that supports them?


Jasper

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



Re: [PHP] mysql query/$post problem

2006-03-27 Thread Jasper Bryant-Greene

PHP Mailer wrote:

Mark skrev:

[snip]

$query = INSERT INTO users AVATARS WHERE id =$user_id '','$avname');
mysql_query($query);s

[snip]
I am trying to insert the value of $avname into the users table, into 
the avatar field.


I think what you are trying to do is coordinated a bit wrong, perhaps 
http://www.w3schools.com/sql/sql_insert.asp

could be of some help for you to achieve this in the future.

Taking a look at your query, i do see what you are trying to do, but the 
structure is wrong.


$query = INSERT INTO users (avatars) VALUES ('$avname')WHERE id 
='$user_id');




Also - it looks like an UPDATE might be more suitable for what you want, 
given that you've got a WHERE clause tacked on the end. Google for a 
good SQL tutorial; the PHP mailing list is not the place to learn SQL :)


Jasper

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



Re: [PHP] $i vs. $r

2006-03-27 Thread Jasper Bryant-Greene

Kevin Murphy wrote:

Does anyone have a clue why using this code doesn't work:


Please specify what doesn't work means in this case :)


$i = 0;

while ($row = mysql_fetch_array($result))

{   
echo (Blah blah blah);

$i++;
}




$r = 0;

while ($row = mysql_fetch_array($result))

{   
echo (Blah blah blah);

$r++;
}


Those two blocks of code are for all intents and purposes identical, and 
indeed probably end up as exactly the same opcodes.


Jasper

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



Re: [PHP] unset a constant

2006-03-27 Thread Jasper Bryant-Greene
There is no way using the core language. You can, however, use the 
runkit function if you absolutely have to:


http://php.net/runkit_constant_remove

Jasper

Suhas wrote:

Hi,

How do I unset a defined variable.

e.g.

define('AA',1);

unset(AA) // gives error

any suggestions!

Thanks
SP



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



Re: [PHP] security risk by using remote files with include(); ?

2006-03-24 Thread Jasper Bryant-Greene

Merlin wrote:

I am wondering if I am opening a potential security risk by
including files on remote servers. I am doing an include 
('http:/www.server.com/file.html') inside a php script of mine
to seperate content from function. Content is produced by a friend of 
mine and

I do not want to grant access to my server to him.


Yes, your friend (or anyone who compromises his server, who may very 
well *not* be friendly :) can output any PHP code he likes from that 
URL, and your server will execute it.


Not Good(tm).

You could do:

| echo file_get_contents( 'http://www.server.com/file.html' );

but only if you really trust his server to never get compromised, as 
that would allow an attacker to replace content on your website with 
anything they liked.


Jasper

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



Re: [PHP] Switching to UTF-8. Need help.

2006-03-24 Thread Jasper Bryant-Greene

Is the file saved in UTF-8 encoding (the PHP script itself)?

Jasper

Andy wrote:

This is my code:
?php
   $str = öüééééÉooOO;
   echo $str;
   echo br;
   echo utf8_encode ($str);
?


öüééééÉõõÕÕ

I tried all the ways:
meta http-equiv=content-type content=text/html; charset=UTF-8
and
?php header('Content-Type: text/html;charset=UTF-8');?
etc.

The first echo... is not showed correctly.
The second (with the encoding function) works well.
In php.ini the default encoding is UFT-8. The webserver sends the correct
encoding.

By default the browser(tested on IE and firefox) sees as UFT-8 encoding for
the page. If I output the string with utf8_encode function than it wroks
well. But... it this the solution??? I don't want to modify the whole
project.

Best regards,
Andy.
- Original Message - From: Richard Lynch [EMAIL PROTECTED]
To: Andy [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Friday, March 24, 2006 2:14 AM
Subject: Re: [PHP] Switching to UTF-8. Need help.



Check the HEADERS your web-server is sending.

If they don't have Charset UTF-8 in there, it won't work on REAL
browsers (Mozilla based)

Then, for reasons known only to Microsoft, you have to use a META tag
to define the Charset for IE.

MS will *ignore* the headers in favor of a heuristic whereby they
count the number of characters in any given document which do/don't
fit into various common charsets, and then they choose the charset
based on that.

Apparently, MS assumes that web-designers who can only handle META
tags are smarter than developers who use header() function.  Go
figure. :-^



On Thu, March 23, 2006 10:13 am, Andy wrote:

Hi to all,

We are developing a multilanguage application, and slowly it seems
that the Latin1(ISO 5589 1) encoding is not enough.
I tried simply to convert the database and the encoding of the php to
UTF-8, but I'm getting some problems.

If I make an echo 'möbel, Belgien' the browser does not show me the
correct character. If I look in the source of the document the
character is good. Default encoding of the browser is UTF-8. If I
change manually the browser encoding then the chars are showed
correclty.

We have a lot of defines with fix texts, which are full with german
and french characters. Any of these aren't shower correctly.

What is the workaround for this?

Best regards,
Andy.



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








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



Re: [PHP] Switching to UTF-8. Need help.

2006-03-24 Thread Jasper Bryant-Greene

If you're on *nix:

man iconv

otherwise, I have no idea, sorry.

Jasper


Andy wrote:

No it was not. If I save it with UFT8 encoding it works well.
So, do I have to convert all the files to UTF8 encoding?
Is there an easy way to do that?

- Original Message - From: Jasper Bryant-Greene 
[EMAIL PROTECTED]

To: Andy [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Friday, March 24, 2006 11:18 AM
Subject: Re: [PHP] Switching to UTF-8. Need help.



Is the file saved in UTF-8 encoding (the PHP script itself)?

Jasper

Andy wrote:

This is my code:
?php
   $str = öüééééÉooOO;
   echo $str;
   echo br;
   echo utf8_encode ($str);
?


öüééééÉõõÕÕ

I tried all the ways:
meta http-equiv=content-type content=text/html; charset=UTF-8
and
?php header('Content-Type: text/html;charset=UTF-8');?
etc.

The first echo... is not showed correctly.
The second (with the encoding function) works well.
In php.ini the default encoding is UFT-8. The webserver sends the 
correct

encoding.

By default the browser(tested on IE and firefox) sees as UFT-8 
encoding for

the page. If I output the string with utf8_encode function than it wroks
well. But... it this the solution??? I don't want to modify the whole
project.

Best regards,
Andy.
- Original Message - From: Richard Lynch [EMAIL PROTECTED]
To: Andy [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Friday, March 24, 2006 2:14 AM
Subject: Re: [PHP] Switching to UTF-8. Need help.



Check the HEADERS your web-server is sending.

If they don't have Charset UTF-8 in there, it won't work on REAL
browsers (Mozilla based)

Then, for reasons known only to Microsoft, you have to use a META tag
to define the Charset for IE.

MS will *ignore* the headers in favor of a heuristic whereby they
count the number of characters in any given document which do/don't
fit into various common charsets, and then they choose the charset
based on that.

Apparently, MS assumes that web-designers who can only handle META
tags are smarter than developers who use header() function.  Go
figure. :-^



On Thu, March 23, 2006 10:13 am, Andy wrote:

Hi to all,

We are developing a multilanguage application, and slowly it seems
that the Latin1(ISO 5589 1) encoding is not enough.
I tried simply to convert the database and the encoding of the php to
UTF-8, but I'm getting some problems.

If I make an echo 'möbel, Belgien' the browser does not show me the
correct character. If I look in the source of the document the
character is good. Default encoding of the browser is UTF-8. If I
change manually the browser encoding then the chars are showed
correclty.

We have a lot of defines with fix texts, which are full with german
and french characters. Any of these aren't shower correctly.

What is the workaround for this?

Best regards,
Andy.



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













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



[PHP] Execute a program from PHP CLI and allow user interaction

2005-11-22 Thread Jasper Bryant-Greene

Hi all

This one's got me stumped. I'm working on a PHP CLI interface, and I 
need to allow the user to input a bit of HTML.


Rather than bandy around with readline() and the like, I thought it 
would be nice to just create a temporary file, pop nano up, and read and 
then delete the file once it's been edited. That way I get nano's syntax 
highlighting and other useful features.


However, I can't for the life of me figure out how to allow the user to 
interact with nano once the process has been launched. The usual culprits:


{exec,system,shell_exec}( nano tmpfile.txt );

all just hang (top shows nano is running, but it doesn't seem to be 
attached to the terminal).


How can I launch a process and attach it to the terminal PHP CLI was 
launched from so that the user can interact with it?


TIA
--
Jasper Bryant-Greene
General Manager
Album Limited

+64 21 708 334
[EMAIL PROTECTED]

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



Re: AW: [PHP] how can I CALL a PHP script from different TEXT LINKS with differentPARAMETERS?

2005-11-19 Thread Jasper Bryant-Greene

xkorakidis wrote:

Webmaster, thanks very much but I think it would be safer to do that by
post, not by get. Furthermore, if I use indivudual files


It is a fallacy to ever tell someone that POST is safer than GET. They 
both transmit data in plaintext and it should not be assumed that either 
is inherently safer than the other, as this simply gives others a false 
sense of security.


The difference between POST and GET lies in the semantics -- POST 
represents something changing on the server, e.g. updating a database 
field, and allows the browser to warn the user if they try to refresh. 
GET represents nothing of importance changing on the server, e.g. 
performing a search on the database, and can safely be repeated.


SSL/TLS is the best option if you wish to transmit sensitive data.

--
Jasper Bryant-Greene
General Manager
Album Limited

+64 21 708 334
[EMAIL PROTECTED]

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



Re: [PHP] Re: Variables in Variables?

2005-11-18 Thread Jasper Bryant-Greene

Ben wrote:
If I understand your question properly I'd explode $two_vars with 
whatever seperator you have between them and then you'll need to use 
eval to get your results.  Maybe something like...


$dbVars=explode(',',$two_vars); // Assuming comma seperator
foreach($dbVars AS $key = $value) {
$eval=\$temp=.$value.;;
eval($eval);
echo $temp;
}


WTF do you need eval() for?!

$dbVars = explode( ',', $two_vars );
foreach( $dbVars as $value ) {
echo $value;
}

... does exactly the same thing.

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



Re: [PHP] Re: Variables in Variables?

2005-11-18 Thread Jasper Bryant-Greene

Jasper Bryant-Greene wrote:

Ben wrote:


$dbVars=explode(',',$two_vars); // Assuming comma seperator
foreach($dbVars AS $key = $value) {
$eval=\$temp=.$value.;;
eval($eval);
echo $temp;
}


WTF do you need eval() for?!

$dbVars = explode( ',', $two_vars );
foreach( $dbVars as $value ) {
echo $value;
}


Ah, sorry, I see what I missed now... Still, I'm sure there's a way to 
do this without resorting to eval()...


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



Re: [PHP] Re: [PHP-DB] Drag and Drop with PHP and MySQL

2005-11-18 Thread Jasper Bryant-Greene

Joe Harman wrote:

Hi Chris,
 I would think that there has to be something out there like a Javascript
that would accomplish that... that would be my first guess anyhow... there
possibly could be something done in flash that would act as a drop area for
the file... let us know what you find
 Joe


There's no way the browser is going to let JS have access to the user's 
filesystem. I would expect ditto for Flash, although I don't use it.


Jasper




 On 11/18/05, Micah Stevens [EMAIL PROTECTED] wrote:


No. That would be nice though eh?

What I have done in the past is when a user needs to upload a file, I give
them a linked button that links to a ftp:// style address. This ftp
account
points to a directory that PHP can have access to.

The user then drags and drops (IE only) the files on this new window,
which
uploads the files to this directory.

Once they're done, they close the window, and hit a second button 'Click
here
when finished uploading' which tells php to grab all the files in the
upload
directory and put them where they need to go.

This is far from ideal, causes miserable problems when more than one
person is
using the technique at once, and offers a host of security and usability
issues. Oh, and it's IE only, Firefox can't do this, and I don't think
opera/safari can either.

However, it's much better than uploading a ton of files individually using
a
form. I only use this for applications where I can be sure that only one
user
will use it at once, and they're trusted.

In a pinch it works though. I don't care so much about drag and drop, I
was
just trying to solve the multi-file upload issue. I wish there was a
better
way.

If I'm stupid and there is, I'd love to hear about it.

-Micah

On Friday 18 November 2005 5:42 pm, Chris Payne wrote:

HI there everyone,



I have a file upload system where you select via requester the file to
upload, it then uploads it with PHP and stores the info in a MySQL
database. Is there an interface / programming method I can use which I

can

DRAG a file from the desktop into an area in a form just as if I had

used a

file requester to select a file? Learning a new programming technique is
no problem as long as it can be used with PHP and MYSQL.



Any helps / pointers would be REALLY welcome.



Chris

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





--
Joe Harman
-
Do not go where the path may lead, go instead where there is no path and
leave a trail. - Ralph Waldo Emerson



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



Re: [PHP] shell command

2005-11-18 Thread Jasper Bryant-Greene

John Taylor-Johnston wrote:

Hi,
I want to echo the location of head.jpg hidden in some deep dark 
recess of my server, unbeknownst to me.

Which shell command do I use? How do I echo it?
John



While this isn't really a PHP question...

On my machine, the following would work. I can't speak for your machine, 
though.


cd /; find -name head.jpg

--
Jasper Bryant-Greene
General Manager
Album Limited

+64 21 708 334
[EMAIL PROTECTED]

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



Re: [PHP] Re: php error message

2005-11-17 Thread Jasper Bryant-Greene

Chuck Anderson wrote:

Ben wrote:


Edward Martin said the following on 11/17/2005 04:27 PM:


Warning: Cannot modify header information - headers already sent by
(output started at
/usr/home/ecmartin/public_html/ethics06/calendarlogin.php:8) in
/usr/home/ecmartin/public_html/ethics06/sas.php on line 34
  


It means you are trying to change the page's headers after they have 
already been sent to the user's browser. You are probably trying to 
use the header() function after HTML/Javascript/what have you has 
already been sent to the browser.  If you need to use header() you 
should write any earlier output to a variable and only output it to 
the browser after any header() function use.


- Ben
 
Most likely that is exactly what's happening. To be even more clear - 
the solution is to use the header function before any HTML (before *any* 
output). I learned this when I had an include file that was all Php 
causing this problem. The end of the included file had a carriage return 
after the closing tag ?. That was a nasty one to locate. Now I always 
make sure there is no white space after the closing tag in files I might 
include somewhere else.


An alternative solution is to just turn on output buffering, which will 
make sure no output gets sent until after all PHP has stopped processing 
(unless you specifically tell it to get sent earlier).


Jasper

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



Re: [PHP] Virtual Directory Support

2005-11-15 Thread Jasper Bryant-Greene

Jay Blanchard wrote:

[snip]
I think I may be headed down the wring direction.
I'm using Apache.
What I'd like to be able to do is to
pass arguments to a script as though it were a directory.

Something like so
http://server.com/script.php/some-virtual/dirs/
[/snip]

http://us2.php.net/dir

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html



Ah, both those links are useless for what he wants to do.

Brad, Make a script called script.php containing the following line:

pre?php print_r( $_SERVER['PATH_INFO'] ); ?/pre

And then access http://yourserver.com/script.php/some/path/info and 
you'll see how you can use that string (hint: explode on '/').


Jasper

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



Re: [PHP] Virtual Directory Support

2005-11-15 Thread Jasper Bryant-Greene

Brad Glonka wrote:

The script does not give me any output.
I think this is what I need to enable.


No, as has already been said on the list. That virtual directory 
setting has nothing to do with this AFAIK.


Are you running PHP as an Apache module or as CGI?

Jasper

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



Re: [PHP] random row

2005-11-15 Thread Jasper Bryant-Greene

John Taylor-Johnston wrote:
My question is simnple. I want to randomly select a row in a mysql 
table. I have a primary id.


?php
$server = localhost;
$user = foo;
$pass = foo;
$db=foo_db;
$table=foo_table;
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$sql = ??;

$news = mysql_query($sql) or die(print font 
color=red.mysql_error()./font);

   while ($mydata = mysql_fetch_object($news))
   {
??
   }
?



If your table isn't too big, it's fine to do:

SELECT * FROM mytable ORDER BY RAND() LIMIT 1

If you've got more than a few 10,000s of rows, you might want to look at 
other ways, like selecting a random row based on the primary key by 
generating a random number in PHP before executing the SQL.


Jasper

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



Re: [PHP] [EMAIL PROTECTED]

2005-11-14 Thread Jasper Bryant-Greene

Miles Thompson wrote:

Can someone get rid of him?
Every time I post, which I admit is not often, I get a bounce.


Yeah, same. I think there was some discussion recently regarding it but 
I don't know what happened.


I even tried to go to www.xasamail.com and register an account ale0952 
just to stop the bounces, but it appears there is no way to sign up on 
that webmail site.


Jasper

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



Re: [PHP] Re: emailing MySQL list not working

2005-11-14 Thread Jasper Bryant-Greene

Bruce Gilbert wrote:

Sorry for the newbie question...

I did a search on php.net but didn't find my answer.

what does \r\n do as opposed to just \n?

and yes, I know what  \n does.


Different platforms have different line-break conventions. \n is a line 
feed, while \r is a carriage return (these names date from typewriters, 
I believe!)


I think that \r\n is the standard way to separate header fields in HTTP 
and SMTP, but maybe it's just the most interoperable way. Everyone I 
know does it, so I'm just being a sheep...


Jasper

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



Re: [PHP] Printing to a buffer

2005-11-13 Thread Jasper Bryant-Greene

Todd Cary wrote:

Marcus -

Many thanks!  I did not know that MIME-Type.  Change duly made!


You're not suggesting that you actually set the MIME-Type to 
application/force-download, are you?





Todd

Marcus Bointon wrote:


On 13 Nov 2005, at 00:17, Jasper Bryant-Greene wrote:

seem to do that.  I just tried application/text since I use  
application/pdf for other applications.



Whatever it's giving the user the ability to do, it's probably  
because the browser doesn't recognise the (invalid) MIME-Type.



Quite - it's right up there with 'application/force-download'. If you  
want to suggest (the final choice is not yours to make) that a  
browser might download something instead of displaying it, set an  
appropriate content-disposition header instead of setting the wrong  
type.


Marcus




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



Re: [PHP] please shed some light on SQLsyntax error

2005-11-13 Thread Jasper Bryant-Greene

Bruce Gilbert wrote:

I am trying to set up a contact list database using guidance from a
PHP/MySQL book I recenty purchased, and not aving done this before I
am not sure what the following error means or where I shoudl look for
this kind of error. I have a table set up in MySQL using PHPMyadmin,
and I am thinking it may be something in my table? Please let me know
if anyone lese is familiar of this type of error below:

You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'List values ('', 'firstname', 'lastname', 'address', '


You would need to show us the SQL that was causing that error. Otherwise 
it is fairly meaningless.


Jasper

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



[PHP] Re: please shed some light on SQLsyntax error

2005-11-13 Thread Jasper Bryant-Greene

Bruce Gilbert wrote:

You would need to show us the SQL that was causing that error. Otherwise
it is fairly meaningless.


hope this helps...

?

//check for required form variables
if ((!$_POST[f_name]) || (!$_POST[l_name])) {


Unrelated, but you should have quotes here. Like $_POST['f_name']



header(Location:http://www.inspired-evolution.com/show_addcontact.php;);


There should also probably be a space between the : and the start of the 
 URL here.



exit;
}else {
//if form variables are present,start a session
session_start();
}

//check for validity of user
if ($_SESSION[valid] != yes) {


Again, quotes on the array subscript.


header(Location:http://www.inspired-evolution.com/contact_menu.php;);


And space between colon and URL here.


exit;
}

//set up table and database names
$db_name =bruceg_contactlist;
$table_name =Contact List;

//connect to server and select database
$connection = @mysql_connect(69.90.6.198,database_username,password)
or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

//build and issue query
$sql = INSERT INTO $table_name values ('', '$_POST[f_name]',


You'll be wanting to put backticks (`) around the table name, because it 
contains a space.


Jasper

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



[PHP] Re: please shed some light on SQLsyntax error

2005-11-13 Thread Jasper Bryant-Greene

Bruce Gilbert wrote:

for the table name you mean like this?

$table_name = 'Contact List' ;


No, backticks. I gave an example of the backtick in my email (in 
brackets). It is on the same key as the tilde, and looks like this: `


Also, I would probably left $table_name as it was and put the backticks 
in the SQL statement, like this:


$sql = INSERT INTO `$table_name` values ('', '$_POST[f_name]', [...]

Jasper



On 11/13/05, Jasper Bryant-Greene [EMAIL PROTECTED] wrote:

Bruce Gilbert wrote:

You would need to show us the SQL that was causing that error. Otherwise
it is fairly meaningless.

hope this helps...

?

//check for required form variables
if ((!$_POST[f_name]) || (!$_POST[l_name])) {

Unrelated, but you should have quotes here. Like $_POST['f_name']


header(Location:http://www.inspired-evolution.com/show_addcontact.php;);

There should also probably be a space between the : and the start of the
  URL here.


exit;
}else {
//if form variables are present,start a session
session_start();
}

//check for validity of user
if ($_SESSION[valid] != yes) {

Again, quotes on the array subscript.


header(Location:http://www.inspired-evolution.com/contact_menu.php;);

And space between colon and URL here.


exit;
}

//set up table and database names
$db_name =bruceg_contactlist;
$table_name =Contact List;

//connect to server and select database
$connection =

@mysql_connect(69.90.6.198,database_username,password)

or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

//build and issue query
$sql = INSERT INTO $table_name values ('', '$_POST[f_name]',

You'll be wanting to put backticks (`) around the table name, because it
contains a space.

Jasper




--
::Bruce::


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



Re: [PHP] Re: emailing MySQL list not working

2005-11-12 Thread Jasper Bryant-Greene

Bruce Gilbert wrote:

I don't suppose you meant like this : $headers = From: 
$sender;(\r\n).
or is it without the ( )?


I think you should read up on some basic PHP syntax (the manual is your 
friend. He meant like this:


$headers = From: $sender\r\n;
$headers .= Reply-To: $reply_to\r\n;

and so on. If the headers are all on one line then the MTAs and mail 
clients have no way of telling them apart.


Jasper


On 11/12/05, Marco Kaiser [EMAIL PROTECTED] wrote:

Hi,

try to add in your $headers linebreaks. (\r\n).

-- Marco


$headers = From: $sender;
$headers .= Reply-To: $reply_to;
$headers .= Return-Path: $return_path;
$headers .= X-Sender: $x_sender;
$headers .= X-Mailer: PHP4\n; //mailer
$headers .= X-Priority: 3\n; //1 UrgentMessage, 3 Normal
$headers .= Mime-Version:1.0\n Content-Type: text/plain;
charset=\iso-8859-1\nContent-Transfer-Encoding: 8bit\n;



--
::Bruce::



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



Re: [PHP] Printing to a buffer

2005-11-12 Thread Jasper Bryant-Greene

Todd Cary wrote:
My client's new shared server does not allow printing to a file, so I 
want my print statement to print to a buffer, then I'll send it to the 
user via Headers.  This does not work since print does no go to the 
buffer, or at least appears not to: I get the errors from the header 
statements;


?
  ob_start;


You're missing some parentheses on the ob_start function. I think you 
meant to write:


ob_start();


  print This is a testbf;


You probably meant br in that string too.


  $buf = ob_get_contents();
  $len = strlen($buf);
  ob_end_clean();
  header(Content-type: application/text);


application/text isn't a MIME-Type, is it? Do you mean text/plain?


  header(Content-Length: $len);
  header(Content-Disposition: inline; filename=Sfyc.html);
  print($buf);
?

Todd



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



Re: [PHP] Printing to a buffer

2005-11-12 Thread Jasper Bryant-Greene

Todd Cary wrote:

Yup!  It was the missing parentheses!  Works as planned.

Many thanks

The application/text gives the user the ability; text/plain does not 


The ability to...?

seem to do that.  I just tried application/text since I use 
application/pdf for other applications.


Whatever it's giving the user the ability to do, it's probably because 
the browser doesn't recognise the (invalid) MIME-Type.


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



Re: [PHP] fopen on windows

2005-11-11 Thread Jasper Bryant-Greene

Jay Blanchard wrote:

$theFile = fopen(docs/InstallationInstructionMaster.txt, r) || die;


I'm not sure if it would make any difference, but I usually use or in 
this case rather than ||, and I know they have different operator 
precedence.



while(!feof($theFile)){
$theLine = fgets($theFile, 4096);
echo $theLine . br\n;
}
fclose($theFile);

The above code appears to work, but all that is output is lines of line
breaksno data. The file is a tab delimited test file;
[snip] 
Am I missing something other than an ice cold beer?


Well, it's a pretty model example of a line-by-line file read. I can't 
see anything wrong with it, so perhaps the problem lies elsewhere. 
There's no other files with the same name in your include_path?


Maybe something to do with auto_detect_line_endings or whatever it's 
called, in php.ini? (I know, probably a long shot.)


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



Re: [PHP] fopen on windows

2005-11-11 Thread Jasper Bryant-Greene

Jay Blanchard wrote:

[snip]
Well, it's a pretty model example of a line-by-line file read. I can't 
see anything wrong with it, so perhaps the problem lies elsewhere. 
There's no other files with the same name in your include_path?


Maybe something to do with auto_detect_line_endings or whatever it's 
called, in php.ini? (I know, probably a long shot.)

[/snip]

The output now looks like
[snip] 
based on the following code;


$theFile = fopen(docs/InstallationInstructionMaster.txt, rb) || die;

while(!feof($theFile)){
$theLine = fgets($theFile);
$lineArray = explode(\t, $theLine);
print_r($lineArray);
}
fclose($theFile);

It appears that something is getting read, but what?


Blank lines. Just to see if the problem is fgets(), try this:

// Left off the b because it ain't binary :)
$theFile = file_get_contents( docs/InstallationInstructionMaster.txt, 
r ) or die;

$lines = explode( \n, $theFile );

foreach( $lines as $line ) {

$line = explode( \t, $line );
print_r( $line );

}

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



Re: [PHP] Filtering and Escaping (Was: Select and $_POST)

2005-11-11 Thread Jasper Bryant-Greene

Chris Shiflett wrote:
I'm pretty lenient with email addresses and use the pattern from the PHP 
Cookbook (David Sklar and Adam Trachtenberg). I usually modify it to not 
allow angled brackets, since I don't know any email address that has 
those (but, they're probably OK as far as the spec goes).


I always try to enter my email address like this when asked for it on a 
form:


Jasper Bryant-Greene [EMAIL PROTECTED]

That is a perfectly valid (according to RFC822) email address. Those 
that do bother to validate usually spit it out as invalid.


Just to demonstrate that it's not quite as simple as it might first 
appear :)


Jasper

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



Re: [PHP] What is the purpose of sessions extension?

2005-11-11 Thread Jasper Bryant-Greene

GamblerZG wrote:

What is the purpose of sessions extension?

The reason I ask is because learning to deal with all its functions, ini
options and quirks took me _much_ more time than writing pure-php
replacement. (That is, without using  session_set_save_handler().)


I realise that yours might be a special case, but for most situations I 
have only had to do session_start() and then simply used $_SESSION as if 
it were any other array with the simple difference that it persists 
across requests. When done with the session, use session_destroy() if 
you feel the need.


I'm not sure how that could be harder than writing a pure-PHP 
replacement for the session extension...


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



Re: [PHP] undefined index and php

2005-11-10 Thread Jasper Bryant-Greene

Ross wrote:
because the following line give the notice 'undefined index'  BEFORE  the 
submit button has been pressed..


? $heading_insert= stripslashes($_POST['heading']);?


That's because before the submit button has been pressed, $_POST is 
empty and so 'heading' is indeed an undefined index. Try:


$heading_insert = isset( $_POST['heading'] ) ? stripslashes( 
$_POST['heading'] ) : '';


By the way, while you're switching register_globals off, it might be a 
good idea to also switch off magic_quotes_gpc (the reason you need 
stripslashes() above) and short_open_tag (judging by your use of the 
non-portable ? open tag rather than ?php).


Jasper

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



Re: [PHP] Gotta learn asp.net...

2005-11-10 Thread Jasper Bryant-Greene

Larry E. Ullman wrote:
Also, in my opinion, having a good knowledge of how to create a  dynamic 
Web site helps when going from PHP to ASP.NET. If you know  what the 
program must do in terms of functionality, protocol, etc.,  then it's 
mostly a matter of picking up the right syntax. I found  that ASP.NET is 
the opposite of PHP: doing something simple is  ridiculously hard but 
doing something kind of complex is pretty  simple. All the built in 
widgets and wizards help and the form  validation tools are really nice.


I wonder if ASP.NET have an email validation function? (For Richard 
Lynch's benefit.) :)


Jasper

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



Re: [PHP] Re: Security Issues - Where to look?

2005-11-10 Thread Jasper Bryant-Greene

GamblerZG wrote:

Richard Lynch wrote:


Please pay attention.



Sorry, I did not see your message when I posted that.



Oh and would you mind using an email address that exists? Every time I 
reply to one of your posts, I get a returned mail from highstream.net 
saying your user doesn't exist...


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



Re: [PHP] Inserting a NULL value into MySQL via PHP

2005-11-10 Thread Jasper Bryant-Greene

[EMAIL PROTECTED] wrote:

Is there a way when making a MySQL database entry through a PHP script and
there is no data to make the db treat it as NULL?


Wouldn't this just work:

INSERT INTO myTable (myField) VALUES (NULL)

Jasper

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



Re: [PHP] Use of auto_prepend_file inside an Apache directory container

2005-11-08 Thread Jasper Bryant-Greene
On Tue, 2005-11-08 at 13:36 -0700, Dan Trainor wrote:
[snip]
  So, as you can see, nothing completely out of the 'norm.  The examples
  given in the manual are not all that clear, so by using absolute path
  names, I'm just guessing.  I have used relative paths as well - same thing.
  
  The auto_prepend_file directive set from within php.ini, is commented
  out, as to not overwrite my specification.  I've tried leaving that
  directive blank, and setting it to something completely different.  Same
  results.
  
  If you guys wouldn't mind taking a few more minutes to mow over all of
  this, I would *greatly* appreciate it.

Would you mind telling us what the problem is? You've said that you are
having problems and that you don't think you're alone, but you haven't
mentioned what the actual problem is.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Use of auto_prepend_file inside an Apache directory container

2005-11-08 Thread Jasper Bryant-Greene
On Tue, 2005-11-08 at 13:43 -0700, Dan Trainor wrote:
 Well, the problem is simple;  it just doesn't work.  No script is
 prepended to the page that I access from within /demo/protected.  My
 prepend script consists of the following line of code:
 
 ? echo This is prepended.br /br /; ?
 
 Sorry about that.

Thanks. Have you tried putting quotes around the auto_prepend_file value
in .htaccess? I'm thinking maybe Apache is messing with the path
somehow. Something like:

php_value auto_prepend_file /absolute/path/to/file.php

Oh, and you probably know this, but make sure AllowOverride is set
correctly in your main Apache config file; try setting it to All for
debugging this.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] FileExists?

2005-11-07 Thread Jasper Bryant-Greene
On Mon, 2005-11-07 at 20:45 +0100, Gustav Wiberg wrote:
 Hi there!
 
 File_exists doesn't seem to work with URLs that point to another domain. 
 What to use?
 
 $x = fopen(http://www.stammis.com/getstart.php);
 if file_exists($x) 

You are trying to check if a file pointer exists. You want to check if
the file exists. Try:

if( file_exists( http://www.stammis.com/getstart.php; ) ) 

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Line breaks in mail function?

2005-11-06 Thread Jasper Bryant-Greene
On Mon, 2005-11-07 at 12:20 +1000, Murray @ PlanetThoughtful wrote:
 Example code:
 
 $body = 'From: ' . $name . '\r\n\r\n';
 $body .= 'Email:' . $email . '\r\n\r\n';
 $body .= 'IP Address: ' . $_SERVER['REMOTE_ADDR'] . '\r\n\r\n';
 $body .= 'Feedback:\r\n\r\n';
 $body .= $feedback;
 mail([EMAIL PROTECTED], Feedback, $body, From: 
 $email\r\nReply-To: $email\r\nX-Mailer: PHP/ . phpversion());
 
 As I said above, I've also tried using \n\n instead of \r\n\r\n.
 
 Can anyone give me some advive on how to get the linebreak characters 
 interpreted as linebreaks?

Use double quotes around the parts that have \r and \n characters if you
want them to be interpreted.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Classes and Functions and If's (Problems Again)

2005-11-03 Thread Jasper Bryant-Greene
On Thu, 2005-11-03 at 18:37 -0500, Unknown Unknown wrote:
 Hi everyone, i have some code that proccesses a login form. i have an object
 $DB which works only in SOME areas, this is the code:
 
 ?php
 require_once(Include.php);
 global $DB;

There is no need to global $DB here. You are already in the global
scope.

 $Username= $_REQUEST['Username'];
 $Password= $_REQUEST['Password'];
 $SQL= SELECT * FROM members WHERE Username='$Username' AND
 Password='$Password'; ;
 $DB-Query($SQL);
 $UserInfo=$DB-QueryInfo(Array);
 if($UserInfo==0) $Login=FALSE;
 else $Login=TRUE;

Why aren't you using real boolean values here?

 //Make Sure the user is not a duplicate user trying to log in again
 if($Login=TRUE)
 {
 global $DB;

Again, no need to global $DB. You are still in the global scope.

 $RL=__;
 $LoginD=__;
 $ID=$UserInfo['ID'];
 echo $ID;
 $DB=membersp;

Here is your problem. You just replaced the $DB object with a string.
Maybe you meant to set a property on the $DB object?

I think you may need to do some reading on OOP, perhaps start at
http://php.net/oop for PHP4 or http://php.net/oop5 for PHP5.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



RE: [PHP] PHP from the command line

2005-11-03 Thread Jasper Bryant-Greene
On Thu, 2005-11-03 at 20:58 -0800, bruce wrote:
 ok..
 
 show us the connection code you're using to access the db..

I think you're on the wrong track. The connection code is known good
because it works in CLI mode.

What I would like to see is any notable differences between the output
of phpinfo() in CLI mode and through your webserver.

Jasper

 -Original Message-
 From: Robbert van Andel [mailto:[EMAIL PROTECTED]
 Sent: Thursday, November 03, 2005 8:37 PM
 To: [EMAIL PROTECTED]; 'David Tulloh'
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] PHP from the command line
 
 
 From the web, all I get is that the connection failed.  Nothing more useful
 than that.  PHP_INFO tells me that it sees the MS SQL ini file and the MS
 SQL configuration settings are displayed further down the list.
 
 The username and password work in the script because I am able to connect
 using the exact same script from the command line.
 
 -Original Message-
 From: bruce [mailto:[EMAIL PROTECTED]
 Sent: Thursday, November 03, 2005 7:28 PM
 To: 'David Tulloh'; 'Robbert van Andel'
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] PHP from the command line
 
 what's the error that you're getting from the web php app...
 
 also, what do you get from the php_info() for the web app? this tells you a
 great deal of information regarding your php/web setup (if you didn't
 already know!)
 
 get us the information and we can help track down your issue...
 
 also, is there a user/passwd setup to access the mssql db?
 
 -bruce
 
 
 -Original Message-
 From: David Tulloh [mailto:[EMAIL PROTECTED]
 Sent: Thursday, November 03, 2005 6:22 PM
 To: Robbert van Andel
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] PHP from the command line
 
 
 Many linux distributions use a different php config file for the apache
 and cli versions.
 Using two different configurations might explain the problems you are
 seeing.
 
 David
 
 Robbert van Andel wrote:
 
 I run a linux webserver with Apache and PHP5.  Does anyone out there know
 why a php script would work from the command line but fail when running it
 through a web browser?  In particular, I'm trying to get a connection to an
 MSSQL server but PHP fails to connect when I run the script with a web
 browser.  My regular scripts (i.e. ones without any mssql functions) work
 fine from the browser. When I run the script from the command line, the
 connection succeeds.  Any idea if this is a PHP error or an apache error.
 If
 this is an apache error, does anyone know what I need to search for to find
 an answer?
 
 
 
 Thanks,
 
 Robbert van Andel
 
 
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Classes and Functions

2005-11-02 Thread Jasper Bryant-Greene
On Wed, 2005-11-02 at 18:56 -0500, Unknown Unknown wrote:
 Hi everybody i have a class that i reference with:
 $DB= new DBInterface;
 outside a function it works fine, but using $DB inside a function changes
 the data type i think... i get an error saying i'm using a method on a
 non-object...
 any help appreciatted

If you are attempting to access the variable $DB inside the function
scope, like this:

$DB = new DBInterface;

function doSomething() {
$DB-doSomethingElse();
}

Then it will not work unless you either pass $DB to doSomething(), or
declare $DB as a global at the start of the function. Like this:

function doSomething() {
global $DB;
$DB-doSomethingElse();
}

Or access $DB through the globals superglobal. RTFM.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Classes and Functions

2005-11-02 Thread Jasper Bryant-Greene
On Wed, 2005-11-02 at 19:05 -0500, Unknown Unknown wrote:
 Oh thanks again
 and what does RTFM mean?

Read The [insert your favourite word beginning with F here] Manual.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Re: Reset STDIN pointer

2005-11-02 Thread Jasper Bryant-Greene
On Wed, 2005-11-02 at 21:58 +, Curt Zirzow wrote:
 On Wed, 02 Nov 2005 15:20:46 -0500, John Nichel wrote:
 
  There has to be a way to do thisreset the internal STDIN pointer to
  the begining but I'll be damned if I can find it.
  
  reset ( STDIN );
  
  returns an error.
 
 The internal STDIN pointer? there is no such thing by the name of STDIN in
 php.

Yes there is, when running in CLI mode. See:

http://php.net/features.commandline#AEN7906

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] eval();

2005-10-30 Thread Jasper Bryant-Greene
On Sun, 2005-10-30 at 21:16 -0500, John Taylor-Johnston wrote:
 I need to generate embedded php within in a mysql record. $contents is 
 the actual contents of that record.
 
 ?php
 $contents = div class=\indent\ style=\font-size: 16px; font-family: 
 arial,helvetica; font-weight: bold;\About the Project/div
 ?php echo \hello world\; ?;
 echo eval($contents);
 ?
 
 I get this error:
 Parse error: parse error in /var/www/html2/test.php(4) : eval()'d code 
 on line 1
 
 If I just echo $contents, my browser spits out:
 
 div class=indent style=font-size: 16px; font-family: 
 arial,helvetica; font-weight: bold;About the Project/div
 ?php echo hello world; ?
 
 What's wrong? eval() is the correct thing to do, I thought?
 

eval() expects PHP code, not HTML with embedded PHP code. Try this
(untested):

eval(  ? $contents ?php  );

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] eval();

2005-10-30 Thread Jasper Bryant-Greene
On Sun, 2005-10-30 at 21:24 -0500, John Taylor-Johnston wrote:
 ?php
 
 $contents = div class=\indent\ style=\font-size: 16px; font-family: 
 arial,helvetica; font-weight: bold;\About the Project/div
 ?php echo \hello world\; ?;
 echo eval($contents);
 ?
 eval() expects PHP code, not HTML with embedded PHP code. Try this
 (untested):
 
 eval(  ? $contents ?php  );
 
 Scary. But it works.
 Shouldn't that error because of the unexpected ? and ?php in a bigger 
 example?

No, because eval(), when passed string $str, effectively does this
silently:

$str = ?php  . $str .  ?;

and then passes $str to the PHP interpreter.

Which is, in most cases, what you want, because you want to evaluate PHP
code.

However, if eval() is the answer, you're probably asking the wrong
question. You should take a hard look at your code and think of a better
way to do what you need to do.

I can assure you one does exist, but with your example it's fairly
obvious, so you'd need to explain better what you're trying to do before
I could help you.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
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 Jasper Bryant-Greene
On Thu, 2005-10-27 at 00:00 +0200, Jochem Maas wrote:
 gonna jump on your thread there Jasper, I would
 like to comment on your function and ask you a question:
 
 which is 'better' (for what), preg_*() or ereg[i]*()?

I prefer preg_*(), but I used eregi() because I couldn't be bothered
figuring out his regexp (it looked right, and it worked) and that's what
he used :)

It's a matter of personal taste, mainly.

[snip]
  ?php
  function fix_mac( $mac ) {
  
  if( eregi(
  
  ^[0-9A-Fa-f]{2}\- .
  [0-9A-Fa-f]{2}\- .
  [0-9A-Fa-f]{2}\- .
  [0-9A-Fa-f]{2}\- .
  [0-9A-Fa-f]{2}\- .
  [0-9A-Fa-f]{2}$,
 
 this string concatenation looks a bit naff.
 although on second thoughts I can see why you did it this way.
 down to personal choice :-).

I don't like it either, but that bit already worked, so I left it
functionally as-is, and I had to make it shorter so as to not wrap
stupidly in the email.

 the use of double quotes means strictly speaking
 you should be escaping the backslash and dollar sign (and the
 parentheseses?) although i would recommend single quotes.

Agreed.

 I would have used preg_match(), something like
[snip]

So would I, if I had been writing the function from scratch.

 white space is nice but too many blank lines lead to overscroll ;-)

Another matter of personal taste. I love whitespace and my scroll wheel
has its acceleration turned up very high, so scrolling doesn't really
bother me :)

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] PHP5 class constants

2005-10-27 Thread Jasper Bryant-Greene
On Fri, 2005-10-28 at 01:02 +0200, Dragan Stanojevic - Nevidljivi wrote:
[snip]
 and it works fine, I cannot define a constant by expression, like:
 
 class Foo {
 const AAA = 1  0;
 const BBB = 1  1;
 const CCC = 1  2;
 const DDD =1  3;
 }
 
 Well now, is this a bug, and I should file it, or is it, and why, normal?

Not a bug. Read manual.

From http://php.net/oop5.constants comes the following:

The value must be a constant expression, not (for example) a variable,
a class member, result of a mathematical operation or a function call.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
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-26 Thread Jasper Bryant-Greene
On Wed, 2005-10-26 at 11:15 -0600, Jason Gerfen wrote:
 I am having a problem with a couple of function I have written to check 
 for a type of string, attempt to fix it and pass it back to the main 
 function.  Any help is appreciated.
[snip]

Would you mind telling us what the problem was?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
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-26 Thread Jasper Bryant-Greene
On Wed, 2005-10-26 at 12:07 -0600, Jason Gerfen wrote:
 Um I did actually, but I will re-interate the problem with more detail.
 
 the vars $mac1, $mac2,  $mac3 are to get passed to the chk_mac() 
 function which determines if it is a valid hex representation of a h/w 
 address, if it does not meet the criteria of having a : separating 
 every two characters it then passes the var to the fix_mac() function 
 which attempts to fix the string or h/w address by either replacing any 
 - with a : or to break the h/w address up and insert a : every two 
 characters.  I also believe this is the one you should be playing with 
 as the last post I added a new regex which wasn't working.

OK, you've told us what your code does. Now can you explain what the
problem is? A new regex which wasn't working is a bit vague.

* Does it throw an error?
  - If so, can we have the error message?

* Does it mark invalid strings as valid?
  - Or vice versa?

Just posting a pile of code with an explanation of what it does and
leaving the rest of us to figure out what the problem is, is not helping
us to help you.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
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-26 Thread Jasper Bryant-Greene
On Wed, 2005-10-26 at 12:24 -0600, Jason Gerfen wrote:
 The code I just showed you is supposed to do the following, the 
 chk_mac() returns a true or false on the vars $mac1, $mac2 and $mac3.  
 $mac3 is the only var that should not be thrown into the fix_mac() 
 function which is working correctly.  The problem is when $mac1 and 
 $mac2 get put into the fix_mac() function nothing is being returned.
 
 I am not recieving any error codes, just an empty var.
 
 Sample output:
 
 00aa11bb22cc converted to
 00-aa-11-bb-22-cc converted to
 00:aa:11:bb:22:cc is valid.
 
 As you can see $mac3 is a valid example of a h/w address where $mac1  
 $mac2 were returned from the fix_mac() function as an empty string.

OK, thanks for that. I've rewritten your function below in much cleaner
code. Some of the situations you've used regexps in, string functions
would work fine. They're also much faster.

The below function works fine in my testing. I removed the special-case
for a valid MAC address at the start since your regexp was throwing
errors and there was no need since you already checked if it was valid
with chk_mac() (which by the way should return true or false, not 1 or
0, but meh).

?php
function fix_mac( $mac ) {

if( eregi(

^[0-9A-Fa-f]{2}\- .
[0-9A-Fa-f]{2}\- .
[0-9A-Fa-f]{2}\- .
[0-9A-Fa-f]{2}\- .
[0-9A-Fa-f]{2}\- .
[0-9A-Fa-f]{2}$,
$mac
) ) {

$mac_final = str_replace( '-', ':', $mac );

} else if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {

$mac_array = str_split( $mac, 2 );
$mac_final = implode( ':', $mac_array );

} else {

return false;

}

echo MAC: $mac_final;
return $mac_final;

}
?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Jasper Bryant-Greene
On Tue, 2005-10-25 at 13:01 +0400, Denis Gerasimov wrote:
 I am in a need of GUID generator but it seems that PHP doesn't have this as
 a built-in feature.
 
 I looked at http://pear.php.net http://pear.php.net/  and
 http://pecl.php.net http://pecl.php.net/  but found nothing suitable
 there.
 
 I really need true unique identifiers - md5() hash is not OK because of
 the birthday paradox.
  
 Can anyone recommend a way for solving this trouble?

I use:

$unique_id = sha1( uniqid( mt_rand(), true ) );

which should be very unique and suitable for most purposes.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



RE: [PHP] GUID or any other unique IDs

2005-10-25 Thread Jasper Bryant-Greene
On Tue, 2005-10-25 at 14:47 +0400, Denis Gerasimov wrote:
  $unique_id = sha1( uniqid( mt_rand(), true ) );
  
  which should be very unique and suitable for most purposes.
 
 I really need millions of unique IDs - hashing is not suitable for this task
 (I think so) :-(. Any more ideas?

The above function could generate much more than millions of unique IDs.

You have 1.46 x 10^48 possible hashes, and with an input of the current
time in microseconds prefixed by a Mersenne Twister random number and
suffixed by additional entropy from the combined linear congruential
generator, collisions should be *very* improbable, even when generating
IDs on multiple hosts all at the same time.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] how to display GD graphic in web page

2005-10-24 Thread Jasper Bryant-Greene
On Mon, 2005-10-24 at 20:14 -0400, Chris wrote:
 I don't understand what is going on with a simple example I created to 
 understand how GD graphics are presented in a web page.
[[snip]]
 However if I replace:
 img src=graphic.php
 
 with
 
 img src=?php
 $image = imagecreatefrompng(my_graphic.png);
 imagepng($image);
 ? 
 
 my_graphic.png is no longer displayed and the web page gets filled with 
 random characters.
 
 Why is this happening or what am I missing.

You're not missing anything. That is exactly the expected behaviour. You
can call graphic.php with GET variables if you need to pass information
on, but you can't put images inline like that except for with data:
URIs.

data: URIs are currently only supported by Gecko browsers (Mozilla,
Firefox, etc) and maybe Safari or Opera (not sure about the latter two).

Do a search for data: URI RFC or similar to find out about them.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Abstract Classes?

2005-10-23 Thread Jasper Bryant-Greene
On Sun, 2005-10-23 at 08:54 +0100, Alan Lord wrote:
 Hi All,
 
 I have started reading a couple of books about PHP 5 and whilst most of
 it is comprehensible even to me :-), I fail to understand WHY there is
 such a thing as an abstract class or method?
 
 I think I understand what it is: A class that can't itself be
 instantiated, only inherited from, or a method that describes itself
 only in terms of what properties it accepts but no implementation
 detail.
 
 But could someone explain why I would want to use this? I'm sure it is
 very useful but I can't quite see the benefit...

Hi Alan

Here's an example from an application framework I've been working on.

It has classes to represent the different HTTP response statuses (like
301 Moved Permanently, 304 Not Modified etc.) with required and
forbidden headers for each and different characteristics (like no
request-body allowed etc).

I have an Abstract class called HTTP_Response, from which
HTTP_Response_Moved_Permanently, HTTP_Response_Not_Modified, and many
others all inherit.

The reason HTTP_Response is abstract is because there's no such thing as
an HTTP_Response on its own. It has to be a specific type of HTTP
Response, that is a 301 Moved Permanently or a 304 Not Modified.

Does that help?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] A better way to do this

2005-10-23 Thread Jasper Bryant-Greene
On Sun, 2005-10-23 at 20:23 +0100, Ross wrote:
 I want the selct table to retain it's value on submit. The way I have done 
 it works but is a bit rubbish and was wondering if there is a more efficient 
 way. I just make the variable equal to selected when the form is submitted
 
 select name=table_name id=table_name
 option value=1 ?=$one; ?Please Select/option
 option value=news ?=$two; ?News/option
 option value=events ?=$three; ?Events/option
 option value=publications ?=$four; ?Publications/option
 /select

?php
$selectValues = array(
'1' = 'Please select',
'news'  = 'News',
'events'= 'Events',
'publications'  = 'Publications'
);

print( 'select name=table_name id=table_name' );

foreach( $selectValues as $value = $option ) {

print( 'option value=' . htmlspecialchars( $value ) . '' );
if( $_POST['table_name'] == $value ) {
print( ' selected' );
}
print( '' . htmlspecialchars( $option ) . '/option' );

}

print( '/select' );
?

If you're using XHTML, replace ' selected' with ' selected=selected'

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] connect to MySql

2005-10-23 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 12:06 -0700, hassan mahdi wrote:
 I have windows XP sevice pack 1 and 2, PHPv5.0.5, Mysql v1. I am working in 
 web design. I am unable to connect to the mysql server. Althought my php 
 files running fine and my mysql server is also running fine.

MySQL 1? Really? That's a *very* old version, you should really
upgrade :)

 i) i had changed the php.ini-dist file to php.ini.
 
 ii)i uncommented the extensions of php_mysql.dll in php.ini file
 
 iii)i set the 
 
 extensions_dir to extension_dir = D:\PHP\php-5.0.3\ext\ in php.ini file

If you're running PHP 5.0.5 then why is the directory called php-5.0.3?

 iv)i had copied the libmysql.dll in windows\system32 and windows\system i 
 wrote the following code:
 
 [snip] 
 
  but after all these i am still getting the error Fatal error: Call to 
 undefined function mysql_connect() in D:\PHP\teknohub\new.php on line 14 
 please help me to solve this problem out.

Confirm that:

a) there exists a file php_mysql.dll in the directory D:\PHP\php-5.0.3
\ext

b) the php.ini file that you have been editing matches the one displayed
if you create a file containing ?php phpinfo(); ? and view it with
your web browser

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] error reporting php-5.0.4-10.4 on FC4

2005-10-23 Thread Jasper Bryant-Greene
On Sun, 2005-10-23 at 17:31 -0400, Bob Hartung wrote:
 Hi all,
Slowly I'm progressing.
Now how to turn error reporting on for a test apache server.
 
I have made the following changes to /etc/php.ini:
 
error_reporting = E_ALL
display_errors = On
error_log = /var/log/php_errors
 
On errors I still have no in browser display nor is anything written 
 to the log file.

Make a file containing just the following line and view it in your
browser:

?php phpinfo(); ?

See if the path to php.ini shown in that file is /etc/php.ini. If it
isn't, then you're editing the wrong php.ini.

Also, make sure you're not overriding those values in a .htaccess file
or in a script.

What kind of errors are happening that aren't being displayed? For
example in an output buffering handler, an error could just cause your
script to output nothing.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] error reporting php-5.0.4-10.4 on FC4

2005-10-23 Thread Jasper Bryant-Greene
On Sun, 2005-10-23 at 21:31 -0400, Bob Hartung wrote:
 Jasper
If if make a file containing only
?php
  phpinfo() ;
?
I get what I expected.
 
If I make a file containing
 ?php
 
 phpinfo() ;
 
 // Now a simple class and a call to the class
   class Simple()

Your error is here^^ (brackets shouldn't be there)

But PHP should tell you that by throwing a Fatal error. What are the
values of error_reporting and display_errors that display in the
phpinfo() output?

By the way, the htmlbody/body/html is put there by your
browser, not PHP. PHP is actually outputting absolutely nothing in the
response-body.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] error reporting php-5.0.4-10.4 on FC4

2005-10-23 Thread Jasper Bryant-Greene
On Sun, 2005-10-23 at 23:01 -0400, Bob Hartung wrote:
 Jasper  Derek
 
phpinfo() says:
   configuration file path /etc/php.ini
 
PHP Core
DirectiveLocal Value   Master Value
 
 display_errorsOff   Off
 error_logno value  no value
 log errorson on
 
 Derek's idea sends nothing to the log but does send to the browser.
 
 It seems that /etc/php.ini is not being parsed since it says:
 
error_reporting  =  E_ALL
display_errors = On
display_startup_errors = On
log_errors = On

/etc/php.ini *is* being parsed, it says so right there (above). However,
display_errors isn't. Do a search inside /etc/php.ini for
display_errors, see if there's more than one declaration for it. Make
sure it isn't commented out (sounds silly, but you never know)...

Oh, and check the permissions on /etc/php.ini, just in case.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Memory Leak?

2005-10-22 Thread Jasper Bryant-Greene
On Sat, 2005-10-22 at 16:36 -0500, Richard Lynch wrote:
 I've written a script to munge and import 108,000+ records.
[snip]
 http://l-i-e.com/feedbaby/memory_leak.htm

It looks fine to me, but you might like to try accumulating the records
say up to 100 at a time and then doing extended INSERTs (if your MySQL
version supports them) like this:

INSERT INTO tablename
(col1, col2)
VALUES
('value1', 'value2'),
('value3', 'value4'),
('value5', 'value6'),
('value7', 'value7')

... and so on.

These are apparently much nicer for MySQL to process, which may result
in lower memory usage and faster operation.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Declaring vars as INT ?

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 21:39 +0200, Chris Knipe wrote:
 Function DoSomething($Blah) {
   $Blah = (int) $Blah;
   return $Blah
 } 
 
 $Blah, cannot be larger than 2147483647, and sometimes, I get negative
 integers back from the above function.
 
 This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
 confirm this, and if it is indeed true, is this a bug, or a limitation
 somewhere on PHP?  Any other ways to confirm that *large* numbers, are
 indeed integers?  I'm working with numbers in the form of mmddsss
 (20051025001 for today for example)

It's not a PHP bug. I'm guessing you're on a 32-bit platform. 2147483647
is the maximum length of a signed integer on a 32-bit platform, and PHP
doesn't do unsigned integers.

A date in the form of mmddsss etc. isn't really a number, so if it
was me I'd probably treat it as a string. If you really *have* to treat
it as a number, then use float and get all the precision errors that
come with floating-point, or use binary coded decimal or another
arbitrary precision system.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



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

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 15:11 -0500, Jay Blanchard wrote:
 IIS5 on W2K
 PHP 4.4.n
 php_curl.dll is not commented.
 libeay32.dll  AND ssleay32.dll are in the system folder (system32 too, just
 in case)
 path to the extensions is correct
 
 Fatal error: Call to undefined function: curl_init() in
 E:\sitegrp1\TEST20051010\curltest.php on line 3

Done a phpinfo() to see if the CURL extension is really getting loaded?

Is your extension_dir (or whatever it's called) correct in php.ini?

The other thing that's caught me out when I've been forced to use that
degenerate platform, is that sometimes PHP is using a different php.ini
from the one you thought it was using, f.x. if there has been an earler
PHP install and someone's put php.ini in c:\windows\system32 or
something.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



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

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 15:26 -0500, Jay Blanchard wrote:
 [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!
  
 
 This is what happens when you go over to the dark side.
 [/snip]
 
 It's not my fault! How do I fix this?
 

I haven't used Windows for a while, but Start-Search-Files  folders
(or something like that) and enter php.ini. Delete all results except
the one that you've been editing, and then move the one you've been
editing around the following folder until you find the one in which it
works:

c:\php
c:\windows
c:\windows\system32
c:\

Horrible, isn't it?

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



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

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 15:43 -0500, Jay Blanchard wrote:
 [snip]
 I haven't used Windows for a while, but Start-Search-Files  folders
 (or something like that) and enter php.ini. Delete all results except
 the one that you've been editing, and then move the one you've been
 editing around the following folder until you find the one in which it
 works:
 
 c:\php
 c:\windows
 c:\windows\system32
 c:\
 
 Horrible, isn't it?
 [/snip]
 
 Horrible indeed. I got no joy from this. It didn't work.

When you say didn't work... do you mean you didn't find any other
php.ini files?

There's one other thing I can think of. It's possible to set things like
the location of the php.ini file and also php configuration directives
through Apache's configuration.

Now I know you're using IIS, but is there a similar thing available
through IIS's configuration? (I wouldn't know, I don't practise the dark
arts...)

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] SCRIPT_NAME

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 21:01 -0400, Robert Cummings wrote:
 Oh I know, I was just pointing out that it won't work :) Doesn't work
 because it only strips off the first path segment (assuming no off by
 one error also ;). For instance:
 
 /a/b/c/d/foo.php
 
 becomes:
 
 a/b/c/d/foo.php
 
 but the OP wanted:
 
 foo.php

It will actually work... Did you not notice that he was using
strrpos() ? Note the extra 'r' in there :) http://php.net/strrpos

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] rtrim Null characters

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 20:45 -0500, Richard Lynch wrote: 
 Anyway, my question is, what is the morally correct function to use to
 remove these null characters from the end of my string?
 
 I'm guessing 'rtrim' would work, but is a NUL char really whitespace?

I think rtrim() is probably your best bet. Haven't tried, though.

 To be clear: I'm mcrypt_encrypt()ing the secret word into the URL and
 a hidden form element, along with the IV, ditto, and so both are
 available to the potentical malicious user.  So if exposure of IV is
 an issue in any suggested answer, keep that in mind.

To be honest, I think you're going about it the wrong way. Put the
secret word into $_SESSION. Point the img tag at a PHP script which
pulls it out of $_SESSION and renders it as an image. Then you don't
need to send it to the client in any form.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Putting Form Variables / URL Parameters in to an associative array?

2005-10-20 Thread Jasper Bryant-Greene
On Thu, 2005-10-20 at 10:01 +0200, Jacques wrote:
 How can I grab parameters / key-value-pairs from a query string and put them 
 in to an associative array where each key-value pair inside the array 
 exactly corresponds with the key-value pairs inside the querystring?

http://php.net/parse_str

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Executing process in background

2005-10-20 Thread Jasper Bryant-Greene
On Thu, 2005-10-20 at 15:07 -0700, Surya Mishra wrote:
 I have to start a task on the server side that is going to take pretty long
 to process in the server side. So I would like to show a message to the user
 and ask him/her to check again later. But starting a new task holds up the
 thread and won't let me exit the php. The user's browser does keeps showing
 busy.
 I tried to create a new thread using pcntl_fork, but my php doesn't allow
 that as it has not been compiled with pcntl support and its not possible to
 change that.
 I also tried to create a script that would do the task and called the script
 using system command and passed an '' at the end to make it process in
 background, but that also keeps the main thread busy.

Add it to a list (flat file, DB, whatever) of processes to be done and
run a cron script regularly (how regular would depend on the specific
app) to execute all the processes in the list.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] SCRIPT_NAME

2005-10-20 Thread Jasper Bryant-Greene
On Thu, 2005-10-20 at 22:22 -0400, John Taylor-Johnston wrote:
 SCRIPT_NAME and PHP_SELF always include leading url information and 
 slashes. Is there a function I can use to skin either down to the 
 filename? No slashes or leading url.

http://php.net/basename for filesystem paths

http://php.net/parse_url for URLs

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] win32service extension source code

2005-10-19 Thread Jasper Bryant-Greene
On Thu, 2005-10-20 at 02:22 +0300, Evil Worm wrote:
 Whre can i fid the source code for this extension?
 
 it's documented at php.net/win32service and can be downloaded from
 snaps.php.net/win32/ but the source isn't in the cvs. or did i miss
 it?

http://cvs.php.net/pecl/win32service/

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] Re: No redirect with header()

2005-10-19 Thread Jasper Bryant-Greene
On Thu, 2005-10-20 at 03:22 +0200, Dotan Cohen wrote:
 On 10/18/05, Oliver Grätz [EMAIL PROTECTED] wrote:
  Snippets are bad ;-)
 
  Please post a full example that is _not_ working on your server.
  Perhaps this is no PHP problem at all.
 
 
 I know, but I don't want to post my tracking code. I am certain,
 however, that it is not returning anything to the browser. The ?php
 is at the top of the page, no echo, ...

So just blank out the tracking code. I'm not sure how you expect us to
help you if we can't see the code that isn't working :)

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

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



Re: [PHP] fckeditor and PDF and pesky users

2005-10-17 Thread Jasper Bryant-Greene

Richard Lynch wrote:


 On Sat, October 15, 2005 7:26 am, Edward Vermillion wrote:

 Do they want the PDF to display in the page, or is a link to a PDF
 ok for them?


 I've already warned them that a PDF embedded into a page is
 impossible.

 That may not be true, technically, for all I know, but I've sure
 never seen it, and don't even want to try to go somewhere that so few
 have gone.



I would expect that putting the PDF in an iframe would work, but I 
wouldn't trust browsers or the Acrobat plugin to not crash horribly in 
that sort of situation. It's also going to be very confusing for users 
seeing the Acrobat toolbar floating in the middle of their page.


It would be interesting to see some tests of PDF-in-iframe done in 
various different browsers, but unless it just happened to work 
perfectly in every common browser (we can all dream, can't we?) I 
wouldn't touch it.


Jasper

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



Re: [PHP] Re: ampersand in dom with utf-8

2005-10-15 Thread Jasper Bryant-Greene

jonathan wrote:
So I'm reading up on character encoding in XML documents as I think  
this is the problem (after the many helpful suggestions on this list).


With regards to your second question; no, I'm not sure if I'm using  
proper utf-8 througout the entire process. When I input from the form  
I'm converting everything via htmlentities . This is why I'm getting  
egrave; etc... (On a side note, is there a function or way to check  to 
see if a form is using the native characters (from a copy and  paste of 
a word document like è) or the HTML entity egrave; .


If you're using the correct character set all the way through, you only 
need to do htmlspecialchars() to convert things like amp; and lt;, as 
all the other characters should already be present in the character set 
you are using (UTF-8). htmlentities() is mostly used for converting 
characters outside of your character set into entities.


I've changed the content-type from text/xml to application/xml but  that 
doesn't seem to help.


As only UTF-8 and UTF-16 have to be supported, I'm concerned whether  
the processor might think it is some other encoding.


The HTTP headers are:

Date = Sat, 15 Oct 2005 17:49:02 GMT
Server = Apache/1.3.33 (Unix) mod_jk/1.2.8 PHP/5.0.4  
mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4  
FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a

X-Powered-By = PHP/5.0.4
Cache-Control = no-cache
Connection = close
Content-Type = application/xml


header('Content-Type: text/xml; charset=UTF-8');

I guess pursuant to cc's suggestion, I should do an  html_entity_decode 
when I make the xml document and then do another  htmlentities on the 
html representatoin.


Shouldn't be any need. Characters like è don't have any special meaning 
in XML, and they can be represented in the UTF-8 character set, so 
there's no need to convert them to entities at any stage.


--
Jasper Bryant-Greene
General Manager
Album Limited

a: Freepost Album, PO Box 579, Christchurch 8015, New Zealand
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
e: [EMAIL PROTECTED]
w: http://www.album.co.nz/

Memberships:
* Institute of Electrical and Electronics Engineers (IEEE)
* Association for Computing Machinery (ACM)

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



Re: [PHP] Re: ampersand in dom with utf-8

2005-10-14 Thread Jasper Bryant-Greene

jonathan wrote:

the real characters (presumably è) won't render correctly.


Are you outputting the correct character set information (UTF-8), and 
are you sure that UTF-8 is being used throughout the entire process?


--
Jasper Bryant-Greene
General Manager
Album Limited

a: Freepost Album, PO Box 579, Christchurch 8015, New Zealand
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
e: [EMAIL PROTECTED]
w: http://www.album.co.nz/

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



Re: [PHP] Problem with Javascript:...submit()

2005-10-13 Thread Jasper Bryant-Greene

Johan Grobler wrote:

while ($row = mysql_fetch_array($sql_result)) { echoForm
name=\.$row['LITERATURE_title'].\ action=\searchlit.php\
method=\post\ font face=\arial\ size=\2\ a
href=\javascript:.$row['LITERATURE_title']..submit();\
.$row['LITERATURE_title']. - .$row['res_fname'].
.$row['res_lname']./a ...

Everything works as long as $row['LITERATURE_title'] is one word, see
this variable contains the names of books, and if the books name is
Heaven for instance it works fine but as soon as the title is
something like PHP for Dummies it doesnt work and i get a error on
page message, I tried using numbers as the form name but then the
same thing happens.


If you've got a row ID number or something, just call the form lit[id] 
(replacing [id] with the ID number), because I don't think a form name 
can start with a number. Otherwise you could sha1() the title and use 
that as the identifier, or simply remove all spaces...


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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



Re: [PHP] help me in creating tables on the fly

2005-10-12 Thread Jasper Bryant-Greene

Suresh Pandian wrote:

im currently working on creating musical forum. i need to create
tables for every song uploaded on the fly to save the comments and
rates entered by the viewers. im unable to create tables on the
fly. can anyone know how to create tables on the fly
.plz tell me . Also, can u tell me the way to how to
play the song using php.. i uploaded the songs to mysql
database... if u know the same kind of work  anywhere  in the net as
tutorials and help .plza tell me the URL


AHHH! Don't create a table for every song Have a `songs` table 
containing all of the songs. Something like:


CREATE TABLE songs (songID INT UNSIGNED NOT NULL AUTO_INCREMENT, artist 
VARCHAR(50) NOT NULL, title VARCHAR(50) NOT NULL, PRIMARY KEY(songID));


(simplified) and another table `comments` like this:

CREATE TABLE comments (commentID INT UNSIGNED NOT NULL AUTO_INCREMENT, 
songID INT UNSIGNED NOT NULL, comment TEXT NOT NULL, PRIMARY 
KEY(commentID), KEY(songID));


and another `ratings` like this:

CREATE TABLE ratings (ratingID INT UNSIGNED NOT NULL AUTO_INCREMENT, 
songID INT UNSIGNED NOT NULL, rating TINYINT UNSIGNED NOT NULL, PRIMARY 
KEY(ratingID), KEY(songID));


That's why it's called a *relational* database. If you're using InnoDB 
you can even define the relations between the tables using foreign keys. 
Go to http://dev.mysql.com/doc/en/mysql/ and have a good read of the 
MySQL manual, it will be very helpful for you.


Please don't just copy-paste the above table definitions, they're meant 
to be modified to suit your needs.


I'll leave your other question to be answered by someone with experience 
of streaming audio from PHP, as I've never had occasion to do that.


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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



Re: [PHP] Trouble moving directory

2005-10-12 Thread Jasper Bryant-Greene

-k. wrote:
I'm having trouble moving some directories. My script works fine on 
some directories but doesn't move others. It seems to have trouble 
with directories with non alphanumeric charters. I'm running Red Hat 
FC2. I'm trying to move the directory basically like this...


?Php

$source_dir = '/some/dir/Dir That Won't Move/';


$source_dir = escapeshellarg( '/some/dir/Dir That Won't Move/' );


$dest_dir   = '/some/other/dir/';


$dest_dir = escapeshellarg( '/some/other/dir/' );



$cmd = escapeshellcmd(mv .$source_dir. .$dest_dir); $result = 
shell_exec($cmd);


?

Is there some way to escape the characters in the directories? For 
example if i put a \ in front of blank spaces it takes care of 
those (same for ',( etc.) but that obviously doesn't take care of
 everything. I'm hoping there is something easy i'm overlooking here 
that will escape all the characters.


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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



Re: [PHP] object as function argument

2005-10-11 Thread Jasper Bryant-Greene

Björn Bartels wrote:

myab ths a stupid question, but i didn't find anything inside the php
docs:

is it possibe to pass an object (like $foo = new myObject(); ) to a
function as its argument (like my_func($foo); )


Yes, but if you're using PHP 4 you may want to define the function as 
taking that argument by reference ($foo) unless you want to pass a copy 
of the object.


It would have taken you less time to write a test script and see for 
yourself than to search the docs and then post to the list...


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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



Re: [PHP] getting php to generate a 503

2005-10-10 Thread Jasper Bryant-Greene

[EMAIL PROTECTED] wrote:

I want to write a php page that can return a 503 with some useful
information. 


?php

header(HTTP/1.0 503 Service Unavailable);
echo Page execution failed.\n;
   
?


Is what I've done so far - yet it doesn't work, the headers don't seem to be
modified and my page just returns the echoed contet and both firefox and IE
blithely ignore the fact that I set the server unavailable header :( can
anyone give me a clue as to what I've done wrong?


What did you expect to happen? The expected behaviour (unless I'm 
missing something) is that the browser should display the content (i.e. 
Page execution failed) that you sent to it.


The 503 status is a signal to the browser, and I don't believe either 
Firefox or IE pass that signal on.


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

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



  1   2   3   4   >