php-general Digest 23 Aug 2006 16:05:53 -0000 Issue 4309
Topics (messages 241039 through 241053):
Re: --with-openssl on x64
241039 by: Chris
241040 by: Chris
Re: Regex
241041 by: Nadim Attari
Re: strange mysqli error
241042 by: Jochem Maas
241046 by: Richard K Miller
Session / cookie issues
241043 by: Dave Goodchild
switch it button
241044 by: Ross
241045 by: Jay Blanchard
241047 by: Ford, Mike
241048 by: tedd
241049 by: Arpad Ray
Why small > big?
241050 by: tedd
241051 by: M. Sokolewicz
241053 by: Alex Turner
MCrypt resource limits?
241052 by: Eric Butera
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Marten Lehmann wrote:
Hello,
openssl is compiled for x86 on my system, so the libs are in /usr/lib64
rather than /usr/lib. But configure only looks in /usr/lib and gives me
configure: error: Cannot find OpenSSL's libraries
Just checked ./configure and it had this option:
--enable and --with options recognized:
--with-libdir=NAME Look for libraries in .../NAME rather than
.../lib
not sure if that affects *all* options you want to build or you can tell
it just openssl:
--with-openssl=/usr --with-libdir=/usr/lib64
worth a shot ;)
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Chris wrote:
Marten Lehmann wrote:
Hello,
openssl is compiled for x86 on my system, so the libs are in
/usr/lib64 rather than /usr/lib. But configure only looks in /usr/lib
and gives me
configure: error: Cannot find OpenSSL's libraries
Just checked ./configure and it had this option:
--enable and --with options recognized:
--with-libdir=NAME Look for libraries in .../NAME rather than
.../lib
not sure if that affects *all* options you want to build or you can tell
it just openssl:
--with-openssl=/usr --with-libdir=/usr/lib64
worth a shot ;)
oops that should be:
--with-openssl=/usr --with-libdir=lib64
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
M. Sokolewicz wrote:
Nadim Attari wrote:
Hello,
I have some text in a table... the text contains hyperlinks (but not
html coded, i.e. plain "Some text...http://www.something.com")
When i retrieve these texts from the table, i want the hyperlinks to
become clickable, i.e. <a href etc added automatically.
"Some text...<a
href="http://www.something.com">http://www.something.com</a>"
I know this sould be done using Regex, but i don't know regex.
Any help (links, examples, etc)
Thanks
Nadim Attari
You don't know Regex. Well, that's simple then, TRY to learn it. Noone
will (or should) give you any answers if it's absolutely clear that
you're not putting any effort into trying to find one yourself. "I know
this should be done using Regex, but I don't know regex.", wouldn't you
think it'd be a good idea to look up a tutorial somewhere or try to find
out what this "regex" exactly is? Try to type regex in the php doc, see
the notes for the various functions?
really, a little more effort goes a long way.
- tul
Hello,
I know i MUST learn it.. time does not permit me. But surely i'll learn
how to use this powerful tool!
And if i didn't need a quick help from this ML, why i would be here ...
do you think if time permitted me to learn this, i'll ask a little help
from this ML ? I am learning and will continue to learn throughout my life.
And remember, the day one says "i've learnt everthing now" this is the
day his downfall begins ...
Anyway i've got something working:
function hyperlinks($text = '', $class = 'link')
{
$text = trim($text);
if ($text != '')
{
if (trim($class) != '') $class = ' class="'.$class.'"';
$in = array('`((?:https?|ftp)://\\S+)(\\s|\\z)`',
'`([[:alnum:]]([-_.]?[[:alnum:]])[EMAIL PROTECTED]:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4}))`');
$out = array('<a href="$1"'.$class.' target="_blank">$1</a>$2', '<a
href="mailto:$1"'.$class.'>$1</a>');
$text = preg_replace($in, $out, $text);
}
return $text;
}
Renders http, https, ftp, mailto.
Thanks M. Sokolewicz and everyone.
Nadim Attari
--- End Message ---
--- Begin Message ---
how do you know which object is destroyed first?
also you are using 3 different versions of php - not something that will
help narrow down the problem.
Richard K Miller wrote:
> Good afternoon. I'm getting a weird mysqli error in my object
> destructor. Here's an example:
>
> <?php
>
> $db = new mysqli('localhost', USERNAME, PASSWORD, DATABASE);
>
> class Test
> {
> function __construct()
> {
> global $db;
>
> $db->query("SELECT 'test'");
> print_r($db->error);
> }
>
> function __destruct()
> {
> global $db;
>
> $db->query("SELECT 'test'"); // line 20
> print_r($db->error); // line 21
> }
> }
>
> $test = new Test();
what happens if you add the following line:
unset($test);
>
> ?>
>
>
> A. On my dev machine (Mac OS X + PHP 5.1.4 + MySQL 5.0.19) I get the
> following errors EVERY time:
> Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli
> in /Users/richard/Projects/data/private/mgftest.php on line 20
> Warning: Test::__destruct() [function.Test---destruct]: Couldn't fetch
> mysqli in /Users/richard/Projects/data/private/mgftest.php on line 21
>
> B. On my production server (FreeBSD + PHP 5.1.2 + MySQL 5.0.19) I
> SOMETIMES get the following error: (If I refresh the page repeatedly,
> sometimes there's an error, sometimes not.)
> Warning: mysqli::query() [function.query]: Couldn't fetch mysqli in
> /usr/local/www/data/private/mgftest.php on line 20
>
> C. On a commercial web host (PHP 5.0.4 + MySQL 5.0.22) I NEVER get any
> errors.
>
> There's nothing else in my error logs, $db-errno is 0, and $db->error is
> empty. Interestingly, I never get any errors from the constructor.
>
> Any ideas?
>
> Richard
>
>
> ---
> Richard K. Miller
> www.richardkmiller.com
>
> --PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On Aug 23, 2006, at 2:33 AM, Jochem Maas wrote:
how do you know which object is destroyed first?
also you are using 3 different versions of php - not something that
will
help narrow down the problem.
Richard K Miller wrote:
Good afternoon. I'm getting a weird mysqli error in my object
destructor. Here's an example:
<?php
$db = new mysqli('localhost', USERNAME, PASSWORD, DATABASE);
class Test
{
function __construct()
{
global $db;
$db->query("SELECT 'test'");
print_r($db->error);
}
function __destruct()
{
global $db;
$db->query("SELECT 'test'"); // line 20
print_r($db->error); // line 21
}
}
$test = new Test();
what happens if you add the following line:
unset($test);
No errors when I use unset(). I see what you mean about not knowing
which object is destroyed first. Maybe I'll have to use a non-OOP
connection to MySQL, since it wouldn't appear there's any way to
specify the order of destruction of objects.
--- End Message ---
--- Begin Message ---
Hi all. I mailed some time ago regarding a cookie/session issue I am having
and thank you all for your useful and knowledgeable responses. I have now
used 10 separate testers and 9 are able to progress through a 3-stage form
process that validates data as it goes along and enters the data into the
session array - enabling the user to go back and see previous forms
pre-populated with their selected data (cahcing is enforced on these pages).
However, the client still has issues and I have confirmed that their browser
is rejecting cookies. They are using IE on Win XP and have Internet security
set to Medium. I set mine to the same, used IE to go through the process and
had no such issues. Can anyone tell me if I am missing something obvious?
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---
--- Begin Message ---
At the moment I have this, but I want to change it to one switch button
<a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=1">switch it</a>.
I
have tried but keep getting wrapped up in nested if-else statements. Does
anyone know how to make an efficient one button on-off switch.
<?
$session_switch = isset($_GET['session_switch']) ? $_GET['session_switch']
: 0;
if ($session_switch==1) {
echo "on";
?>
//do something here
<?
}
else {
//do something else
}
?>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=0">off</a>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=1">on</a>
--- End Message ---
--- Begin Message ---
[snip]
At the moment I have this, but I want to change it to one switch button
<a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=1">switch
it</a>.
I have tried but keep getting wrapped up in nested if-else statements.
Does
anyone know how to make an efficient one button on-off switch.
[/snip]
Have you considered a switch statement? http://www.php.net/switch
--- End Message ---
--- Begin Message ---
On 23 August 2006 12:45, Ross wrote:
> At the moment I have this, but I want to change it to one
> switch button
>
> <a href="<?php echo
> $_SERVER['PHP_SELF'];?>?session_switch=1">switch it</a>.
> I
>
> have tried but keep getting wrapped up in nested if-else statements.
> Does anyone know how to make an efficient one button on-off switch.
>
>
>
> <?
> $session_switch = isset($_GET['session_switch']) ?
> $_GET['session_switch']
> > 0;
> if ($session_switch==1) {
> echo "on";
> >
> //do something here
>
> <?
> }
> else {
>
> //do something else
>
> }
> >
>
> <a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=0">off</a>
> <a href="<?php echo $_SERVER['PHP_SELF'];?>?session_switch=1">on</a>
How about something like:
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?session_switch=<?php
$_GET['session_switch']?0:1 ?>">switch</a>
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
At 12:44 PM +0100 8/23/06, Ross wrote:
At the moment I have this, but I want to change it to one switch button
I think I know what you mean -- a single switch button.
Please review this kiddie-script:
http://xn--ovg.com/a/toggle.php
hth's
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Ford, Mike wrote:
How about something like:
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?session_switch=<?php $_GET['session_switch']?0:1
?>">switch</a>
Beware that PHP_SELF is injectable like several other $_SERVER
variables, so you must at least encode it to prevent XSS attacks.
Eg. http://example.com/foo.php/"></a><script>alert('xss here');</script
Passing it through htmlspecialchars() will encode it safely, but in this
case you can just omit it.
href="?foo=bar" is perfectly valid and works fine.
Arpad
--- End Message ---
--- Begin Message ---
Hi gang:
I have a thumbnail script, which does what it is supposed to do.
However, the thumbnail image generated is larger than the original
image, how can that be?
Here's the script working:
http://xn--ovg.com/thickbox
And, here's the script:
<?php /* thumb from file */
/* some settings */
ignore_user_abort();
set_time_limit( 0 );
error_reporting( FATAL | ERROR | WARNING );
/* security check */
ini_set( 'register_globals', '0' );
/* start buffered output */
ob_start();
/* some checks */
if ( ! isset( $_GET['s'] ) ) die( 'Source image not specified' );
$filename = $_GET['s'];
// Set a maximum height and width
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
// Output & Content type
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
/* end buffered output */
ob_end_flush();
?>
---
Thanks in advance for any comments, suggestions or answers.
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
I'm not quite sure, but consider the following:
Considering the fact that most JPEG images are stored with some form of
compression usually ~75% that would mean the original image, in actual
size, is about 1.33x bigger than it appears in filesize. When you make a
thumbnail, you limit the amount of pixels, but you are setting
compression to 100% (besides that, you also use a truecolor pallete
which adds to its size). So, for images which are scaled down less than
25% (actually this will prob. be more around 30-ish, due to palette
differences) you'll actually see the thumbnail being bigger in
*filesize* than the original (though smaller in memory-size)
- tul
P.S. isn't error_reporting( FATAL | ERROR | WARNING ); supposed to be
error_reporting( E_FATAL | E_ERROR | E_WARNING ); ??
tedd wrote:
Hi gang:
I have a thumbnail script, which does what it is supposed to do.
However, the thumbnail image generated is larger than the original
image, how can that be?
Here's the script working:
http://xn--ovg.com/thickbox
And, here's the script:
<?php /* thumb from file */
/* some settings */
ignore_user_abort();
set_time_limit( 0 );
error_reporting( FATAL | ERROR | WARNING );
/* security check */
ini_set( 'register_globals', '0' );
/* start buffered output */
ob_start();
/* some checks */
if ( ! isset( $_GET['s'] ) ) die( 'Source image not specified' );
$filename = $_GET['s'];
// Set a maximum height and width
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
// Output & Content type
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
/* end buffered output */
ob_end_flush();
?>
---
Thanks in advance for any comments, suggestions or answers.
tedd
--- End Message ---
--- Begin Message ---
M Sokolewice got it nearly correct. However, the situation is a little
more complex than he has discussed.
The % compression figure for jpeg is translated into the amount of
information stored in the reverse cosine matrix. The size of the
compressed file is not proportional to the % you set in the compressor.
Thus 100% actually means store all the information in the reverse
cosine matrix. This is like storing the image in a 24 bit png, but with
the compressor turned off. So at 100% jpeg is quite inefficient.
The other issue is the amount of high frequency information in your
images. If you have a 2000x2000 image with most of the image dynamics
at a 10 pixel frequency, and you reduce this to 200x200 then the JPEG
compression algorithm will 'see' approximately the same amount of
information in the image :-( The reality is not quite as simple as this
because of the way JPEG uses blocks etc, but it is an easy way of
thinking about it.
What all this means is that as you reduce the size of an image, if you
want it to retain some of the detail of the original but at a smaller
size, there will be a point at which 8 or 24 bit PNG will become a
better bet.
Clear as mud?
AJ
M. Sokolewicz wrote:
I'm not quite sure, but consider the following:
Considering the fact that most JPEG images are stored with some form of
compression usually ~75% that would mean the original image, in actual
size, is about 1.33x bigger than it appears in filesize. When you make a
thumbnail, you limit the amount of pixels, but you are setting
compression to 100% (besides that, you also use a truecolor pallete
which adds to its size). So, for images which are scaled down less than
25% (actually this will prob. be more around 30-ish, due to palette
differences) you'll actually see the thumbnail being bigger in
*filesize* than the original (though smaller in memory-size)
- tul
P.S. isn't error_reporting( FATAL | ERROR | WARNING ); supposed to be
error_reporting( E_FATAL | E_ERROR | E_WARNING ); ??
tedd wrote:
Hi gang:
I have a thumbnail script, which does what it is supposed to do.
However, the thumbnail image generated is larger than the original
image, how can that be?
Here's the script working:
http://xn--ovg.com/thickbox
And, here's the script:
<?php /* thumb from file */
/* some settings */
ignore_user_abort();
set_time_limit( 0 );
error_reporting( FATAL | ERROR | WARNING );
/* security check */
ini_set( 'register_globals', '0' );
/* start buffered output */
ob_start();
/* some checks */
if ( ! isset( $_GET['s'] ) ) die( 'Source image not specified' );
$filename = $_GET['s'];
// Set a maximum height and width
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
// Output & Content type
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
/* end buffered output */
ob_end_flush();
?>
---
Thanks in advance for any comments, suggestions or answers.
tedd
--- End Message ---
--- Begin Message ---
Hi list,
Yesterday I noticed one of the sites I had created was running really slow.
Yet all the other sites on our webserver were running great. I had our
network admin look at the cpu, ram usage, etc of the webserver and
everything looked fine. Finally I just recommended we stick Xdebug on there
to find out what the exact problem was. It boiled down to my encryption
wrapper object. I guess there were too many MCrypt resources open at once.
I'm not really sure of the real problem, but when I switched around some
code to avoid unnecessarily loading initializing the resource, the site was
zippy again.
As I was developing locally everything was fine because it was just me
hitting the site. When I pushed it to the server though there was quite a
bit of traffic to it. So my question is, are there limits in PHP to how
many resources can be opened? What about limits to how many MCrypt
resources you can have open? This specific instance was a stupid mistake on
my part, but I just want to know for future reference.
Thanks!
--- End Message ---