php-general Digest 3 Jan 2005 02:48:04 -0000 Issue 3205
Topics (messages 205472 through 205486):
critique this code please
205472 by: Sebastian
205473 by: M. Sokolewicz
205485 by: Rory Browne
function problem
205474 by: Viktor Popov
205475 by: Ligaya Turmelle
How to enable ftp in php5?
205476 by: Jerry Swanson
205481 by: Rory Browne
compiling PHP error, please help (configure: error: libjpeg.(a|so) not found.)
205477 by: Aaron Paulley
205483 by: Rasmus Lerdorf
205484 by: Jason Wong
Is there any way that PHP will issue a warning when using undeclared vars?
205478 by: Dan Eloff
205479 by: Comex
205480 by: Rory Browne
205482 by: Dan Eloff
Re: php vs java....
205486 by: GH
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 ---
i have this small function for a template system (if you want to call it
that ;)
my idea was having something simple to separate html code from php and i
think using something like smarty is too big for me and i really dont have
time to learn to use it. so i have this code here:
http://www.cstrike-planet.com/function.phps
i call this function which reads .tpl files which contain html and some
$vars, then in my pages use something like:
eval('echo("' . template('home_index') . '");');
unfortunaly my site has grown since and im not sure if this is causing an
extra overhead on the site..
is there a way to 'improve' this small function?
thanks for any help.
--- End Message ---
--- Begin Message ---
Sebastian wrote:
i have this small function for a template system (if you want to call it
that ;)
my idea was having something simple to separate html code from php and i
think using something like smarty is too big for me and i really dont have
time to learn to use it. so i have this code here:
http://www.cstrike-planet.com/function.phps
i call this function which reads .tpl files which contain html and some
$vars, then in my pages use something like:
eval('echo("' . template('home_index') . '");');
unfortunaly my site has grown since and im not sure if this is causing an
extra overhead on the site..
is there a way to 'improve' this small function?
thanks for any help.
sure it has some overhead. However, you'd need a seriously large site to
even notice it. The same way of templating is used by XMB (a message
board system). It's quite widespread, and some of the boards are quite
large, generating a lot of traffic, and are heavily used. However, such
a relativly small thing doesn't have that big an impact on speed AFAICS :)
--- End Message ---
--- Begin Message ---
Nothing too serious, but saying as you did ask for a critique, I'll
tell you things I'd have done differently. That DOES NOT necessarly
mean that my way is better than yours, but may be something you need
to take into consideration.
// #################### TEMPLATE ####################
function template($templatename)
{
// I can't imagine $templatecache being used outside of this
function, so I'd
// personally declare it static, instead of global, to avoid
poluting the namespace.
// Personally I generally avoid globals except for configuration variables.
global $templatecache, $setting;
// Personally I'd just if($templatecache[$templatename]), without the != ''
// What type of error reporting are you using? You may want to
consider simply
// checking if $templatecache contains a key called $templatename to avoid
// E_NOTICE, using array_key_exists(), or perhaps isset()
if ($templatecache[$templatename] != '')
{
$template = $templatecache[$templatename];
}
else
{
// consider the use file_get_contents(); I'm surprised at
your use of the error
// suppression operator. I know its good security practice not
to show errors, but
// logging them can often be helpful.
// adding or die('some useful, debugging error message'), may
help debugging.
// perhaps or die($setting['debugtemplate'] ? "template
$templatename failed to open" : "") would only display the error
whilst $setting['debugtemplate'] is set.
$fetchfile = @fopen('/templates/' . $templatename . '.tpl', 'r');
$template = @fread($fetchfile, filesize('/templates/' .
$templatename . '.tpl'));
@fclose($fetchfile);
$templatecache[$name] = $template;
// why are you adding slashes and immediately removing them again?
// perhaps you only want to slash the double quotes, and backslashes?
// $template = str_replace(array('"', '\'), array('\"', '\\'),
$template);
$template = addslashes($template);
$template = str_replace("\\'", "'", $template);
// just for the sake of making the code easier to read, I'd
if ($setting['debugtemplate'])
{
return "<!-- S:DEBUG:Template: $templatename
-->\n$template\n<!-- E:DEGUG:Template: $templatename -->";
}
}
return $template;
}
##########################################
Having that said I'd try to flatten down the if's a bit. Most of your
code is in an else block. Personally I'd probably do something like.
PLEASE REMEMBER THAT IM NOT SUGGESTING THAT MY WAY IS BETTER THAN
YOURS This is just food for thought.
function template($template_name){
$return_format = $setting['debug_template'] ? "<!-- debug_info
-->%s<!--end debug_info -->" : "%s";
if($template = $template_cache[$template_name]){
return sprintf($template_format, $template);
}
$template = read_template_from_file_and_process_it($template_name);
$template_cache = $template;
return sprintf($template_format, $template);
}
#####################################
One more thing: $template_name, or $TemplateName, or $templateName is
easier to read, than $templatename
On Sun, 02 Jan 2005 20:19:06 +0100, M. Sokolewicz <[EMAIL PROTECTED]> wrote:
> Sebastian wrote:
>
> > i have this small function for a template system (if you want to call it
> > that ;)
> >
> > my idea was having something simple to separate html code from php and i
> > think using something like smarty is too big for me and i really dont have
> > time to learn to use it. so i have this code here:
> >
> > http://www.cstrike-planet.com/function.phps
> >
> > i call this function which reads .tpl files which contain html and some
> > $vars, then in my pages use something like:
> >
> > eval('echo("' . template('home_index') . '");');
> >
> > unfortunaly my site has grown since and im not sure if this is causing an
> > extra overhead on the site..
> > is there a way to 'improve' this small function?
> >
> > thanks for any help.
> sure it has some overhead. However, you'd need a seriously large site to
> even notice it. The same way of templating is used by XMB (a message
> board system). It's quite widespread, and some of the boards are quite
> large, generating a lot of traffic, and are heavily used. However, such
> a relativly small thing doesn't have that big an impact on speed AFAICS :)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi,
I'm trying to do the following but I don't have any success. Could you help
me here...
I have this code in mu page:
<?php
include "script/functions.php";
require 'script/common.inc';
$valid = TRUE;
if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
$$key = $value;
}
$valid = $fn = checkLength($fname, 2, 50);
$ln = checkLength($family, 2, 50);
$valid = $valid && $ln;
$cm = checkLength($company,0,50);
$valid = $valid && $cm;
$ml = checkLength($MOL,0,50);
$valid = $valid && $ml;
$dnum = checkLength($dannum,0,12);
$valid = $valid && $dnum;
$bst = checkLength($bulstat,0,12);
$valid = $valid && $bst;
$phn = checkLength($phone,3,20);
$valid = $valid && $phn;
$em = checkEmail($email);
$valid = $valid && $em;
$usr = checkLength($username,4,10);
$valid = $valid && $usr;
$ps = checkLength($password,4,16);
$valid = $valid && $ps;
$ps2 = checkLength($password2,4,16);
$valid = $valid && $ps2;
$ps2 = $password == $password2;
$valid = $valid && $ps2;
$adr = checkLength($Addr,3,70);
$valid = $valid && $adr;
$cty = checkLength($City,2,50);
$valid = $valid && $cty;
$zp = checkLength($zipcode,2,10);
$valid = $valid && $zp;
if ($valid) { //-----------------------------------------CHECK
THIS-------------------------------
doReg($fname,$family,$company, $MOL, $dannum, $bulstat,
$phone, $email, $username, $password, $payment, $maillist, $Addr, $City,
$zipcode,
$Country, $shippingName, $shippingFamily, $shippingphone, $shippingAddr,
$shippingcity, $shippingzipcode, $shippingCountry);
exit;
}
} else {
$fn = $ln = $cm = $ml = $dnum = $bst = $phn = $em = $usr = $ps = $ps2 =
$adr = $cty = $zp = TRUE;
$fname = $family = $company = $MOL = $dannum = $bulstat = $phone =
$email = $username = $password = $password2 = $Addr = $City = $zipcode = '';
}
?>
This is a page with validation. If everything is correct($valid==TRUE), I
would like to call doReg which must do the following:
function doReg($fname1="",$family1="",$company1="", $MOL1="", $dannum1="",
$bulstat1="", $phone1="", $email1="", $username1="", $password1="",
$payment1="", $maillist1="", $Addr1="", $City1="", $zipcode1="",
$Country1="", $shippingName1="", $shippingFamily1="", $shippingphone1="",
$shippingAddr1="", $shippingcity1="", $shippingzipcode1="",
$shippingCountry1="")
{
mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD);
mysql_db_query($DB, "insert into users(name,family,company, MOL, taxnum,
bulstat, phone, email, username, password, payment, maillist, Addr, City,
zipcode, Country, shippingName, shippingFamily, shippingphone, shippingAddr,
shippingcity, shippingzipcode, shippingCountry)
values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
'$phone1', '$email1', '$username1', '$password1', '$payment1', '$maillist1',
'$Addr1', '$City1', '$zipcode1',
'$Country1','$shippingName1','$shippingFamily1',
'$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
'$shippingCountry1')");
}
The problem is that it doesn't work. I have tryed to put the code from the
doReg function in the page and it works. But when I call the function I
can't insert nothing. Why is that? could you tell me?
Thank you in advance!!
Viktor
--- End Message ---
--- Begin Message ---
Are you getting an error? If so what does it say. Also in your code you
have nothing to tell you if something is going wrong. Use echo
statements - say something if the connection or the query doesn't go
through. Also noticed that when you made the connection to the DB you
didn't assign it to a variable, but in the query you use $DB as the link.
Ex:
$DB = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD);
if (!$DB)
{
// remove in production or have it sent to a log.
echo 'Failed to connect to the DB';
}
You can do the same thing for the query.
Respectfully,
Ligaya Turmelle
Viktor Popov wrote:
Hi,
I'm trying to do the following but I don't have any success. Could you help
me here...
I have this code in mu page:
<?php
include "script/functions.php";
require 'script/common.inc';
$valid = TRUE;
if (isset ($_POST['submit'])) {
foreach($_POST as $key=>$value) {
$$key = $value;
}
$valid = $fn = checkLength($fname, 2, 50);
$ln = checkLength($family, 2, 50);
$valid = $valid && $ln;
$cm = checkLength($company,0,50);
$valid = $valid && $cm;
$ml = checkLength($MOL,0,50);
$valid = $valid && $ml;
$dnum = checkLength($dannum,0,12);
$valid = $valid && $dnum;
$bst = checkLength($bulstat,0,12);
$valid = $valid && $bst;
$phn = checkLength($phone,3,20);
$valid = $valid && $phn;
$em = checkEmail($email);
$valid = $valid && $em;
$usr = checkLength($username,4,10);
$valid = $valid && $usr;
$ps = checkLength($password,4,16);
$valid = $valid && $ps;
$ps2 = checkLength($password2,4,16);
$valid = $valid && $ps2;
$ps2 = $password == $password2;
$valid = $valid && $ps2;
$adr = checkLength($Addr,3,70);
$valid = $valid && $adr;
$cty = checkLength($City,2,50);
$valid = $valid && $cty;
$zp = checkLength($zipcode,2,10);
$valid = $valid && $zp;
if ($valid) { //-----------------------------------------CHECK
THIS-------------------------------
doReg($fname,$family,$company, $MOL, $dannum, $bulstat,
$phone, $email, $username, $password, $payment, $maillist, $Addr, $City,
$zipcode,
$Country, $shippingName, $shippingFamily, $shippingphone, $shippingAddr,
$shippingcity, $shippingzipcode, $shippingCountry);
exit;
}
} else {
$fn = $ln = $cm = $ml = $dnum = $bst = $phn = $em = $usr = $ps = $ps2 =
$adr = $cty = $zp = TRUE;
$fname = $family = $company = $MOL = $dannum = $bulstat = $phone =
$email = $username = $password = $password2 = $Addr = $City = $zipcode = '';
}
?>
This is a page with validation. If everything is correct($valid==TRUE), I
would like to call doReg which must do the following:
function doReg($fname1="",$family1="",$company1="", $MOL1="", $dannum1="",
$bulstat1="", $phone1="", $email1="", $username1="", $password1="",
$payment1="", $maillist1="", $Addr1="", $City1="", $zipcode1="",
$Country1="", $shippingName1="", $shippingFamily1="", $shippingphone1="",
$shippingAddr1="", $shippingcity1="", $shippingzipcode1="",
$shippingCountry1="")
{
mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD);
mysql_db_query($DB, "insert into users(name,family,company, MOL, taxnum,
bulstat, phone, email, username, password, payment, maillist, Addr, City,
zipcode, Country, shippingName, shippingFamily, shippingphone, shippingAddr,
shippingcity, shippingzipcode, shippingCountry)
values('$fname1','$family1','$company1', '$MOL1', '$dannum1', '$bulstat1',
'$phone1', '$email1', '$username1', '$password1', '$payment1', '$maillist1',
'$Addr1', '$City1', '$zipcode1',
'$Country1','$shippingName1','$shippingFamily1',
'$shippingphone1','$shippingAddr1', '$shippingcity1', '$shippingzipcode1',
'$shippingCountry1')");
}
The problem is that it doesn't work. I have tryed to put the code from the
doReg function in the page and it works. But when I call the function I
can't insert nothing. Why is that? could you tell me?
Thank you in advance!!
Viktor
--- End Message ---
--- Begin Message ---
How I can enable php in FTP 5? What I should change in PHP.INI file?
Thanks
--- End Message ---
--- Begin Message ---
depends on where you got PHP. If you compiled from source then you
need to add --with-ftp or --enable-ftp in your ./configure command. Do
a ./configure --help to find out more, ie which one.
If you got it with an RPM based linux distro, then you probably need
to install a php-ftp rpm.
Oh, and shouldn't that be FTP in PHP 5?
If all you need to do is change something in PHP.ini, look for a line
with ;extension=ftp.so or ;extension=ftp.dll under windos, and remove
the ;.
What OS are you running, and where did you get PHP?
On Mon, 3 Jan 2005 00:01:25 +0000, Jerry Swanson <[EMAIL PROTECTED]> wrote:
> How I can enable php in FTP 5? What I should change in PHP.INI file?
>
> Thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
The error I'm getting when running ./configure is this:
configure: error: libjpeg.(a|so) not found.
I know libjpeg is installed, I just installed it. Here is my ./configure:
./configure --with-mysql --with-apxs=/www/bin/apxs --with-xml
--enable-ftp --with-gd --enable-magic-quotes --with-jpeg-dir=/usr/lib
--with-mcrypt --with-png-dir=/usr --enable-sockets --enable-track-vars
--enable-versioning --with-zlib --enable-bcmath --enable-calendar
--with-xpm-dir=/usr/X11R6
Side question - if there's anything I'm missing in my ./configure that
I should have in it, please let me know. This is my first from-scratch
PHP install.
--- End Message ---
--- Begin Message ---
Aaron Paulley wrote:
The error I'm getting when running ./configure is this:
configure: error: libjpeg.(a|so) not found.
I know libjpeg is installed, I just installed it. Here is my ./configure:
./configure --with-mysql --with-apxs=/www/bin/apxs --with-xml
--enable-ftp --with-gd --enable-magic-quotes --with-jpeg-dir=/usr/lib
--with-mcrypt --with-png-dir=/usr --enable-sockets --enable-track-vars
--enable-versioning --with-zlib --enable-bcmath --enable-calendar
--with-xpm-dir=/usr/X11R6
Why did you use /usr/lib for jpeg but /usr for png? /usr is correct.
-Rasmus
--- End Message ---
--- Begin Message ---
On Monday 03 January 2005 08:18, Aaron Paulley wrote:
> The error I'm getting when running ./configure is this:
>
> configure: error: libjpeg.(a|so) not found.
>
>
> I know libjpeg is installed, I just installed it. Here is my ./configure:
Assuming that you have installed it in a fairly standard location then ...
> --with-jpeg-dir=/usr/lib
... that should be
--with-jpeg-dir=/usr
> Side question - if there's anything I'm missing in my ./configure that
> I should have in it, please let me know.
That would depend entirely on what extensions you require. If this is for a
production machine then it would be useful to have:
--enable-memory-limit
and enforce it in php.ini.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
In Seattle, Washington, it is illegal to carry a concealed weapon that
is over six feet in length.
*/
--- End Message ---
--- Begin Message ---
My single biggest beef with PHP is the fact that it silently fails
when I use a variable that has never been declared. Like if($sumbit)
will always be false because the variable was really named $submit. My
only clue that this is happening is whe the program fails to work as
intended and I waste lots of time trying to find out why the block
never executes.
Or if you forget to use $this->var and you just use $var. I just had
that happen to me too. Wasted another 30 min.
Is there any way at all to control this? I went into my PHP.ini file,
but my errors are set to E_ALL & E_STRICT which seems to be the
highest level I can set.
If not I think we should seriously push for E_STRICT warnings if a
variable is used without every being assigned to.
Happy New Year All
-Dan
--- End Message ---
--- Begin Message ---
> Is there any way at all to control this? I went into my PHP.ini file,
> but my errors are set to E_ALL & E_STRICT which seems to be the
> highest level I can set.
That error generates an E_NOTICE.
--- End Message ---
--- Begin Message ---
Unless I'm mistaken, which is quite possible considering that its been
years since I set my error_level, to anything other than E_ALL, but I
think you need to 'bitwise or' the error_levels instead of 'bitwise
and' them.
The default setting IIRC is E_ALL & ~E_NOTICE, which means all errors
except E_NOTICE. I think what you're looking for is simply E_ALL, but
so long as it can emit E_NOTICE's you should be okay.
On Sun, 2 Jan 2005 16:23:34 -0800, Dan Eloff <[EMAIL PROTECTED]> wrote:
> My single biggest beef with PHP is the fact that it silently fails
> when I use a variable that has never been declared. Like if($sumbit)
> will always be false because the variable was really named $submit. My
> only clue that this is happening is whe the program fails to work as
> intended and I waste lots of time trying to find out why the block
> never executes.
>
> Or if you forget to use $this->var and you just use $var. I just had
> that happen to me too. Wasted another 30 min.
>
> Is there any way at all to control this? I went into my PHP.ini file,
> but my errors are set to E_ALL & E_STRICT which seems to be the
> highest level I can set.
>
> If not I think we should seriously push for E_STRICT warnings if a
> variable is used without every being assigned to.
>
> Happy New Year All
> -Dan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
I knew I missed something when I configured php 5 on my pc. I forgot
to set the errors to be printed instead of logged. And you're right, I
should have used bitwise or to combine the flags. Thanks, you guys
saved me a lot of aggravation.
-Dan
--- End Message ---
--- Begin Message ---
Can you please explain Threads to me?
On Sat, 1 Jan 2005 14:38:50 -0600, Greg Donald <[EMAIL PROTECTED]> wrote:
> On Sat, 1 Jan 2005 10:07:20 -0800 (PST), Lewis LaCook <[EMAIL PROTECTED]>
> wrote:
> > ...just looking for opinions: will PHP eclipse (IS PHP
> > eclipsing) Java?
>
> I'd like to see threads added to PHP. Java has them, and Perl does as
> well. And I'm sure there are others that I don't know about.
>
> --
> Greg Donald
> Zend Certified Engineer
> http://gdconsultants.com/
> http://destiney.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---