php-general Digest 2 Dec 2008 17:39:37 -0000 Issue 5822
Topics (messages 283974 through 283997):
Re: Which is the right list?
283974 by: Chris
283977 by: Geek (de=German top level domain)
Re: Multiple MySQL INSERT
283975 by: Chris
283976 by: ddg2sailor
Re: question about corrupt db?
283978 by: Ashley Sheridan
283994 by: uaca man
array_intersect question
283979 by: Andrej Kastrin
283981 by: Yeti
283983 by: Tim | iHostNZ
283985 by: Andrej Kastrin
Re: How to hide MySQL password in connection string in PHP script?
283980 by: Yeti
283990 by: ceo.l-i-e.com
Re: XML RSS installation
283982 by: Richard Heyes
283991 by: ceo.l-i-e.com
283993 by: Richard Heyes
283995 by: ceo.l-i-e.com
283997 by: Richard Heyes
Re: category and sub category traversal
283984 by: Richard Heyes
283989 by: ceo.l-i-e.com
Short circuit evaluation and include
283986 by: Yeti
283992 by: ceo.l-i-e.com
Re: Countries and Timezones
283987 by: Per Jessen
Re: Voting methodology
283988 by: Al
How to type arguments
283996 by: Gautier Di Folco
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 ---
Geek (de=German top level domain) wrote:
Hi everyone,
Sorry for my stupidity, but I couldn't see which of the lists is the right
one to know about important news and or features that I might not think or
be aware about for PHP. I'm a PHP developer, mainly using the Symfony
framework and would like to know about important developments, new stuff and
interesting suggestions. This seems to be more of a "catch all" list.
This list is for "I have a problem, can someone help me" type questions.
If you want general announcements (new versions, stuff about security
issues I guess), join the announcements list
(http://www.php.net/mailing-lists.php).
For symfony, look at their site: http://www.symfony-project.org/community
If you want other general stuff, you can also look at
http://www.planet-php.net/ - it just aggregates a bunch of blogs.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Thanks for the prompt reply! I'll try and answer as many questions here as I
can. Maybe one of you can answer my questions then :)
On Tue, Dec 2, 2008 at 6:26 PM, Chris <[EMAIL PROTECTED]> wrote:
> Geek (de=German top level domain) wrote:
>
>> Hi everyone,
>>
>> Sorry for my stupidity, but I couldn't see which of the lists is the right
>> one to know about important news and or features that I might not think or
>> be aware about for PHP. I'm a PHP developer, mainly using the Symfony
>> framework and would like to know about important developments, new stuff
>> and
>> interesting suggestions. This seems to be more of a "catch all" list.
>>
>
> This list is for "I have a problem, can someone help me" type questions.
>
> If you want general announcements (new versions, stuff about security
> issues I guess), join the announcements list (
> http://www.php.net/mailing-lists.php).
>
> For symfony, look at their site: http://www.symfony-project.org/community
>
> If you want other general stuff, you can also look at
> http://www.planet-php.net/ - it just aggregates a bunch of blogs.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
--
Tim-Hinnerk Heuer
http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
--- End Message ---
--- Begin Message ---
ddg2sailor wrote:
Hi People
My real problem is that I dont know code. I can sort of edit it in a sloppy
more or less works fashion. Any help would be great.
This is the code Im having problems with:
//Example//
$id = 0 + $_GET["id"];
$md5 = $_GET["secret"];
$gig = 1;
$giveupload = $gig*1024*1024*1024;
$res = mysql_query("SELECT passhash, editsecret, status FROM users WHERE id
= $id");
$row = mysql_fetch_array($res);
$res = mysql_query("SELECT passhash, editsecret, status FROM users WHERE id
= $id");
$row = mysql_fetch_array($res);
I hope this is a copy/paste error or are you running the same thing twice?
mysql_query("UPDATE users SET status='confirmed', uploaded = $giveupload ");
This updates *every* user to have a confirmed status. Probably not what
you want.
Add a
WHERE id='X';
clause
//send pm to new user
{
$msg = sqlesc("Hello and welcome to Cyber Drive In you have been
given a 1gb head start to help your ratio. .we are a strict but fair site
and our warning are based on the torrent ratio not the global just because
you have a good ratio dont mean you can hit and run if you do hit and run
your downloads maybe disabled even if your global ratio is fine..so enjoy
our free 1gb gift rules are seed what you take or for 72 hours..plz read the
rules and facts now you have joined our friendly community");
$added = sqlesc(get_date_time());
$subject = sqlesc("Welcome to Cyber Drive In");
mysql_query("INSERT INTO messages (sender, receiver, subject, msg,
added) VALUES (0, $id, $subject, $msg, $added)");
What is the sqlesc function?
You need quotes around your values:
$sql = "insert into table(f1, f2, f3) values ('" .
mysql_real_escape_string($value_1) . "', '" .
mysql_real_escape_string($value_2) . "')";
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
chris smith-9 wrote:
>
> ddg2sailor wrote:
>> $row = mysql_fetch_array($res);
>
>> $res = mysql_query("SELECT passhash, editsecret, status FROM users WHERE
>> id
>> = $id");
>> $row = mysql_fetch_array($res);
>
> I hope this is a copy/paste error or are you running the same thing twice?
>
>
> I diddnt see that right away. In fact Im combining 2 pieces of code. The
> owner of this site dosent want to use a mail server and dosent want to do
> a manual confirm. So I added part of the confirm.php to the takesignup.php
> file....
>
>> mysql_query("UPDATE users SET status='confirmed', uploaded = $giveupload
>> ");
>
> This updates *every* user to have a confirmed status. Probably not what
> you want.
>
> Add a
>
> WHERE id='X';
>
> clause
>
> Believe me I agree with you... but this is how he wants it. It took me a
> while to realize that the new user cant call up the confirm.php without
> the mail with the link and the user name and secret word.
>
>> //send pm to new user
>>
>> {
>>
>> $msg = sqlesc("Hello and welcome to Cyber Drive In you have been
>> given a 1gb head start to help your ratio. .we are a strict but fair site
>> and our warning are based on the torrent ratio not the global just
>> because
>> you have a good ratio dont mean you can hit and run if you do hit and run
>> your downloads maybe disabled even if your global ratio is fine..so enjoy
>> our free 1gb gift rules are seed what you take or for 72 hours..plz read
>> the
>> rules and facts now you have joined our friendly community");
>> $added = sqlesc(get_date_time());
>> $subject = sqlesc("Welcome to Cyber Drive In");
>> mysql_query("INSERT INTO messages (sender, receiver, subject,
>> msg,
>> added) VALUES (0, $id, $subject, $msg, $added)");
>
> What is the sqlesc function?
>
> This is the way the code is when I got it. I think that this is how it
> reads from the array. I can see where a table might be more use here.
>
> You need quotes around your values:
>
> $sql = "insert into table(f1, f2, f3) values ('" .
> mysql_real_escape_string($value_1) . "', '" .
> mysql_real_escape_string($value_2) . "')";
>
> Im guessing that the preceding line got a bit chopped in the sending....
> at least it dosent look quite right as it is. If I cut and paste this back
> together I should be able to follow your convention.
>
> Thanks for your Reply... and if you saw the first post in this thread..
> sorry , shouldnt have clicked html and I should have previewed first.
>
> Regards
> Sailor
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--
View this message in context:
http://www.nabble.com/Multiple-MySQL-INSERT-tp20786333p20787487.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---
--- Begin Message ---
On Tue, 2008-12-02 at 01:14 +0000, Nathan Rixham wrote:
> Ashley Sheridan wrote:
> > On Mon, 2008-12-01 at 16:29 -0600, Terion Miller wrote:
> >>
> >> On Mon, Dec 1, 2008 at 4:20 PM, Ashley Sheridan
> >> <[EMAIL PROTECTED]> wrote:
> >>
> >> On Mon, 2008-12-01 at 15:53 -0600, Terion Miller wrote:
> >> > On Mon, Dec 1, 2008 at 3:40 PM, Wolf <[EMAIL PROTECTED]>
> >> wrote:
> >> >
> >> > >
> >> > >
> >> > > -----Original Message-----
> >> > > From: Terion Miller <[EMAIL PROTECTED]>
> >> > > Sent: Monday, December 01, 2008 4:23 PM
> >> > > To: Micah Gersten <[EMAIL PROTECTED]>
> >> > > Cc: PHP General <[EMAIL PROTECTED]>
> >> > > Subject: Re: [PHP] question about corrupt db?
> >> > >
> >> > > On Mon, Dec 1, 2008 at 3:12 PM, Micah Gersten
> >> <[EMAIL PROTECTED]> wrote:
> >> > >
> >> > > > Terion Miller wrote:
> >> > > > > could a corrupt db make php pages stop functioning?
> >> > > > > My pages no longer go anywhere, I went back found the
> >> original scripts
> >> > > > and
> >> > > > > still it didn't fix the problem (thought I had messed
> >> the code up) so
> >> > > it
> >> > > > has
> >> > > > > to be something external of the code its doing this
> >> locally on my box
> >> > > and
> >> > > > on
> >> > > > > the live server.
> >> > > > >
> >> > > > > thanks
> >> > > > > terion
> >> > > > >
> >> > > > >
> >> > > > Have you checked the PHP error logs?
> >> > > >
> >> > > > Thank you,
> >> > > > Micah Gersten
> >> > > > onShore Networks
> >> > > > Internal Developer
> >> > > > http://www.onshore.com
> >> > > >
> >> > > > I put this:
> >> > >
> >> > >
> >> > >
> >> > > > ini_set('error_reporting', E_ALL);
> >> > > > ini_set('display_errors', true);
> >> > >
> >> > > in the top of the pages but no errors are showing....
> >> > > ------
> >> > >
> >> > > Then that answer would be no....
> >> > >
> >> > > You need to actually look at your error logs as if the
> >> server is set up
> >> > > right it won,'t allow ini bypasses.
> >> > >
> >> > > Wolf
> >> > >
> >> > I can't find any error logs, I've looked in the inetpub
> >> folder, the php
> >> > folder the IIS services admin ....
> >>
> >>
> >> IIS has an option that lets you view the websites you have set
> >> up (I
> >> believe you can get to it from right-clicking My Computer and
> >> selecting
> >> Manage.) Select the site you are having problems with, and
> >> view the
> >> properties for it. One of the tabs (I forget which exactly)
> >> tells you
> >> where the error logs are for this site.
> >>
> >>
> >> Ash
> >> www.ashleysheridan.co.uk
> >>
> >>
> >> wow not there either, is it possible the person in this job before me
> >> just removed the logs and the servers capability to log? like there is
> >> no usr/bin/log file or anything like that (went to the apache site)
> >> and in the IIS install I went thru everything and can't find a thing
> >> about error logs...OMG pulling out my hair.
> > Well, /usr/bin/log is for Apache on Linux, so won't be of any use to you
> > with IIS on Windows!
> >
> > Stupid question, but have you searched for all *.log files? As far as I
> > know, you can't stop the server logging, and I think IIS locks the logs
> > to prevent accidental deletion. Generally speaking, the logs will be
> > pretty large files (depending on how busy your website is) if that helps
> > you narrow down your search.
> >
> >
> > Ash
> > www.ashleysheridan.co.uk
> >
>
> just turn display errors on and set reporting to E_ALL ? save mucking
> around (although it is normally a good idea to know where you're log
> files are) :p
>
If you read the thread, you'd know he's already tried that, and there's
some information you just don't get with E_ALL that you need to look at
the logs for.
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
To view the logs in IIS you must go to the root web site in the IIS
Snap in, virtual folders, folders and applications don't have a
separate log file. In the left panel in the snap in, right click in
the site, probably default web site, click on properties, look for a
tab called 'Web Site', in the bottom of the tab look for a checkbox
labeled "Enable Logs", mark it to enable logs, Click the properties
button and select the folder to store logs. Fallow the same path to
see where the logs are stored.
Hope it helps.
Uaca
2008/12/2 Ashley Sheridan <[EMAIL PROTECTED]>:
> On Tue, 2008-12-02 at 01:14 +0000, Nathan Rixham wrote:
>> Ashley Sheridan wrote:
>> > On Mon, 2008-12-01 at 16:29 -0600, Terion Miller wrote:
>> >>
>> >> On Mon, Dec 1, 2008 at 4:20 PM, Ashley Sheridan
>> >> <[EMAIL PROTECTED]> wrote:
>> >>
>> >> On Mon, 2008-12-01 at 15:53 -0600, Terion Miller wrote:
>> >> > On Mon, Dec 1, 2008 at 3:40 PM, Wolf <[EMAIL PROTECTED]>
>> >> wrote:
>> >> >
>> >> > >
>> >> > >
>> >> > > -----Original Message-----
>> >> > > From: Terion Miller <[EMAIL PROTECTED]>
>> >> > > Sent: Monday, December 01, 2008 4:23 PM
>> >> > > To: Micah Gersten <[EMAIL PROTECTED]>
>> >> > > Cc: PHP General <[EMAIL PROTECTED]>
>> >> > > Subject: Re: [PHP] question about corrupt db?
>> >> > >
>> >> > > On Mon, Dec 1, 2008 at 3:12 PM, Micah Gersten
>> >> <[EMAIL PROTECTED]> wrote:
>> >> > >
>> >> > > > Terion Miller wrote:
>> >> > > > > could a corrupt db make php pages stop functioning?
>> >> > > > > My pages no longer go anywhere, I went back found the
>> >> original scripts
>> >> > > > and
>> >> > > > > still it didn't fix the problem (thought I had messed
>> >> the code up) so
>> >> > > it
>> >> > > > has
>> >> > > > > to be something external of the code its doing this
>> >> locally on my box
>> >> > > and
>> >> > > > on
>> >> > > > > the live server.
>> >> > > > >
>> >> > > > > thanks
>> >> > > > > terion
>> >> > > > >
>> >> > > > >
>> >> > > > Have you checked the PHP error logs?
>> >> > > >
>> >> > > > Thank you,
>> >> > > > Micah Gersten
>> >> > > > onShore Networks
>> >> > > > Internal Developer
>> >> > > > http://www.onshore.com
>> >> > > >
>> >> > > > I put this:
>> >> > >
>> >> > >
>> >> > >
>> >> > > > ini_set('error_reporting', E_ALL);
>> >> > > > ini_set('display_errors', true);
>> >> > >
>> >> > > in the top of the pages but no errors are showing....
>> >> > > ------
>> >> > >
>> >> > > Then that answer would be no....
>> >> > >
>> >> > > You need to actually look at your error logs as if the
>> >> server is set up
>> >> > > right it won,'t allow ini bypasses.
>> >> > >
>> >> > > Wolf
>> >> > >
>> >> > I can't find any error logs, I've looked in the inetpub
>> >> folder, the php
>> >> > folder the IIS services admin ....
>> >>
>> >>
>> >> IIS has an option that lets you view the websites you have set
>> >> up (I
>> >> believe you can get to it from right-clicking My Computer and
>> >> selecting
>> >> Manage.) Select the site you are having problems with, and
>> >> view the
>> >> properties for it. One of the tabs (I forget which exactly)
>> >> tells you
>> >> where the error logs are for this site.
>> >>
>> >>
>> >> Ash
>> >> www.ashleysheridan.co.uk
>> >>
>> >>
>> >> wow not there either, is it possible the person in this job before me
>> >> just removed the logs and the servers capability to log? like there is
>> >> no usr/bin/log file or anything like that (went to the apache site)
>> >> and in the IIS install I went thru everything and can't find a thing
>> >> about error logs...OMG pulling out my hair.
>> > Well, /usr/bin/log is for Apache on Linux, so won't be of any use to you
>> > with IIS on Windows!
>> >
>> > Stupid question, but have you searched for all *.log files? As far as I
>> > know, you can't stop the server logging, and I think IIS locks the logs
>> > to prevent accidental deletion. Generally speaking, the logs will be
>> > pretty large files (depending on how busy your website is) if that helps
>> > you narrow down your search.
>> >
>> >
>> > Ash
>> > www.ashleysheridan.co.uk
>> >
>>
>> just turn display errors on and set reporting to E_ALL ? save mucking
>> around (although it is normally a good idea to know where you're log
>> files are) :p
>>
> If you read the thread, you'd know he's already tried that, and there's
> some information you just don't get with E_ALL that you need to look at
> the logs for.
>
>
> Ash
> www.ashleysheridan.co.uk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Dear all,
I have to perform an intersection on array of arrays. The fact is that
php does not support intersection on multidimensional arrays.
So, the first simple example using only one dimensional arrays works well:
$array1 = array("green", "red", "blue");
$array2 = array("green", "yellow", "red");
$array3 = array("green", "red", "purple");
$array4 = array("green","red","yellow");
$result = array_intersect($array1,$array2,$array3,$array4);
print_r($result);
And the result is: Array ( [0] => green [1] => red )
The question is how to perform intersection on the following structure:
$products =
array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
Thanks in advance for any suggestions.
Best, Andrej
--- End Message ---
--- Begin Message ---
> The question is how to perform intersection on the following structure:
>
> $products =
> array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
If I understood you correctly ..
<?php
$arr = array();
$arr[] = array("green", "red", "blue");
$arr[] = array("green", "yellow", "red");
$arr[] = array("green", "red", "purple");
$arr[] = array("green","red","yellow");
var_dump($arr);
// you could also ..
$arr = array();
array_push(
$arr, array("green", "red", "blue"),
array("green", "yellow", "red"),
array("green", "red", "purple"),
array("green","red","yellow")
);
var_dump($arr);
?>
--- End Message ---
--- Begin Message ---
I know there must be a more elegant way with array_reduce or something, but
I would simply write a function called
function array_intersect_m($m_array) {
$intersection = $m_array[0];
for ($i=1; $i < count($m_array); $i++) {
$intersection = array_intersect($m_array[$i], $intersection);
}
return $intersection;
}
and put that into my library. O and while i'm at it, the array_reduce way
would prob be:
$m_array =
array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
array_reduce($m_array, 'array_intersect');
but this could be wrong, havent done much with these 'meta' functions.
Regards,
Tim
On Tue, Dec 2, 2008 at 10:24 PM, Andrej Kastrin <[EMAIL PROTECTED]>wrote:
> Dear all,
>
> I have to perform an intersection on array of arrays. The fact is that php
> does not support intersection on multidimensional arrays.
>
> So, the first simple example using only one dimensional arrays works well:
>
> $array1 = array("green", "red", "blue");
> $array2 = array("green", "yellow", "red");
> $array3 = array("green", "red", "purple");
> $array4 = array("green","red","yellow");
> $result = array_intersect($array1,$array2,$array3,$array4);
> print_r($result);
>
> And the result is: Array ( [0] => green [1] => red )
>
> The question is how to perform intersection on the following structure:
>
> $products =
> array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
>
> Thanks in advance for any suggestions.
>
> Best, Andrej
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Tim-Hinnerk Heuer
http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
--- End Message ---
--- Begin Message ---
It works like a charm.
Thanks, Andrej
Tim | iHostNZ wrote:
I know there must be a more elegant way with array_reduce or something, but
I would simply write a function called
function array_intersect_m($m_array) {
$intersection = $m_array[0];
for ($i=1; $i < count($m_array); $i++) {
$intersection = array_intersect($m_array[$i], $intersection);
}
return $intersection;
}
and put that into my library. O and while i'm at it, the array_reduce
way would prob be:
$m_array =
array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
array_reduce($m_array, 'array_intersect');
but this could be wrong, havent done much with these 'meta' functions.
Regards,
Tim
On Tue, Dec 2, 2008 at 10:24 PM, Andrej Kastrin
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:
Dear all,
I have to perform an intersection on array of arrays. The fact is
that php does not support intersection on multidimensional arrays.
So, the first simple example using only one dimensional arrays works
well:
$array1 = array("green", "red", "blue");
$array2 = array("green", "yellow", "red");
$array3 = array("green", "red", "purple");
$array4 = array("green","red","yellow");
$result = array_intersect($array1,$array2,$array3,$array4);
print_r($result);
And the result is: Array ( [0] => green [1] => red )
The question is how to perform intersection on the following structure:
$products =
array(array("green","red","blue"),array("green","yellow","red"),array("green","red","purple"),array("green","red","yellow"));
Thanks in advance for any suggestions.
Best, Andrej
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Tim-Hinnerk Heuer
http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
--- End Message ---
--- Begin Message ---
"Robert Dodier" robert_dodier AT yahoo.com wrote on 12-21-2003
> Hello,
>
> I am experimenting with a wiki system (PhpWiki) which uses
> a MySQL database to store pages. It seems like a great system.
>
> The MySQL connection string is specified in a PHP script
> in the form "mysql://FOO:[EMAIL PROTECTED]/baz".
>
> If I'm not mistaken the script has to be world-readable.
> But then, can't any other user (logged in to the host)
> just read the password?
>
> I share the host with other users, and the script has to
> be in my home directory, so I don't think I can guarantee
> that no other user can see it.
>
> Thanks for any advice,
>
> Robert Dodier
I recently had the same problem on a shared host. The only solution I
could think of was to have the server admin set an environment
variable in an httpd.conf include file owned by root (chmod 600)
[1].
EXAMPLE (mysql_pw.conf):
SetEnv mysql_pw password
SetEnv mysql_user username
In PHP the variables then should end up in the $_SERVER array ...
EXAMPLE (PHP):
<?php
var_dump($_SERVER['mysql_pw'], $_SERVER['mysql_user']);
?>
If this is impossible I can't think of another secure way on shared
host systems, since other hosts usually are able to read your files.
Maybe (if supported) one could SetEnv in .htaccess, so an attacker
would at least have to glance into the PHP source code to find out
where the password is stored.
Still most people have it inside an include file and it works, I think.
[1] http://httpd.apache.org/docs/1.3/mod/mod_env.html
--- End Message ---
--- Begin Message ---
On a shared server, you rarely can really protect your MySQL user/pass from
other users on the same server.
The problem is that your PHP process is probably an Apache module, and you
probably don't have your own separate pool of Apache User processes.
So, by definition, if YOUR script can read the .php file and load it and get
the user/pass to use them, then ANY .php file can load the file and get the
user/pass to abuse them.
You have to weigh this risk with the value/secrecy/privacy of the data, and
decide what to do.
You might have to move to a dedicated server. You might not.
You might just add a barrier for the absolutely crucial fields of 2-way
encrypting them in PHP. Of course, the bad person can then read your other
.php file to find the 2-way de-cryption, but it's more steps for them to go
through, and if the data isn't THAT interesting, they won't.
You would NOT want to do this for:
credit card info (which probably doesn't need storing anyway)
SSN
medical info
But you might not care all THAT much for yet another shopping cart or a blog
etc.
Keep backups though, just in case a rogue user does mess you up!
--- End Message ---
--- Begin Message ---
> What do you mean by replicating the directory structure?
PEAR has a directory structure. Duplicate it and set you include_path
accordingly. Have a look at the application structure on article my
website ( http://www.phpguru.org ) - it may be of some help.
Eg:
htdocs <-- This the document root of your website
pear
+ HTML
+ Mail
+ Net
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 29th)
--- End Message ---
--- Begin Message ---
> htdocs <-- This the document root of your website pear + HTML + Mail
> + Net
If you're going to set your include path properly, you might as well not put
PEAR in htdocs, since none of those files are front-facing URLs that should be
visited by an end user.
They belong in a non web root directory "somewhere else" to insure that there
is NO WAY EVER that they could be visited directly by a malicious user.
--- End Message ---
--- Begin Message ---
>> htdocs <-- This the document root of your website pear + HTML + Mail
>> + Net
That's not what I wrote:
htdocs <-- This the document root of your website
pear
+ HTML
+ Mail
+ Net
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 29th)
--- End Message ---
--- Begin Message ---
>>> htdocs <-- This the document root of your website pear + HTML +
>>> Mail
>>> + Net
>
>That's not what I wrote:
>
>htdocs <-- This the document root of your website pear + HTML + Mail
> + Net
I apologize for the misunderstanding.
--- End Message ---
--- Begin Message ---
> I apologize for the misunderstanding.
That's OK, I forgive you my child. :-)
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 29th)
--- End Message ---
--- Begin Message ---
> I need some help in figuring out this logic.
>
> I have two tables one for category and other for category_hierarchy.
> category_hirerarchy has a column to determine the parent.
>
> So the query I have to retrieve tree of one specific category is:
>
> SELECT t.tid, t.*, parent FROM term_data t INNER JOIN term_hierarchy h ON
> t.tid = h.tid WHERE t.vid = 16 ORDER BY weight, name;
>
> The ones with parent = 0 is the top category
>
> Now I need to prepare an associative array with parent child relation.
>
> So bascially I need to retrieve [parentID] => array('childID', 'chidName')
>
> Can anyone shed some light on the logic involved in preparation of this
> array with out using multiple sql queries?
The structure you've highlighted is very common (that's not to say bad
at all). You might be interested in this:
http://www.phpguru.org/downloads/Tree_array/Tree.phps Which looks at
the same structure and creates a tree object from it. Using this you
will be able to manage it.
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 29th)
--- End Message ---
--- Begin Message ---
Google for "SELF JOIN"
You also may want to just put the parent_id in the category table, rather than
a second table.
Your query would then look like this:
select parent.tid, child.tid
from term_data as parent, term_data as child
where child.parent_id = parent.tid
and child.vid = 16
order by weight, name
WARNING:
If term_data is a LARGE table, this query could become problematic.
You'll need an index on (tid, vid, weight, name), I think.
Follow-up with more questions to the MySQL (or other SQL) mailing list please,
as there's no actual PHP in this question.
--- End Message ---
--- Begin Message ---
Hello everyone,
I'm posting this as a warning when using include() or include_once()
and checking their return values.
I'm refactoring someone else's code at the moment and got a short
circuit evaluation problem that made some problems ..
Here's the code:
FILE "some_file.php":
<?php
function some_function($file) {
$obj = false;
if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !include_once($file)
|| !class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj->some_method()
) return false; // line 14
return $obj;
}
$file = 'some_class.php';
some_function($file);
?>
FILE "some_class.php":
<?php
class some_class {
function some_method() {
return true;
}
}
?>
ERRORS PRODUCED:
Warning: some_function(1) [function.some-function]: failed to open
stream: No such file or directory in */some_file.php on line 14
Warning: some_function() [function.include]: Failed opening '1' for
inclusion (include_path='.;*/php/pear/') in */some_file.php on line 14
Note: I ran this code in PHP 4.4.9
It seemed to me like include_once() was not fully executed or
something when "short circuited", because this code worked just fine
...
FILE "some_file.php":
<?php
function some_function($file) {
$obj = false;
if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !include_once($file)
) return false;
if (
!class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj->some_method()
) return false;
return $obj;
}
$file = 'some_class.php';
var_dump(some_function($file));
?>
OUTPUT:
object(some_class)(0) {
}
So I was wondering how include() or include_once() are actually being
executed. I know they both return int(1) if no return specified in the
included file.
That's why I had a glance at the manual [1], where I saw this ..
Because include() is a special language construct, parentheses are not
needed around its argument. Take care when comparing return value.
Example #4 Comparing return value of include
<?php
// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
echo 'OK';
}
// works
if ((include 'vars.php') == 'OK') {
echo 'OK';
}
?>
So when I added the paranthesis it worked ...
FILE "some_file.php":
<?php
function some_function($file) {
$obj = false;
if (
!isset($file)
|| !is_string($file)
|| !is_readable($file)
|| !(include_once($file)) // <--- added paranthesis
|| !class_exists('some_class')
|| !is_a(($obj = new some_class()), 'some_class')
|| !method_exists($obj, 'some_method')
|| !$obj->some_method()
) return false;
return $obj;
}
$file = 'some_class.php';
var_dump(some_function($file));
?>
Me, after an hour of coding without a line of code.
[1] http://in.php.net/manual/en/function.include.php
--- End Message ---
--- Begin Message ---
include and require are not functions.
They are language constructs.
They probably don't "return values" nor short-circuit in the usual way.
Ditto for "echo"
If you can strip the parens and have it still work, it's for sure not a
function.
<?php
include_once $file;
echo $file;
?>
is perfectly valid code.
PS
All those disk calls are going to get pretty expensive if your site gets heavy
traffic...
You may want to just write a custom error_handler and use include_once which
will let you trap the error and do something intelligent with it...
--- End Message ---
--- Begin Message ---
franzemmanuel wrote:
> Hi everybody,
>
> For those who are interested in Countries and timezones.
>
> I needed to have the list of all the countries in the world and the
> timezones by country without redundancy.
>
Couldn't you just have use the timezone info from mysql?
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Shawn McKenzie wrote:
tedd wrote:
Hi gang:
What methodology would be the best for online voting?
I have a client who is a Union and they want members to vote online, but
don't want someone to stuff the voting box.
I have some ideas of my own, but would like to hear what you people
would recommend.
Cheers,
tedd
Being a union I would expect that they want "some way" to control the
stuffing to their advantage. :-)
Also, don't forget to insure the is NO audit trail. e.g., all champaign contributions less than
$200, even for some credit cards that post $199 1000 times.
--- End Message ---
--- Begin Message ---
Hello,
I'm a french student, sorry for my mail :
I want to know how can I type my functions' arguments ?
It is heavy to do :
function post($id)
{
$id=(int)$id;
//...
or tu put (int) before each use...
Thank you for your help
_________________________________________________________________
Email envoyé avec Windows Live Hotmail. Dites adieux aux spam et virus, passez
à Hotmail ! C'est gratuit !
http://www.windowslive.fr/hotmail/default.asp
--- End Message ---