php-general Digest 10 Oct 2006 14:05:57 -0000 Issue 4393

2006-10-10 Thread php-general-digest-help

php-general Digest 10 Oct 2006 14:05:57 - Issue 4393

Topics (messages 242880 through 242901):

Re: Working with overly aggressive anti-spam measures
242880 by: Chris
242882 by: Travis Doherty
242885 by: Dave M G
242886 by: Chris

Re: ftp_put and ftp_chmod does not work
242881 by: Chris
242899 by: João Cândido de Souza Neto

Removing quotes
242883 by: John Taylor-Johnston

unexpected T_STRING parse error
242884 by: Ilaria De Marinis
242887 by: Penthexquadium
242893 by: Ilaria De Marinis

If array()
242888 by: John Taylor-Johnston
242889 by: Philipp Schwarz
242890 by: Chris
242892 by: Jochem Maas

Seperate HTML from PHP
242891 by: Sancar Saran
242896 by: Peter Lauri

Passing JAVASCRIPT variable to PHP Script...
242894 by: Captain
242895 by: Penthexquadium

PHP Mailer and SMTP = SPAM?
242897 by: Peter Lauri

Re: Using mysql_real_escape_string
242898 by: Alan Milnes

Re: Apply the hyper link ( javascript functon ) with php
242900 by: edwardspl.ita.org.mo
242901 by: clive

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:
php-general@lists.php.net


--
---BeginMessage---

Dave M G wrote:

PHP List,

I run a few various social groups, and with each one I keep in contact 
with members by emailing them short newsletters.


All my user information is stored in a MySQL database. I use PHP to get 
the relevant contact information, and use the mail() command to send out 
the emails one by one, so that each email is a little personalized.


I've used this system for many years now with no problems up until now.

What has changed, though, is that in recent years, anti-spam measures 
have become so aggressive that more and more people who sign up to my 
groups complain that they never receive the emails.


A lot of the times, after they alert me to the issue, I can educate them 
a little about the anti-spam measures they most likely have on their 
system, and walk them through how to make it so that my newsletters go 
through.


However, that is clearly not enough.

To shorten a story that has already gone on a little long, it's come to 
my attention that part of the reason that my emails may not be getting 
through are because the headers are not sufficiently legitimate looking 
enough to bypass some server side anti-spam measures. Things like 
Return-Path are being set so that they look like they come from an 
email address that begins with the username nobody.



mail($email, $subject, $mailContent, $fromAddress);


You need to set the 5th parameter to change who it comes from (instead 
of nobody). See php.net/mail for more info.



You can't change that parameter if safe-mode is on for the server or if 
exim doesn't have the webserver user as a 'trusted-user' (I think only 
exim is affected by this particular issue).


--
Postgresql  php tutorials
http://www.designmagick.com/
---End Message---
---BeginMessage---
Dave M G wrote:

 PHP List,

 I run a few various social groups, and with each one I keep in contact
 with members by emailing them short newsletters.

 All my user information is stored in a MySQL database. I use PHP to
 get the relevant contact information, and use the mail() command to
 send out the emails one by one, so that each email is a little
 personalized.

 I've used this system for many years now with no problems up until now.

 What has changed, though, is that in recent years, anti-spam measures
 have become so aggressive that more and more people who sign up to my
 groups complain that they never receive the emails.

 A lot of the times, after they alert me to the issue, I can educate
 them a little about the anti-spam measures they most likely have on
 their system, and walk them through how to make it so that my
 newsletters go through.

 However, that is clearly not enough.

 To shorten a story that has already gone on a little long, it's come
 to my attention that part of the reason that my emails may not be
 getting through are because the headers are not sufficiently
 legitimate looking enough to bypass some server side anti-spam
 measures. Things like Return-Path are being set so that they look
 like they come from an email address that begins with the username
 nobody.

 If possible, can anyone help me with creating the PHP code that will
 make an email as legitimate as it can be? I know I can't totally
 prevent my email from being marked as spam (after all, if it were
 possible, all the spammers would do it). But as much as I can prevent
 anti-spam measures getting a false positive when testing my email, the
 better.

 Here is the PHP code I currently use (trimmed for clarity):

 while ( $member = 

Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Travis Doherty
Dave M G wrote:

 PHP List,

 I run a few various social groups, and with each one I keep in contact
 with members by emailing them short newsletters.

 All my user information is stored in a MySQL database. I use PHP to
 get the relevant contact information, and use the mail() command to
 send out the emails one by one, so that each email is a little
 personalized.

 I've used this system for many years now with no problems up until now.

 What has changed, though, is that in recent years, anti-spam measures
 have become so aggressive that more and more people who sign up to my
 groups complain that they never receive the emails.

 A lot of the times, after they alert me to the issue, I can educate
 them a little about the anti-spam measures they most likely have on
 their system, and walk them through how to make it so that my
 newsletters go through.

 However, that is clearly not enough.

 To shorten a story that has already gone on a little long, it's come
 to my attention that part of the reason that my emails may not be
 getting through are because the headers are not sufficiently
 legitimate looking enough to bypass some server side anti-spam
 measures. Things like Return-Path are being set so that they look
 like they come from an email address that begins with the username
 nobody.

 If possible, can anyone help me with creating the PHP code that will
 make an email as legitimate as it can be? I know I can't totally
 prevent my email from being marked as spam (after all, if it were
 possible, all the spammers would do it). But as much as I can prevent
 anti-spam measures getting a false positive when testing my email, the
 better.

 Here is the PHP code I currently use (trimmed for clarity):

 while ( $member = mysql_fetch_row($mysqlResult) )
 {
 $subscriber = $member[0];
 $email = $member[1];
 $subject = Report for  . date('l jS F Y');
 $mailContent = This is an email to  . $subscriber .  at  . $email
 . .;
 $fromAddress = [EMAIL PROTECTED]
 mail($email, $subject, $mailContent, $fromAddress);
 }


 And here is what the headers for an email from that code looks like:

 -Account-Key: account5
 X-UIDL: UID497-1152485402
 X-Mozilla-Status: 0001
 X-Mozilla-Status2: 
 Return-path: [EMAIL PROTECTED]
 Envelope-to: [EMAIL PROTECTED]
 Delivery-date: Sun, 03 Sep 2006 14:22:42 -0700
 Received: from nobody by server.myhostingservice.com with local (Exim
 4.52)
 id 1GJzQQ-0005pA-Mz
 for [EMAIL PROTECTED]; Sun, 03 Sep 2006 14:22:42 -0700
 To: [EMAIL PROTECTED]
 Subject: Report for Monday 4th September 2006
 From: [EMAIL PROTECTED]
 Message-Id: [EMAIL PROTECTED]
 Date: Sun, 03 Sep 2006 14:22:42 -0700

 Which parts are key to change, and how?

 Thank you for any and all advice.

 -- 
 Dave M G
 Ubuntu 6.06 LTS
 Kernel 2.6.17.7
 Pentium D Dual Core Processor
 PHP 5, MySQL 5, Apache 2


If it is sendmail it would be the -f parameter to set the Envelope-From
address.  ie... php.ini would have 'sendmail_path = /pathto/sendmail -f
[EMAIL PROTECTED]'.  Since PHP 4.0.5 you can also set the
additional_parameter like php.net/manual/function.mail.php (the example
there is specifically for this use.)

What you actually should be doing: install SpamAssasin on your
workstation and run the message through it in test mode...  Figure out
what rules get hit and work to resolve those.  Run it like `spamassassin
-t  message_with_headers`

So, you'd copy your complete message (as you have above) into
message_with_headers and run it through SA.  Maybe SA is giving you
points for things like too many exclamations, certain ratio of HTML... 
I doubt that having a return-path of 'nobody' is the lowest-hanging
fruit you can pick up here to make yourself look less spammy.

Also make sure the sending mail server isn't listed in any blacklists
(yahoo for RBL lookup tool to check.)

Travis Doherty

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



[PHP] Removing quotes

2006-10-10 Thread John Taylor-Johnston
Someone kindly gave me this once. I now need to reverse engineer it to 
remove the quotes and plus signs from $searchenquiry. Is it as simple as 
this?


   // FINAL RESULT: [+john +johnston]

   $sEnquiry = preg_replace(/\s+/, +, $sEnquiry);
   // RESULT: [john johnston]

   $sEnquiry = preg_replace(/\s+/, \, $sEnquiry);
   // RESULT: [john johnston]

original code---

   $sEnquiry = preg_replace(/\s+/,  , $sEnquiry);
   // remove whitespace from beginning  end
   // RESULT: [johnjohnston]

   $sEnquiry = preg_replace(/\s+/,  , $sEnquiry);
   // replace internal whitespace with single spaces
   // RESULT: [john johnston]

   $sEnquiry = str_replace( , \ +\, $sEnquiry);
   // replace each space with quote-space-plus-quote
   // RESULT: [john +johnston]

   $sEnquiry = +\ . $sEnquiry . \;
   // add beginning  ending delimiters
   // FINAL RESULT: [+john +johnston]

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



[PHP] unexpected T_STRING parse error

2006-10-10 Thread Ilaria De Marinis

Hi list,
I got a php error in my apache log:

PHP Parse error:  parse error, unexpected T_STRING in 
/var/www/html/dummy/typo3conf/ext/direct_mail/locallang_tca.xml on line 1


This is line 1 of locallang_tca.xml file
?xml version=1.0 encoding=utf-8 standalone=yes ?

I try to switch short_open_tag to off in php.ini, but I got a bad page 
visualization.

In fact it's visible also source code while displaying pages.

Any ideas?
Thank in advance

Ilaria

--

De Marinis Ilaria
Settore Automazione Biblioteche
Phone: +3906-44486052
CASPUR - Via dei Tizii ,6b - 00185 Roma
e-mail: [EMAIL PROTECTED]


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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Dave M G

Travis, Chris,

Thank you for your advice.

I've installed spamassassin and I'm using it to monitor how well my PHP 
generated emails rate as spam.


So far, I'm not doing well. I have two main issues so far:

1. Spamassassin says:

Spam detection software, running on the system homebase, has
identified this incoming email as possible spam.  [...]

Content analysis details:   (0.3 points, 5.0 required)

pts rule name  description
 -- 
--

0.3 AWLAWL: From: address is in the auto white-list

I looked up about auto white-lists on the net, and it says that it's a 
comparison between the current and previous emails. But for testing 
purposes, I don't really want it to compare against previous emails, 
since previous test emails would be spammier and bias spamassassin the 
wrong way.


How can I compensate for this?

2. I've attempted to add the Return-Path headers to my headers, like so:

$headers = Return-Path: [EMAIL PROTECTED];
$headers .= From: Tokyo Street Hockey Association 
[EMAIL PROTECTED]\n;

$headers .= X-Sender: [EMAIL PROTECTED];
mail($member, $subject, $content, $headers);

And yet, when I look at the headers of the email that's being generated, 
it says:


Return-Path: [EMAIL PROTECTED]
Received: from server.mywebhost.com (ns1.nameserver.com 
[123.123.123.123] (may be forged)


(Note that I've changed the names of servers and the DNS just to keep 
some info private)


Why are my attempts to set these headers in PHP not taking effect?

--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2

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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Chris

Dave M G wrote:

Travis, Chris,

Thank you for your advice.

I've installed spamassassin and I'm using it to monitor how well my PHP 
generated emails rate as spam.


So far, I'm not doing well. I have two main issues so far:

1. Spamassassin says:

Spam detection software, running on the system homebase, has
identified this incoming email as possible spam.  [...]

Content analysis details:   (0.3 points, 5.0 required)

pts rule name  description
 -- 
--

0.3 AWLAWL: From: address is in the auto white-list

I looked up about auto white-lists on the net, and it says that it's a 
comparison between the current and previous emails. But for testing 
purposes, I don't really want it to compare against previous emails, 
since previous test emails would be spammier and bias spamassassin the 
wrong way.


How can I compensate for this?

2. I've attempted to add the Return-Path headers to my headers, like so:

$headers = Return-Path: [EMAIL PROTECTED];
$headers .= From: Tokyo Street Hockey Association 
[EMAIL PROTECTED]\n;

$headers .= X-Sender: [EMAIL PROTECTED];
mail($member, $subject, $content, $headers);

And yet, when I look at the headers of the email that's being generated, 
it says:


Return-Path: [EMAIL PROTECTED]
Received: from server.mywebhost.com (ns1.nameserver.com 
[123.123.123.123] (may be forged)


(Note that I've changed the names of servers and the DNS just to keep 
some info private)


Why are my attempts to set these headers in PHP not taking effect?


Because the return path can't be set manually.

You need to set the 5th parameter:

mail($to, $subject, $headers, $body, '[EMAIL PROTECTED]');

or

ini_set('sendmail_from', '[EMAIL PROTECTED]');
mail($to, $subject, $headers, $body);

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] unexpected T_STRING parse error

2006-10-10 Thread Penthexquadium
On Tue, 10 Oct 2006 09:18:18 +0200, Ilaria De Marinis [EMAIL PROTECTED] wrote:
 Hi list,
 I got a php error in my apache log:
 
 PHP Parse error:  parse error, unexpected T_STRING in 
 /var/www/html/dummy/typo3conf/ext/direct_mail/locallang_tca.xml on line 1
 
 This is line 1 of locallang_tca.xml file
 ?xml version=1.0 encoding=utf-8 standalone=yes ?
 
 I try to switch short_open_tag to off in php.ini, but I got a bad page 
 visualization.
 In fact it's visible also source code while displaying pages.
 
 Any ideas?
 Thank in advance
 
 Ilaria
 
 -- 
 
 De Marinis Ilaria
 Settore Automazione Biblioteche
 Phone: +3906-44486052
 CASPUR - Via dei Tizii ,6b - 00185 Roma
 e-mail: [EMAIL PROTECTED]
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

?php
echo '' . '?xml version=1.0 encoding=utf-8 standalone=yes ?';
// ...
?

--
Sorry for my poor English.

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



[PHP] If array()

2006-10-10 Thread John Taylor-Johnston

How can I use if to see an array contains something?

if ($array()) does not work, of course.

John

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



Re: [PHP] If array()

2006-10-10 Thread Philipp Schwarz

Try this:

if (is_array($array)  count($array)) {
   ...
}

John Taylor-Johnston schrieb:

How can I use if to see an array contains something?

if ($array()) does not work, of course.

John




--
Mit freundlichen Grüßen

Philipp Schwarz
-
comtrance 


E-Mail: [EMAIL PROTECTED]
Internet:   http://www.comtrance.net
Telefon:+49 (211) 27159 - 20
Fax:+49 (211) 54423 - 05

Anschrift:  comtrance GmbH
   In der Steele 20
   40599 Düsseldorf

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



Re: [PHP] If array()

2006-10-10 Thread Chris

John Taylor-Johnston wrote:

How can I use if to see an array contains something?


php.net/in_array

--
Postgresql  php tutorials
http://www.designmagick.com/

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



[PHP] Seperate HTML from PHP

2006-10-10 Thread Sancar Saran
Hi there, following words are my ideas about that HTML PHP parting. I hope you 
can understand my broken english and do not take personally.

SEPERATING html FROM php ARE USELESS

For years, some php users try to show php to look like other programming 
languages like C or JAVA. I believe they try to prove PHP can act like other 
programming languages because most professionals from other disciplines 
thinks that thing PHP was so easy to write to someting and because of this 
that PHP thing can't be a professional tool.

To show professionalisim of php, people start to make programs using 3 tier 
programming aproach. Then that MAGIC WORD seperating business layer from 
presentation layer comes to php land...

After some time community sees templating engines, today you will see lots of 
them oh sorry TONS of them...

I'm sorry guys, I admire your efforts, REALLY. 

Personally I spend more than 2 years to create some kind of OO library to 
making forms easly.  And after some time I realize, we cannot standardize 
HTML/Javascirpt, every new project we have to challange to new interface 
problems and because of this I have to redesign that templating library to 
not broke code integritiy. Of course I may use that common library's to solve 
problems and of course later or sooner I find myself into a deep trouble. 
That new project can't fit that lib.

And of course that was not only problem about templating engines. 
They are slow, hell yes SLOW. (yea yea I know your uber template system 
blazingly faster than more popular ones). You have to open tons of mini tpl 
files, have to parse them, have to manage them.

So if that templating system generates this much of problem why we should use 
them ? Just Because of our uber HTML designer can't understand php ?.

I'm sorry, things are changing, nearly all new project are contains dynamic 
parts. These visual designers have to learn some degree of php code.

And also I believe we have to change aproaching and usage of php language.

I see most people using php dynamic part of their html code. They using php 
like

a href=somepage.php?a=?php echo $foo; ??php echo $bar; ?/a

And I suggest we can aproaching html marking language to part of php 
presentation layer. 

Like

?php
...
generate $head
generate $header
generate $left
generate $content
generate $right
generate $footer
...
include('theme.inc.php')
print $strOutput;
?

theme.inc.php
?php

$strOutput=!DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Transitional//EN\
 
\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\;
html xmlns=\http://www.w3.org/1999/xhtml\; lang=\en\
head
.$head.
/head
body
div id='mainDiv' class='cMainDiv'
div id='headDiv' class='cHeadDiv'
.$header.
/div
div id='contDiv' class='cContDiv'
table border='0' cellpadding='0' 
cellspacing='1' width='100%'
tr
td id='contLeftTD' 
class='cContLeftTD' valign='top'
.$left.
/td
td id='contCentTD' 
class='cContCentTD' valign='top'
.$content.
/td
td id='contRightTD' 
class='cContRightTD' valign='top'
.$right.
/td
/tr
/table
/div
div id='footDiv' class='cFootDiv'
.$footer.
/div
/div
/body
/html;

?
Also we can use php to generate some kind of html code to reduce our workload, 
I believe best aproach was, do not generate data and html code in same 
function...

Seperating html generation and data generation best way to increase code 
reuse.

For example

function makeSelects($arrData,$strRequest)
{
$intSize = sizeof($arrData);
for($intS=0;$intS$intSize;$intS++)
{
@$strReturn.=option value='.$arrData[$intS]['val'].';
if(@$strRequest == $arrData[$intS]['val']) { $strReturn.=  
selected; }
$strReturn.= .$arrData[$intS]['tex']./option\n;
}
return $strReturn;
}

with this function we can generate select options. 

$sqlGetType = 
SELECT typeId,typeName
  FROM listType
 WHERE typeStatus = 'active'
 ORDER BY typeName ASC;

$resGetType = doSql($sqlGetType); // put your sql extraction function here

$intT = 0;
while(!$resGetType-EOF)
{
$arrType[$intT]['val'] = 

Re: [PHP] If array()

2006-10-10 Thread Jochem Maas
Philipp Schwarz wrote:
 Try this:
 
 if (is_array($array)  count($array)) {

given that your not interested in the actual count of the array,
only that is is not empty, save yourself a couple of CPU cycles
and use empty() instead ...


if (is_array($array)  !empty($array)) {
foreach ($array as $k = $v) echo htmlentities($v = $kbr /);
}

...
 }
 
 John Taylor-Johnston schrieb:
 How can I use if to see an array contains something?

 if ($array()) does not work, of course.

 John

 
 

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



Re: [PHP] unexpected T_STRING parse error

2006-10-10 Thread Ilaria De Marinis

It's impossible for me to make this change.

xml files are packaged in external modules. I can't manipulate them!

Penthexquadium wrote:


On Tue, 10 Oct 2006 09:18:18 +0200, Ilaria De Marinis [EMAIL PROTECTED] wrote:
 


Hi list,
I got a php error in my apache log:

PHP Parse error:  parse error, unexpected T_STRING in 
/var/www/html/dummy/typo3conf/ext/direct_mail/locallang_tca.xml on line 1


This is line 1 of locallang_tca.xml file
?xml version=1.0 encoding=utf-8 standalone=yes ?

I try to switch short_open_tag to off in php.ini, but I got a bad page 
visualization.

In fact it's visible also source code while displaying pages.

Any ideas?
Thank in advance

Ilaria

--

De Marinis Ilaria
Settore Automazione Biblioteche
Phone: +3906-44486052
CASPUR - Via dei Tizii ,6b - 00185 Roma
e-mail: [EMAIL PROTECTED]


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



?php
echo '' . '?xml version=1.0 encoding=utf-8 standalone=yes ?';
// ...
?

--
Sorry for my poor English.

 



--

De Marinis Ilaria
Settore Automazione Biblioteche
Phone: +3906-44486052
CASPUR - Via dei Tizii ,6b - 00185 Roma
e-mail: [EMAIL PROTECTED]


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



[PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread Captain

Hi geeks,
  i am uploading a file to server. Uploading part is working fine. i
am struggle with minor part. actually before uploading file, i am checking
for existance of a file. If it is not exists, directly i am uploading that
file. If it exists, i sud ask user that This file is exits. Do You really
want to Upload it?...If YES, i will overwrite it. otherwise, i won't do
anything.
 i am using javascript for popup windows. i used confirm()
function(CANCEL / OK).
 the problem is, i am not able to get the variable value for php
script. Of course, php is server side programming language  javascript
client side programming language.
Plz see my code  give the solution.

See my progress:

 upload.php

# Checking for the File existance
if (file_exists($fullPath)) {
   echo script language='JavaScript'if(confirm('This
file is already Exists ! Do You Want to Duplicate ?')) { var s=1;} else {var
s=0;} /script;

   $decide=script
language='JavaScript'document.write(s)/script;
   echo $decide;
   if (!$decide) {
  // Don't Upload
exit;
   }
   else {
   // Upload the file
   }

In this code, echo $decide; is printing whether 1 or 0. But by using that
variable, i cudn't proceed further. Bcoz it is not useful for manipulating.

* Is anyway to store that variable value in a static file, so that, i can
proceed easily.
* Is it possible to execute shell commands by javascript, so that i can
create file  store this variable.

If it is not possible, plz give any other solution.
Expecting ur reply.

Thanks in advance
Prabhakaran.
-- 
View this message in context: 
http://www.nabble.com/Passing-JAVASCRIPT-variable-to-PHP-Script...-tf2415628.html#a6733549
Sent from the PHP - General mailing list archive at Nabble.com.

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



Re: [PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread Penthexquadium
On Tue, 10 Oct 2006 03:09:42 -0700 (PDT), Captain [EMAIL PROTECTED] wrote:
 
 Hi geeks,
   i am uploading a file to server. Uploading part is working fine. i
 am struggle with minor part. actually before uploading file, i am checking
 for existance of a file. If it is not exists, directly i am uploading that
 file. If it exists, i sud ask user that This file is exits. Do You really
 want to Upload it?...If YES, i will overwrite it. otherwise, i won't do
 anything.
  i am using javascript for popup windows. i used confirm()
 function(CANCEL / OK).
  the problem is, i am not able to get the variable value for php
 script. Of course, php is server side programming language  javascript
 client side programming language.
 Plz see my code  give the solution.
 
 See my progress:
 
  upload.php
 
 # Checking for the File existance
 if (file_exists($fullPath)) {
echo script language='JavaScript'if(confirm('This
 file is already Exists ! Do You Want to Duplicate ?')) { var s=1;} else {var
 s=0;} /script;
 
$decide=script
 language='JavaScript'document.write(s)/script;
echo $decide;
if (!$decide) {
   // Don't Upload
 exit;
}
else {
// Upload the file
}
 
 In this code, echo $decide; is printing whether 1 or 0. But by using that
 variable, i cudn't proceed further. Bcoz it is not useful for manipulating.
 
 * Is anyway to store that variable value in a static file, so that, i can
 proceed easily.
 * Is it possible to execute shell commands by javascript, so that i can
 create file  store this variable.
 
 If it is not possible, plz give any other solution.
 Expecting ur reply.
 
 Thanks in advance
 Prabhakaran.
 -- 
 View this message in context: 
 http://www.nabble.com/Passing-JAVASCRIPT-variable-to-PHP-Script...-tf2415628.html#a6733549
 Sent from the PHP - General mailing list archive at Nabble.com.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

This is my ideas:

If the file has already existed, the server-side script could save it in
a place temporarily, and marks the file by an unique identification
(such as md5 checksum). And then the the server-side tells the
client-side file exists and gives it the id. If the user choose
overwrite, the client-side only need to post the received id, do not
need to upload the file again.

--
Sorry for my poor English.

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



RE: [PHP] Seperate HTML from PHP

2006-10-10 Thread Peter Lauri
Have you tried Smarty (smarty.php.net)?

-Original Message-
From: Sancar Saran [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 10, 2006 3:43 PM
To: php-general@lists.php.net
Subject: [PHP] Seperate HTML from PHP

Hi there, following words are my ideas about that HTML PHP parting. I hope
you 
can understand my broken english and do not take personally.

SEPERATING html FROM php ARE USELESS

For years, some php users try to show php to look like other programming 
languages like C or JAVA. I believe they try to prove PHP can act like other

programming languages because most professionals from other disciplines 
thinks that thing PHP was so easy to write to someting and because of this 
that PHP thing can't be a professional tool.

To show professionalisim of php, people start to make programs using 3 tier 
programming aproach. Then that MAGIC WORD seperating business layer from 
presentation layer comes to php land...

After some time community sees templating engines, today you will see lots
of 
them oh sorry TONS of them...

I'm sorry guys, I admire your efforts, REALLY. 

Personally I spend more than 2 years to create some kind of OO library to 
making forms easly.  And after some time I realize, we cannot standardize 
HTML/Javascirpt, every new project we have to challange to new interface 
problems and because of this I have to redesign that templating library to 
not broke code integritiy. Of course I may use that common library's to
solve 
problems and of course later or sooner I find myself into a deep trouble. 
That new project can't fit that lib.

And of course that was not only problem about templating engines. 
They are slow, hell yes SLOW. (yea yea I know your uber template system 
blazingly faster than more popular ones). You have to open tons of mini tpl 
files, have to parse them, have to manage them.

So if that templating system generates this much of problem why we should
use 
them ? Just Because of our uber HTML designer can't understand php ?.

I'm sorry, things are changing, nearly all new project are contains dynamic 
parts. These visual designers have to learn some degree of php code.

And also I believe we have to change aproaching and usage of php language.

I see most people using php dynamic part of their html code. They using php 
like

a href=somepage.php?a=?php echo $foo; ??php echo $bar; ?/a

And I suggest we can aproaching html marking language to part of php 
presentation layer. 

Like

?php
...
generate $head
generate $header
generate $left
generate $content
generate $right
generate $footer
...
include('theme.inc.php')
print $strOutput;
?

theme.inc.php
?php

$strOutput=!DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Transitional//EN\

\http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\;
html xmlns=\http://www.w3.org/1999/xhtml\; lang=\en\
head
.$head.
/head
body
div id='mainDiv' class='cMainDiv'
div id='headDiv' class='cHeadDiv'
.$header.
/div
div id='contDiv' class='cContDiv'
table border='0' cellpadding='0'
cellspacing='1' width='100%'
tr
td id='contLeftTD'
class='cContLeftTD' valign='top'
.$left.
/td
td id='contCentTD'
class='cContCentTD' valign='top'
.$content.
/td
td id='contRightTD'
class='cContRightTD' valign='top'
.$right.
/td
/tr
/table
/div
div id='footDiv' class='cFootDiv'
.$footer.
/div
/div
/body
/html;

?
Also we can use php to generate some kind of html code to reduce our
workload, 
I believe best aproach was, do not generate data and html code in same 
function...

Seperating html generation and data generation best way to increase code 
reuse.

For example

function makeSelects($arrData,$strRequest)
{
$intSize = sizeof($arrData);
for($intS=0;$intS$intSize;$intS++)
{
@$strReturn.=option value='.$arrData[$intS]['val'].';
if(@$strRequest == $arrData[$intS]['val']) { $strReturn.= 
selected; }
$strReturn.= .$arrData[$intS]['tex']./option\n;
}
return $strReturn;
}

with this function we can generate select options. 

$sqlGetType = 
SELECT typeId,typeName
  FROM listType
 WHERE 

[PHP] PHP Mailer and SMTP = SPAM?

2006-10-10 Thread Peter Lauri
Hi,

 

I am developing a tell-a-friend application for one of my customers. We
are going to have it all located on their server, and want to make sure we
take the right decisions on the road so that we don't spam mark our server
and don't end up in the SPAM inbox of the recipients. This is how I have
prepared it all:

 

1.  We have setup an email that do have an inbox and is REAL. We have an
mailbox connected to it and can send and read emails from it via webmail and
pop
2.  We have an SMTP server that requires authentication
3.  We are going to use PHP Mailer

 

Using PHP Mailer and the SMTP sending function should make the emails look
pretty real, am I right? On that we make sure that the HTML that we create
is good, check that with http://spamcheck.sitesell.com
http://spamcheck.sitesell.com/  or similar.

 

Shouldn't I be pretty good to go? We are not talking about millions of
emails per day here, maybe a few thousands. What are the risks of ending up
being a spam marked ip?

 

Best regards,

Peter Lauri

 

www.lauri.se http://www.lauri.se/  - personal web site

www.dwsasia.com http://www.dwsasia.com/  - company web site

 

 

 



Re: [PHP] Using mysql_real_escape_string

2006-10-10 Thread Alan Milnes

Thanks everyone.

Alan

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



Re: [PHP] ftp_put and ftp_chmod does not work

2006-10-10 Thread Jo�o C�ndido de Souza Neto

Chris [EMAIL PROTECTED] escreveu na mensagem 
news:[EMAIL PROTECTED]
 João Cândido de Souza Neto wrote:
 Hello everyone.

 I have got some parts of my system where some files are sent and i use 
 ftp functions to save suche files.

 When i run it in my local machine, it works fine but, when it is on the 
 server i got some errors.

 I was using ftp_put to copy such files from upload_temp folder of php to 
 my system own folder and it does not work, i thought it could be because 
 the ftp user has no permission in upload_temp folder of php.

 Most likely. ftp users are usually locked in to their own home folders and 
 can't access any other parts of the system. It's simply a security thing.

I agree.



 Then i tried to use php_chmod to give permissions for the apache user, 
 move_uploaded_files to move such file and ftp_chmod agais to remove 
 permissions. It does not work too, i think it is because the server has 
 safe_mode on.

 chmod will be affected by safe mode (please read the documentation):

 When safe mode is enabled, PHP checks whether the files or directories you 
 are about to operate on have the same UID (owner) as the script that is 
 being executed. In addition, you cannot set the SUID, SGID and sticky 
 bits.

It means that the UID (owner) of the folder ought to be the apache user or 
the ftp user?



 move_uploaded_file will always fail because the file isn't uploaded 
 through a form. The documentation makes this rather clear (see also 
 is_uploaded_file).

The file realy was uploaded by a form and it is in the temporary upload 
folder of php.



 -- 
 Postgresql  php tutorials
 http://www.designmagick.com/ 

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



Re: [PHP] Apply the hyper link ( javascript functon ) with php

2006-10-10 Thread edwardspl
Richard Lynch wrote:

On Sun, October 8, 2006 6:53 pm, [EMAIL PROTECTED] wrote:
  

How to apply the following function with php ?
a href=javascript:popup('index.htm') Test /a



If you're new to PHP, be a minimalist, and pull out PHP only when you
absolutely have to:

a href=javascript:popup('?php echo $dir?/index.htm') Test /a

Since $dir is the ONLY part you want to be changing, use PHP only for
that part.

Switching in/out of PHP like this is very fast/cheap, and leaves you
with HTML that mostly looks just like you are used to.

YMMV

  

Hello to you,

php web page ( test.php ) :

script language=javascript type=text/javascript
!--
function popup(page)
{
window.open(page,title, height=100,width=100);
}
// --
/script

a href=javascript:popup('./?php echo $dir?/index.htm') Test /a

Result : homepage error

Web Server error log :

[Tue Oct 10 18:07:36 2006] [error] [client 202.108.22.70] File does not
exist: /home/web/index.htm
[Tue Oct 10 18:10:12 2006] [error] [client 61.135.145.217] File does not
exist: /home/web/test2004.htm
[Tue Oct 10 18:10:14 2006] [error] [client 61.135.145.217] File does not
exist: /home/web/readme.htm

Please help, thanks !

Edward.


Re: [PHP] Apply the hyper link ( javascript functon ) with php

2006-10-10 Thread clive



Hello to you,

php web page ( test.php ) :

script language=javascript type=text/javascript
!--
function popup(page)
{
window.open(page,title, height=100,width=100);
}
// --
/script

a href=javascript:popup('./?php echo $dir?/index.htm') Test /a

Result : homepage error

Web Server error log :

[Tue Oct 10 18:07:36 2006] [error] [client 202.108.22.70] File does not
exist: /home/web/index.htm
[Tue Oct 10 18:10:12 2006] [error] [client 61.135.145.217] File does not
exist: /home/web/test2004.htm
[Tue Oct 10 18:10:14 2006] [error] [client 61.135.145.217] File does not
exist: /home/web/readme.htm

Please help, thanks !

Edward.
  


does $dir have a value ?

probably nothing to do with php, does your page work if there was no php 
code in it and if you replaced

?php echo $dir? with a page url.

and go through some tutorial on php !!!

--
Regards,

Clive

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



Re: [PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread David Tulloh
Captain wrote:
 Hi geeks,
   i am uploading a file to server. Uploading part is working fine. i
 am struggle with minor part. actually before uploading file, i am checking
 for existance of a file. If it is not exists, directly i am uploading that
 file. If it exists, i sud ask user that This file is exits. Do You really
 want to Upload it?...If YES, i will overwrite it. otherwise, i won't do
 anything.
  i am using javascript for popup windows. i used confirm()
 function(CANCEL / OK).
  the problem is, i am not able to get the variable value for php
 script. Of course, php is server side programming language  javascript
 client side programming language.
 Plz see my code  give the solution.

You hit the nail right on the head, javascript is client side, PHP is
server side.  This means that PHP completely finishes it's execution
before the javascript starts to run.


To get this to work you need to do most of the work in the javascript.

Prompt the user for the file and the filename.
In javascript send a request to the PHP server and pass the filename as
a GET or POST variable.
The PHP script that recieves this checks if the file exists and echos
true of false for the javascript to recieve, the PHP script then exists.
The javascript recieves this value and prompts the user to confirm if
the file exists.
The javascript can then handle the false value or make an upload request
if the file is to be sent.

This kind of processing is generally refered to as AJAX, searching on
that term will give you a whole pile of examples.


David

PS: Geeks isn't normally seen as a complimentary term.

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



Re: [PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread tedd

At 3:09 AM -0700 10/10/06, Captain wrote:


If it is not possible, plz give any other solution.
Expecting ur reply.



It's possible, but why not do it in php -- it's simpler -- like:

?php
// specify the directory where the uploaded file should end up
$path = 'upload/' ;
// specify the filetypes allowed
$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');
// specify the max filesize in bytes
$max_size = 20;
if(isset($HTTP_POST_FILES['userfile']))
{
if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
{
if($HTTP_POST_FILES['userfile']['size']  $max_size)
{
if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed))
{
if(!file_exists($path . $HTTP_POST_FILES['userfile']['name']))
{
if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name']))
{
$html_output = 'Upload sucessful!br';
$html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'br';
$html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' 
bytesbr';

$html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'br';
$image = $HTTP_POST_FILES['userfile']['name'] ;
}else{
$html_output = 'Upload failed!br';
if(!is_writeable($path))
{
$html_output = 'The Directory '.$path.' must be writeable!br';
}else{
$html_output = 'an unknown error ocurred.br'; 
}

}
}else{
$html_output = 'The file already existsbr';
}
}else{
$html_output = 'Wrong file typebr';
}
}else{
$html_output = 'The file is too bigbr';
}
}
}else{
$html_output = 'form method=post enctype=multipart/form-data 
action='.$_SERVER['PHP_SELF'].'';

$html_output .= 'input type=file name=userfile';
$html_output .= 'input type=submit value=upload';
$html_output .= '/form';
}
echo 'htmlheadtitleUploader/title/headbody';
echo $html_output;
echo '/body/html';
?

Expecting ur payment.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Apply the hyper link ( javascript functon ) with php

2006-10-10 Thread edwardspl
clive wrote:


 Hello to you,

 php web page ( test.php ) :

 script language=javascript type=text/javascript
 !--
 function popup(page)
 {
 window.open(page,title, height=100,width=100);
 }
 // --
 /script

 a href=javascript:popup('./?php echo $dir?/index.htm') Test /a

 Result : homepage error

 Web Server error log :

 [Tue Oct 10 18:07:36 2006] [error] [client 202.108.22.70] File does not
 exist: /home/web/index.htm
 [Tue Oct 10 18:10:12 2006] [error] [client 61.135.145.217] File does not
 exist: /home/web/test2004.htm
 [Tue Oct 10 18:10:14 2006] [error] [client 61.135.145.217] File does not
 exist: /home/web/readme.htm

 Please help, thanks !

 Edward.


 does $dir have a value ?

 probably nothing to do with php, does your page work if there was no
 php code in it and if you replaced
 ?php echo $dir? with a page url.

 and go through some tutorial on php !!!

I just modified the test.php again :

script language=javascript type=text/javascript

function popup(page,title)
{
window.open(page,title, height=700,width=780);
}

/script

a href=javascript:popup('index.htm') Test /a

No any php var, it can open another windows, but no any display ( info )
with the windows :
Only Location : javascript:popup('index.htm')

Any more help ?

Thanks !

Edward.

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



[PHP] Disable all caching

2006-10-10 Thread Benjamin Adams

I have a php (ver 4.x) script that is being cached.
I have placed:
META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
but the page is still being cached.  I'm not sure if its apache or  
the php.  How can I disable all caching?

is there something I can set in php.ini?

(Mac OS X Server)

Thanks

Ben

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



Re: [PHP] ereg_replace with user defined function?

2006-10-10 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-09 22:01:34 +0200:
 Thank you Ilaria and Roman for your input. I did not know that preg  
 is able to deal with PCRE patterns.

preg is obviously short for Perl REGular expressions, while
PCRE positively means Perl-Compatible Regular Expressions.
The regexp syntax from Perl is a superset of POSIX extended
regexps, so anything ereg_ function accept will be good for
preg_ as well (but beware of pattern delimiters).

 As a matter of fact I came up  
 with the following solution (if someone is interested):
 
What problem does it solve? I mean, why are you trying to avoid
preg_replace_callback() in the first place?

 the function takes a text and an array with converters like:
 
 $converters[] = array (   metric = mm, imperial = in, 
 ratio  = 0.039370079, round = 1 );
 $converters[] = array (   metric = m, imperial = ft, ratio 
 = 3.280839895, round = 1 );
 
 
 function convertTextString ( $text, $convertTable )
 {
   # this function takes a text string, searches for numbers to  
 convert, convert those numbers and returns
   # the complete text again.
 
   if ( !ereg ( [[:digit:]], $text ) ) // if the text does not  
 contain any numbers, return the text as it is
   {
   return $text;
   }
   
   foreach ( $convertTable as $convertKey = $convertUnit )
   {
   $pattern = 
   ((\d{1,10}[,|.]*\d{0,10})*(\s)(%s)([$|\s|.|,|\)|/]+| $)); // 
 this regex 
 looks for a number followed by white space,  followed by the metric unit, 
 followed by a closing character like  ., , or )
   $pattern = sprintf ( $pattern, $convertUnit['metric'] );
   
   while ( preg_match ( $pattern, $text, $matches ) )
   {
   $matches[1] = str_replace ( ,, ., $matches[1] ); 
   // in case  numbers are written like 6,6 m, we need 
 to replace , with 
 .
   // because we do not want to return 0, we have to 
   make shure that  the new value is not zero.
   $itterator = 0;
   do {
   $value = round ( ( $matches[1] * 
   $convertUnit['ratio'] ),  $convertUnit['round'] 
 + $itterator  );
   ++$itterator;
   } while ( $value == 0 || $itterator == 10 );
   
   $replacement = $value . $2 . 
   $convertUnit['imperial'] . $4;
   $text = preg_replace ( $pattern, $replacement, 
   $text, 1 );
   }
   }
   return $text;
 }

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] PHP Mailer and SMTP = SPAM?

2006-10-10 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-10 19:06:53 +0700:
 I am developing a tell-a-friend application for one of my customers. We
 are going to have it all located on their server, and want to make sure we
 take the right decisions on the road so that we don't spam mark our server
 and don't end up in the SPAM inbox of the recipients.

Submit your mail submission form and your mail server for tests
by a few RBLs, check the results, fix them, resubmit, repeat.
That should help you arrive at a bulletproof app.

As for testing the messages: a bayesian spam filter will help you
identify most of problems.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Disable all caching

2006-10-10 Thread Andrew Brampton
Caching occurs client side (ie in the webbrowser) not by apache or php 
unless you have setup something especially to do so...

How are you testing that something stays cached?

There is also a HTTP header you can make your PHP send to ask the page not 
to be cached.
Looking at this page: http://uk2.php.net/header and googling for no cache 
will help.


Andrew

- Original Message - 
From: Benjamin Adams [EMAIL PROTECTED]

To: php php php-general@lists.php.net
Sent: Tuesday, October 10, 2006 4:17 PM
Subject: [PHP] Disable all caching



I have a php (ver 4.x) script that is being cached.
I have placed:
META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
but the page is still being cached.  I'm not sure if its apache or  the 
php.  How can I disable all caching?

is there something I can set in php.ini?

(Mac OS X Server)

Thanks

Ben

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




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



Re: [PHP] PHP Mailer and SMTP = SPAM?

2006-10-10 Thread David Giragosian


How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991


How many Boomer wannabes does it take to pollute a mailing list?
Just one, [EMAIL PROTECTED], MAN!

David


RE: [PHP] Disable all caching

2006-10-10 Thread Brad Fuller
 I have a php (ver 4.x) script that is being cached.
 I have placed:
 META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
 but the page is still being cached.  I'm not sure if its apache or  the 
 php.  How can I disable all caching?
 is there something I can set in php.ini?

 (Mac OS X Server)

 Thanks

 Ben

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

 

Try adding this to your php page

code

if(!strpos(strtolower($_SERVER[HTTP_USER_AGENT]), msie) === FALSE) {
   header(HTTP/1.x 205 OK);
} else {
   header(HTTP/1.x 200 OK);
}   
header(Pragma: no-cache);
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
header(Last-Modified:  . gmdate(D, d M Y H:i:s) .  GMT);
header(Cache-Control: no-cache, cachehack=.time());
header(Cache-Control: no-store, must-revalidate);
header(Cache-Control: post-check=-1, pre-check=-1, false);

/code

Hope that helps,

Brad

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



Re: [PHP] Disable all caching

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 10:17 am, Benjamin Adams wrote:
 I have a php (ver 4.x) script that is being cached.
 I have placed:
 META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
 but the page is still being cached.  I'm not sure if its apache or
 the php.  How can I disable all caching?
 is there something I can set in php.ini?

All the headers and all the META tags in the world won't get EVERY
browser and EVERY caching / proxy server (AOHell) to stop caching.

If you really truly absolutely MUST have no caching at all, generate
random/unique URLs for your content.

img src=/images/phpscript/nocache=?php echo
mt_rand()?/whatever.jpg /

phpscript can be ForceType'd to readfile whatever.jpg (or to
fopen/fread/echo if your JPGs are large) and the nocache will
guarantee the browser won't cache it.

More precisely, the browser WILL cache it, but you send the browser a
new URL every time, so it renders the cached item useless.

Maybe if the browser-makers actually honored the no-cache headers they
keep making up out of thin air, I would feel bad about wasting their
cache like this.  But they don't, so I don't.

You need the .jpg at the end for IE to do the right thing.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] php and mysql date mapping question

2006-10-10 Thread Dave Goodchild

Hi all, I am in the process of creating a national events directory where
people can enter their events (car boot sales, evening classes etc) and
specify whether those events are one-ff events or repeating (daily, weekly
etc) affairs and people can search for those events by postcode, date range,
category etc.

I have a table containing all dates between Oct 1 2006 and 2030, including
leap years etc. I am pretty new to relational design so here's my question:

I have an events table and a dates table. As an event can happen on many
dates and a date can hold many events, I created an intermediary table
called dates_events to express that many-to-many relationship. The data
entry works like a dream as does the search.

However, the dates_events table is growing quite large (200,000 mapped
relationships for 300+ test events), but the logic I used seemed clear. When
the system goes live, allowing for a sweeper script that removes outdated
mappings from all three tables, I estimate that this mapping table may grow
to 2-3 million records at least.

Does this sound flawed, and will mysql handle this kind of data volume?
Anyone have any experience building a similar system. I am happy to use this
method for the initial test run but may re-engineer it before we go national
if suggestions lead me that way.

I am unable to release the URL as yet.

--
http://www.web-buddha.co.uk


[PHP] Question about Arrays

2006-10-10 Thread Alex Major

Hi List.
I have a table, which contains 'setting' information for my website.
The table has the following columns: setting_id, setting_name and 
setting_value.
Now there are currently 30 settings stored in this table, however i am 
having trouble pulling values out on a 'as needed' basis.


At the moment i have this select query:
$settings_query = SELECT * FROM `robin_settings`;
$settings_result = mysql_query($settings_query);

And from that, i would like to pull individual results, for example...

I have a setting which has a 'setting_id' of 4, a 'setting_name' 
called banner_on and a 'setting_value' of  1.


How am i able to pull that information from the results i get?

I know i could pull it by putting a WHERE clause on the SQL query, 
however that would mean having 30 select queries per page and i don't 
really fancy that!


Thanks for any help! (i'm new at this :) )

Alex.

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



[PHP] foreach

2006-10-10 Thread Jo�o C�ndido de Souza Neto
Hello.

In the follow code:

$numbers=array(1,2,3,4,5);
foreach ($numbers as number) {
...
}

Inside foreach, could i know if i am in the last element of the array 
$numbers?

-- 
João Cândido de Souza Neto
Curitiba Online
[EMAIL PROTECTED]
(41) 3324-2294 (41) 9985-6894
http://www.curitibaonline.com.br

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



Re: [PHP] foreach

2006-10-10 Thread Brad Bonkoski

João Cândido de Souza Neto wrote:

Hello.

In the follow code:

$numbers=array(1,2,3,4,5);
foreach ($numbers as number) {
...
}

Inside foreach, could i know if i am in the last element of the array 
$numbers?


  
Sure, maintain a count in the foreach and then compare to 
count($numbers)..but why not just use a for loop?


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



Re: [PHP] foreach

2006-10-10 Thread John Nichel

João Cândido de Souza Neto wrote:

Hello.

In the follow code:

$numbers=array(1,2,3,4,5);
foreach ($numbers as number) {
...
}

Inside foreach, could i know if i am in the last element of the array 
$numbers?




$last = end ( $numbers );
reset ( $numbers );
foreach ( $numbers as $number ) {
if ( $number == $last ) {
// last element
...
}

}

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] foreach

2006-10-10 Thread Chris Boget

$last = end ( $numbers );
reset ( $numbers );


I thought foreach() already performed a reset()?  Why do it again here?

thnx,
Chris

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



Re: [PHP] Apply the hyper link ( javascript functon ) with php

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 7:57 am, [EMAIL PROTECTED] wrote:
 php web page ( test.php ) :

 script language=javascript type=text/javascript
 !--
 function popup(page)
 {
 window.open(page,title, height=100,width=100);
 }
 // --
 /script

 a href=javascript:popup('./?php echo $dir?/index.htm') Test /a

 Result : homepage error

 Web Server error log :

 [Tue Oct 10 18:07:36 2006] [error] [client 202.108.22.70] File does
 not
 exist: /home/web/index.htm
 [Tue Oct 10 18:10:12 2006] [error] [client 61.135.145.217] File does
 not
 exist: /home/web/test2004.htm
 [Tue Oct 10 18:10:14 2006] [error] [client 61.135.145.217] File does
 not
 exist: /home/web/readme.htm

 Please help, thanks !

So, after you take out the $dir and there is NO PHP in it, the problem
clearly has nothing to do with PHP.

It has everything to do with you don't know what the URL is to get to
the page you want.

Can you surf directly to the index.htm or readme.htm page?

If so, copy/paste the URL, with the http:// and everything, into your
HTML.  That will work.

You can then experiment with stripping out parts of the URL, to see
what else *might* work.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] foreach

2006-10-10 Thread John Nichel

Chris Boget wrote:

$last = end ( $numbers );
reset ( $numbers );


I thought foreach() already performed a reset()?  Why do it again here?



Well, corn my fritters, according to TFM, it does this indeed.  Maybe an 
old dog can learn new tricks.  ;)


--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

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



Re: [PHP] PHP Mailer and SMTP = SPAM?

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 7:06 am, Peter Lauri wrote:
 1.We have setup an email that do have an inbox and is REAL. We have
 an
 mailbox connected to it and can send and read emails from it via
 webmail and
 pop
 2.We have an SMTP server that requires authentication
 3.We are going to use PHP Mailer

 Using PHP Mailer and the SMTP sending function should make the emails
 look
 pretty real, am I right? On that we make sure that the HTML that we
 create
 is good, check that with http://spamcheck.sitesell.com
 http://spamcheck.sitesell.com/  or similar.

If it's HTML enhanced email, you've already blown it.

It will get you marked as a spammer.

 Shouldn't I be pretty good to go? We are not talking about millions of
 emails per day here, maybe a few thousands. What are the risks of
 ending up
 being a spam marked ip?

Unless the email is coming from somebody the recipient knows/trusts,
then you're going to get marked by them as a spammer -- which will
report back to some of the lists marking you as a spammer.

So you have to have the From: and Reply-to: coming FROM the person
recommending the product for starters.

You also have a huge gaping hole, or completely forgot to mention,
that anybody could script your site to send out the product
recommendations to a million people as a prank.

There is a singular lack as well of a mention of cleansing the To:
address, which hopefully you do to avoid header injection.

One nice technique to limit spammers is to put in a throttle on any
given IP address using the form to send out the product
recommendations.  While IP sucks for authentication/identification,
you *know* something is wrong if more than 4 mails are being sent out
by the same IP address surfing to your site within X minutes.  Bam! 
Slam the door in their face.  Very simple to code/implement/maintain. 
Most bad guys will just go find some other wide-open form to use to
send their spam instead of dinking around with their IP all the time.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] foreach

2006-10-10 Thread Jo�o C�ndido de Souza Neto
You´re right, in my example here i could just use a for loop.

But in my real code it´s better to use foreach.

Thanks for your tip.

-- 
João Cândido de Souza Neto
Curitiba Online
[EMAIL PROTECTED]
(41) 3324-2294 (41) 9985-6894
http://www.curitibaonline.com.br

Brad Bonkoski [EMAIL PROTECTED] escreveu na mensagem 
news:[EMAIL PROTECTED]
 João Cândido de Souza Neto wrote:
 Hello.

 In the follow code:

 $numbers=array(1,2,3,4,5);
 foreach ($numbers as number) {
 ...
 }

 Inside foreach, could i know if i am in the last element of the array 
 $numbers?


 Sure, maintain a count in the foreach and then compare to 
 count($numbers)..but why not just use a for loop? 

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



Re: [PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 5:09 am, Captain wrote:
 Hi geeks,

Hi, non-listener...

You do realize you posted much the same question yesterday, right?

Do you think our answer will have changed in 24 hours?

Actually, it will change.

I have GIVEN UP trying to tell you the RIGHT WAY to do this, and will
blindly answer your question giving you BAD ADVICE.

The remainder of this email is BAD ADVICE and I do not recommend
anybody other than Captain follow it.

You have been warned.

   i am uploading a file to server. Uploading part is working
 fine. i
 am struggle with minor part. actually before uploading file, i am
 checking
 for existance of a file.

Here are 2 ways to do this:

1. In the PHP script that dumps out the INPUT NAME=upload
TYPE=FILE add something like this:

script language=javascript
  var file_exists = new Array;
?php
  $i = 0;
  $upload_dir = /full/path/to/dir/where/you/store/uploads/;
  $dir = opendir($upload_dir) or die(Failed to open $upload_dir);
  while (($file = readdir($dir)) !== false){ //this is subtle, do not
simplify
echo   file_exists[, $i++, ] = '$file';\n;
  }
?
/script

You can then check in javascript with something like:
if (file_exists[document.upload.value].length){
  alert('Overwrite?');
}


Another option is to use AJAX in your JS to check back to a URL on the
server that lists all the files already used.

Note that NEITHER of these guarantees that the file won't exist
because some OTHER user uploaded the same name file while yours was
being uploaded.

 If it is not exists, directly i am uploading
 that
 file. If it exists, i sud ask user that This file is exits. Do You
 really
 want to Upload it?...If YES, i will overwrite it. otherwise, i won't
 do
 anything.
  i am using javascript for popup windows. i used confirm()
 function(CANCEL / OK).
  the problem is, i am not able to get the variable value for
 php
 script. Of course, php is server side programming language 
 javascript
 client side programming language.

You say Of course so blithely, but clearly do not yet understand the
implications of that statement.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] unexpected T_STRING parse error

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 2:18 am, Ilaria De Marinis wrote:
 PHP Parse error:  parse error, unexpected T_STRING in
 /var/www/html/dummy/typo3conf/ext/direct_mail/locallang_tca.xml on
 line 1

 This is line 1 of locallang_tca.xml file
 ?xml version=1.0 encoding=utf-8 standalone=yes ?

 I try to switch short_open_tag to off in php.ini, but I got a bad
 page
 visualization.
 In fact it's visible also source code while displaying pages.

When you turn off short_open_tag, you also need to convert things like:

? $x = 'foo';?

into:

?php $x = 'foo';?

?= ... ? becomes ?php echo ... ?



-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 8:55 pm, Dave M G wrote:
 If possible, can anyone help me with creating the PHP code that will
 make an email as legitimate as it can be? I know I can't totally
 prevent
 my email from being marked as spam (after all, if it were possible,
 all
 the spammers would do it). But as much as I can prevent anti-spam
 measures getting a false positive when testing my email, the better.

Get the problem users to send you valid email that gets through,
headers and all, and compare yours to theirs. :-)

 Here is the PHP code I currently use (trimmed for clarity):

 while ( $member = mysql_fetch_row($mysqlResult) )
 {
 $subscriber = $member[0];
 $email = $member[1];
 $subject = Report for  . date('l jS F Y');
 $mailContent = This is an email to  . $subscriber .  at  . $email
 . .;
 $fromAddress = [EMAIL PROTECTED]
 mail($email, $subject, $mailContent, $fromAddress);

$fromAddress, by itself, is not a valid header line.  That right there
is going to choke many mail agents, before they even try to look at it
for spam content.

$headers = From: $fromAddress\r\n;
$headers .= Reply-to: $fromAddress\r\n;
$extra = -f$fromAddress;
mail($email, $subject, $mailContent, $headers, $extra);

$extra requires PHP 5 (4.x?) and that your mail config trusts the
Apache user to forge emails.  It may not be possible in your setup.

 }


 And here is what the headers for an email from that code looks like:

 -Account-Key: account5

Hopefully this had an X in the front of it...???

 X-UIDL: UID497-1152485402
 X-Mozilla-Status: 0001
 X-Mozilla-Status2: 
 Return-path: [EMAIL PROTECTED]

This is set by $extra.

If your server won't let you change it, then there is little you can
do other than re-configure sendmail, switch hosts, and/or turn off
safe_mode -- all of which are outside the purvue of PHP and this list.

(Well, okay, safe_mode on/off is within our realm.  Turn it off.)

 Envelope-to: [EMAIL PROTECTED]
 Delivery-date: Sun, 03 Sep 2006 14:22:42 -0700
 Received: from nobody by server.myhostingservice.com with local (Exim
 4.52)
 id 1GJzQQ-0005pA-Mz
 for [EMAIL PROTECTED]; Sun, 03 Sep 2006 14:22:42 -0700
 To: [EMAIL PROTECTED]
 Subject: Report for Monday 4th September 2006
 From: [EMAIL PROTECTED]

I'm AMAZED PHP and/or your MTA got this From: like this, when you
didn't do it right above...

 Message-Id: [EMAIL PROTECTED]
 Date: Sun, 03 Sep 2006 14:22:42 -0700

 Which parts are key to change, and how?

You're actually very close to a valid email, mainly because you've
kept it so simple...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 9:01 pm, Chris wrote:
 You can't change that parameter if safe-mode is on for the server or
 if
 exim doesn't have the webserver user as a 'trusted-user' (I think only
 exim is affected by this particular issue).

Almost-for-sure sendmail has the same issue.

Or maybe you are all laughing at me because that was obvious to
anybody who knows anything about exim and sendmail... :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 3:01 am, Dave M G wrote:
 Content analysis details:   (0.3 points, 5.0 required)

  pts rule name  description
  --
 --
  0.3 AWLAWL: From: address is in the auto
 white-list

 I looked up about auto white-lists on the net, and it says that it's a
 comparison between the current and previous emails. But for testing
 purposes, I don't really want it to compare against previous emails,
 since previous test emails would be spammier and bias spamassassin
 the
 wrong way.

 How can I compensate for this?

That's gotta be some kind of SA setting...

 2. I've attempted to add the Return-Path headers to my headers, like
 so:

 $headers = Return-Path: [EMAIL PROTECTED];

No, no, no.

Return-path: may *LOOK* like a normal header, but it's not, and you
cannot just set it in the $headers variable 4th arg to PHP mail().

Return-path is a super-special only-god-can-do-this header, and has to
be set in the sendmail_path or with that new FIFTH arg, which only
works if you've got permissions set up right in sendmail (or whatever)
and PHP (no safe mode).

 $headers .= From: Tokyo Street Hockey Association
 [EMAIL PROTECTED]\n;

 $headers .= X-Sender: [EMAIL PROTECTED];

This is not needed.

Reply-to: is good, though, as it looks more human

 mail($member, $subject, $content, $headers);

 And yet, when I look at the headers of the email that's being
 generated,
 it says:

 Return-Path: [EMAIL PROTECTED]
 Received: from server.mywebhost.com (ns1.nameserver.com
 [123.123.123.123] (may be forged)

 (Note that I've changed the names of servers and the DNS just to keep
 some info private)

 Why are my attempts to set these headers in PHP not taking effect?

They're just not handled like normal headers, as they are part of the
routing of the email handled by mail software more than they are
regular old headers.

It's just the way it is, no matter how goofy it seems from our (well,
my, anyway) naive view-point.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Re: set cookie with non-english

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 6:21 pm, Nisse Engström wrote:
No matter. Thanks for the information. By the bye,
 are we talking IE in general, or specific versions
 thereof?

Put it this way:

*ANYTHING* you can say about IE at all, is not about IE in general,
but only about specific versions thereof.

:-) :-) :-)

Maybe it's not really that bad, but it seems that way to me every time
I do any QA testing.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



RE: [PHP] Re: Understanding persistent connections with oci8

2006-10-10 Thread Bauer, Jay W
Hello Richard,

  First let me introduce myself, I'm Jay Bauer and have been supporting
the Apache webserver for the last couple of years and have been doing
networking support for over 15 years.  I want to thank you for
explaining why the folks replying to our lab's enquiries don't think the
tests are valid.  I can appreciate the need of doing fault isolation of
a problem so that all possible extraneous causes are eliminated.   

  However, I don't think their specific concerns are valid, as these
systems are on internal networks, and very few people access them at
all, and only Kiran or I would be accessing the oracle database and that
is for our tests.  And yes we will get some 50 httpd servers up and
running, but once we stop our testing there is little access to the
system or none to these connections, and they will stay around for hours
or days till one of us decides to do more testing and stops and restarts
the Apache server. 

  Now having said all of that, I had no problem implementing the test
setup you suggested.  If that is what it takes to get everyone on the
same page, I'm happy to oblige.

 The HP-UX Apache web server only provides the worker MPM so in order to
set up Apache as requested we use the following configuration in
httpd.conf:

 changed the worker.c configuration to:

IfModule worker.c
StartServers 1
MaxClients   1
MinSpareThreads  1
MaxSpareThreads  1
ThreadsPerChild  1
MaxRequestsPerChild  1
/IfModule

and commented out mod_cgid:
#LoadModule cgid_module modules/mod_cgid.so 

and in php.ini:

extension=oci8.sl
oci8.max_persistent=1
oci8.persistent_timeout=10
oci8.ping_interval=0

After starting Apache we have two process running:

ps -ef |grep apache 
 www 29362 29361  0 23:39:52 ? 0:00
/opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start   
root 29361 1  0 23:39:52 ? 0:00
/opt/hpws/apache/bin/httpd -d /opt/hpws/apache -k start

Pid 29361, the master httpd server, and one worker httpd server pid
29362, which is the minimum configuration possible with worker MPM.

 I then ran the apache bench mark for just one connection:

bin/ab -n 1 http://maggie.india.hp.com/oracle_mufasa.php

Document Path:  /oracle_mufasa.php
Document Length:334 bytes

Concurrency Level:  1
Time taken for tests:   0.370606 seconds
Complete requests:  1
 
And then checked on the connection
 
As quick as possible:
netstat -an |grep 1521
tcp0  0  15.42.227.146.5926215.106.72.129.1521
ESTABLISHED

30 sends later:
netstat -an |grep 1521
tcp0  0  15.42.227.146.5926215.106.72.129.1521
ESTABLISHED

2 minutes later:
netstat -an |grep 1521
tcp0  0  15.42.227.146.5926215.106.72.129.1521
ESTABLISHED

5 minutes later:
netstat -an |grep 1521
tcp0  0  15.42.227.146.5926215.106.72.129.1521
ESTABLISHED

It wasn't until about 40 minutes later that this connection did finally
terminate. 

And when I checked the error_log, it was clear what terminated it:

[error] [client 15.10.45.59] Symbolic link not allowed:
/opt/hpws/apache/htdocs/index.html
[debug] worker.c(1342): taking over scoreboard slot from 29362
(quiescing)

 Another request finally came in to this system , which errored, and
since there was only one server allowed to run it did and that is what
killed this persistent connection.   This is what we have also observed
that other apache requests will cause this persistent connections to be
terminated, they don't close on their own.   And as said earlier this
system's webserver doesn't get many hits, it is a test environment, not
a production system.  And as we can see it took 40 minutes for any
traffic to hit this system.  

  I hope this test is adequate to clear up the concerns that the testing
is invalid.   

Best regards, Jay Bauer 
WTEC Engineer, Internet Services HP-UX
Hewlett Packard Co.  



-Original Message-
From: Richard Lynch [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 05, 2006 4:48 PM
To: Mendonce, Kiran (STSD)
Cc: php-general@lists.php.net
Subject: RE: [PHP] Re: Understanding persistent connections with oci8

On Wed, October 4, 2006 12:34 pm, Mendonce, Kiran (STSD) wrote:
 I understand the performance boost one can get by reusing existing 
 connections. And I did see for myself that with the default settings,
 oci_pconnect() does reuse all the connections.

 But what should happen if there are idle connections and the timeout 
 is reached ? That is my question. What is the purpose of the 
 persistent_timeout setting ? Does it give the user a means of 
 specifying a timeout after which idle connections are removed ?

Yes.

Their claim is that your tests are invalid because your have MULTIPLE
Apache processing swapping the connections around, so they are NOT idle
for 10 seconds.

To prove them wrong, you would need to:
Set up a dev server on a private network with Apache having ONE, and
ONLY ONE, child.
Set the timeout to 10 seconds.
Surf to 

Re: [PHP] need help to build a query

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 2:44 pm, [EMAIL PROTECTED] wrote:
 I have table orders with primary key order_id. I have table
 uploaded_files
 with primary key ufid and uploaded files are linked to orders by
 order_id
 column.

 I have to list all orders and uploaded files. this works fine:

 $query = mysql_query(
   select order_id, order_date, order_status
   from orders
   order by order_id desc
   limit 100);
 while($result=mysql_fetch_array($query))
 {
   echo ID: . $result['order_date'].|;
   echo DATE: . $result['order_date'] .|;
   echo STATUS: . $result['order_status'] .|;
   echo UPLOADED FILES: ;
   $query2 = mysql_query(
 select uf.file_name
 from uploaded_files as uf
 where uf.order_id = $result['order_id']
   );
   while($result2=mysql_fetch_array($query2))
   {
 echo $result2['file_name'].|;
   }
   echo hr;
 }

 but I know there must be much better solution then this one.

This is really an SQL question...

But let's take the PHP performance test, to stay on topic.

Yes, you are sending 100 queries to the DB through mysql_query.

Does that negatively impact performance on YOUR server for YOUR web
app at your current or 5-year projected levels of usage?

If not, don't waste time trying to optimize it.  K.I.S.S. and use the
queries that work just fine.

As a bonus, the answer to what you actually asked is:


select orders.order_id, order_date, order_status
from orders
left outer join uploaded_files on uploaded_files.order_id =
orders.order_id
order by orders.order_id desc
limit 100

Unfortunately, this limit now applies to the number of uploaded files
and/or orders with no files at all, rather than the number of orders.

AFAIK, there is no easy way to get the exact same limit of 100 orders
with however many uploaded files.

So if you NEED 100 orders, and who cares how many uploaded files, the
solution you have is CORRECT, no matter how wrong it looks.

Actually, you could *maybe* get some performance gain by running
through the first result, gathering up the IDs into an array, and then
splicing that into a single query like:

//outside the loop:
$order_ids_sql = implode(', ', $order_ids);
$result2 = mysql_query(select order_id, file_name from uploaded_files
where order_id in ($order_ids_sql) order by order_id);

You can then run through $result2 in parallel with $result1 and
compare the $order_id to make sure you print the right thing at the
right time.

Don't be surprised if the LEFT OUTER JOIN above, or the parallel
processing and the extra array to build the query with 100 IDs turns
out to be not any faster/better than your current solution.  SQL
theory often turns out to be not-so-practical, in my experience.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] need help to build a query

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 2:58 pm, John Wells wrote:
 On 10/9/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 but I know there must be much better solution then this one.

 You're right: Simply JOIN your queries...

 SELECT order_id, order_date, order_status, file_name
 FROM orders
 JOIN uploaded_files AS uf ON orders.order_id = uf.order_id
 ORDER BY orders.order_id DESC
 LIMIT 100

This will miss all the orders with no upload at all, unlike the
original.

AND it limits you to the 100 uploaded files, not 100 orders.

This is a lot more subtle problem than it seems at first glance, eh?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] need help to build a query

2006-10-10 Thread Richard Lynch




On Mon, October 9, 2006 3:09 pm, [EMAIL PROTECTED] wrote:
 But, in this case I will have repeating order_date and order_status
 info?

 idorder_datestatusfile_name
 122006-10-09live  file1.jpg
 122006-10-09live  file2.jpg
 122006-10-09live  file3.jpg
 132006-10-09live  file1.jpg
 142006-10-09live  test.gif

Yes.

But what you print out and what you have in each result row need not
be exactly one-to-one.

$last_order_id = '';
while (... mysql_fetch_row($result)){
  if ($last_order_id != $order_id){
echo $order_id $order_date $statusbr /\n;
$last_order_id = $order_id;
  }
  echo   $file_namebr /\n;
}

Here we only print out the order_id etc when the order_id changes, not
for every uploaded file.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] need help to build a query

2006-10-10 Thread afan
sure it is!
;)

 On Mon, October 9, 2006 2:58 pm, John Wells wrote:
 On 10/9/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 but I know there must be much better solution then this one.

 You're right: Simply JOIN your queries...

 SELECT order_id, order_date, order_status, file_name
 FROM orders
 JOIN uploaded_files AS uf ON orders.order_id = uf.order_id
 ORDER BY orders.order_id DESC
 LIMIT 100

 This will miss all the orders with no upload at all, unlike the
 original.

 AND it limits you to the 100 uploaded files, not 100 orders.

 This is a lot more subtle problem than it seems at first glance, eh?

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?

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



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



Re: [PHP] need help to build a query

2006-10-10 Thread afan
ok. got the point.




 On Mon, October 9, 2006 3:09 pm, [EMAIL PROTECTED] wrote:
 But, in this case I will have repeating order_date and order_status
 info?

 idorder_datestatusfile_name
 122006-10-09live  file1.jpg
 122006-10-09live  file2.jpg
 122006-10-09live  file3.jpg
 132006-10-09live  file1.jpg
 142006-10-09live  test.gif

 Yes.

 But what you print out and what you have in each result row need not
 be exactly one-to-one.

 $last_order_id = '';
 while (... mysql_fetch_row($result)){
   if ($last_order_id != $order_id){
 echo $order_id $order_date $statusbr /\n;
 $last_order_id = $order_id;
   }
   echo   $file_namebr /\n;
 }

 Here we only print out the order_id etc when the order_id changes, not
 for every uploaded file.

 --
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?



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



RE: [PHP] Disable all caching

2006-10-10 Thread Kristen G. Thorson
 -Original Message-
 From: Brad Fuller [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, October 10, 2006 12:55 PM
 To: php-general@lists.php.net
 Subject: RE: [PHP] Disable all caching
 
  I have a php (ver 4.x) script that is being cached.
  I have placed:
  META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
  but the page is still being cached.  I'm not sure if its apache or
the
  php.  How can I disable all caching?
  is there something I can set in php.ini?
 
  (Mac OS X Server)
 
  Thanks
 
  Ben
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 Try adding this to your php page
 
 code
 
 if(!strpos(strtolower($_SERVER[HTTP_USER_AGENT]), msie) === FALSE) {
header(HTTP/1.x 205 OK);
 } else {
header(HTTP/1.x 200 OK);
 }
 header(Pragma: no-cache);
 header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
 header(Last-Modified:  . gmdate(D, d M Y H:i:s) .  GMT);
 header(Cache-Control: no-cache, cachehack=.time());
 header(Cache-Control: no-store, must-revalidate);
 header(Cache-Control: post-check=-1, pre-check=-1, false);


I've seen a lot of people do this, so I have to comment.  The last
Cache-Control header REPLACES any other Cache-Control headers set
previously unless you specify not to.

http://us2.php.net/manual/en/function.header.php

The header 

Cache-Control: no-cache, cachehack=time()

will never be sent because the second one replaces it.  The third one
uses the second argument to specify that it should not replace the
existing one.  Of those three Cache-Control lines, only two will even be
sent to the browser.

Cache-Control: no-store, must-revalidate
Cache-Control: post-check=-1, pre-check=-1


kgt

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



[PHP] [JOB] PHP Book Tech Reviewer

2006-10-10 Thread Larry E. Ullman
I'm currently writing the second edition of my PHP Advanced book and  
need a technical reviewer. It is a paid job and some people think  
it's interesting/looks good on a resume/etc. Obviously you'll need to  
be an expert in PHP and pay close attention to detail. My definition  
of advanced for this book means:

- OOP
- Doing what you already do but better and faster
- Tangential topics (GD, PDFlib, CLI, PEAR, XML, Ajax, MySQL, E- 
Commerce, other buzzwords).

Experience in these areas required.

You must be able to work quickly (the entire book must be reviewed  
over the course of a month, I think). If you are interested or have  
any questions, please email me off-list.


Thanks,
Larry

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



Re: [PHP] php and mysql date mapping question

2006-10-10 Thread Jochem Maas
Dave Goodchild wrote:
 Hi all, I am in the process of creating a national events directory where
 people can enter their events (car boot sales, evening classes etc) and
 specify whether those events are one-ff events or repeating (daily, weekly
 etc) affairs and people can search for those events by postcode, date
 range,
 category etc.
 
 I have a table containing all dates between Oct 1 2006 and 2030, including

Dave, if you are starting a calendar/event DB with a table full of dates
something is probably wrong. you only need to store dates for actual events (in 
theory).

 leap years etc. I am pretty new to relational design so here's my question:
 
 I have an events table and a dates table. As an event can happen on many
 dates and a date can hold many events, I created an intermediary table
 called dates_events to express that many-to-many relationship. The data
 entry works like a dream as does the search.
 
 However, the dates_events table is growing quite large (200,000 mapped
 relationships for 300+ test events), but the logic I used seemed clear.
 When
 the system goes live, allowing for a sweeper script that removes outdated
 mappings from all three tables, I estimate that this mapping table may grow
 to 2-3 million records at least.

asuming you tables are correctly indexes and the relations are correctly
defined record count is not the limiting factor at all.

it does sound like you have one table too many. a one to many relationship
between an events table and a dates table should suffice.

then again your denormalized design may allow for much faster data retrieval,
in which case stick with it :-) only one way to find out though.


 
 Does this sound flawed, and will mysql handle this kind of data volume?

yup :-) use InnoDB as the storage format and even the 4Gig limit is history.

 Anyone have any experience building a similar system. I am happy to use
 this
 method for the initial test run but may re-engineer it before we go
 national
 if suggestions lead me that way.
 
 I am unable to release the URL as yet.
 

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



Re: [PHP] PHP Mailer and SMTP = SPAM?

2006-10-10 Thread David Giragosian

-- Forwarded message --
From: Roman Neuhauser [EMAIL PROTECTED]
Date: Oct 10, 2006 5:11 PM
Subject: Re: [PHP] PHP Mailer and SMTP = SPAM?
To: David Giragosian [EMAIL PROTECTED]

# [EMAIL PROTECTED] / 2006-10-10 12:49:11 -0500:

Do you realize how many Vietnam war veterans you're offending with what I
guess is supposed to be a joke?


  Surely not. How could I know how many of those who spilled blood in
  Vietnam, Cambodia or Laos cannot reflect on their deeds almost 40
  years later?

  I know it's easy for the older parts of our behavioral equipment to
  take hold esp. in difficult situations, and 18-20 years old guys
  aren't exactly known as a group with the closest obedience of
  so-called moral norms (that's quite natural and I would have to damn
  myself if I weren't forgiving about it). But don't complain it was
  tough if you were there to murder other people.

  Sure, we (humans) are weaklings, and easily fall prey to whatever
  bullshit any drunkard and/or Hitler-wannabe says if they repeat it
  long enough, but if those Americans who fought in Vietnam didn't
  elect the government that sent them there then it was their parents,
  and grandparents. If you get agitated by a joke referring to the US
  movie and TV cliche they fed us with for 20 years or so, complain to
  those Americans who voted for the war. The GM children born today
  in Vietnam, mutilated by defoliants sprayed on their parents 35
  years ago are shame of those who elected Nixon.


You're in the Czech Republic, I'm guessing by your country code, so maybe

I

should have cut you some slack, but it isn't funny to those of us who went
to war or lived through it.


  Yes, I'm a citizen of a country that takes part in the running US
  raid on Middle East. I'm living through a war myself, mind you.
  Although much closer to the shit than you I'm much calmer these days
  than when the US Army was raging full-auto all over Europe (the
  bombing of Bulgaria[!] during the deathmatch in Yugoslavia in the
  92-4 or so). Back then it could also have been /my/ roof.

  If I wanted to have a combative signature I'd be using something
  like How many American soldiers does it take to kick a tied-up POW
  to death in Guantanamo? or perhaps American cars run on blood of
  Iraqi people., Operation Enduring Oil or a variant.  But it's
  just a joke.

  I freely admit you're not the first to bitch about this signature.
  You're second.  I'm surprised that you're only the second guy to
  whine!  Given how much the situation in Iraq reminds the 1968
  invasion of Czechoslovakia by the brother armies of several
  communist countries led by the USSR, how devastated the soldiers
  were when they realized they weren't the saviors their /politruks/
  made them believe... I'm quite surprised the morale is so high.

  So much for the topic of my signature. It will stay there of course,
  at least until your country, which BTW recently passed a bill that
  basically negates the Geneva conventions, attacks my country. Czech
  republic is lucky enough to have no large amounts of strategic
  minerals, but will probably be one of the last pieces of land when
  the US industry and DMCA-controlled SUV-driving consumers unbound by
  the Kyoto protocol produce enough smog to melt the Antarctida, and
  land becomes more important than oil. Until then...


Boomers, as in Baby Boomers, were the generation of Americans who fought

in

Vietnam. The folks your closing lines refer to.  Do you get it now?


  Yeah, Baby Boom is a term known to me. I'm was born in 1975, during
  a baby boom in Czechoslovakia, predecessor of Czech rep. I'm not
  used to the capitalization though, and wasn't sure if Boomer wasn't
  meant as the surname of a person relevant to the rest of your
  message. Thanks for the clarification.


Re: [PHP] foreach

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 1:14 pm, João Cândido de Souza Neto wrote:
 $numbers=array(1,2,3,4,5);
 foreach ($numbers as number) {
 ...
 }

 Inside foreach, could i know if i am in the last element of the array
 $numbers?

In general, you can't.

If the elements are unique, you could do:

$last = end($numbers);
   ...
   if ($last == $number) this is the end;

Most people who want this feature are trying to suppress outputting
a comma or other separator after the last item because they have not
yet figured out how to use this function:
http://php.net/implode

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Question about Arrays

2006-10-10 Thread Richard Lynch
On Tue, October 10, 2006 1:04 pm, Alex Major wrote:
 I have a table, which contains 'setting' information for my website.
 The table has the following columns: setting_id, setting_name and
 setting_value.
 Now there are currently 30 settings stored in this table, however i am
 having trouble pulling values out on a 'as needed' basis.

For only 30 items in a table like this, I would have an include file
that just pulled them all down and put them in an array and be done
with it.

The query and loop for 30 items will be chump-change in your overall
resource usage.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] need help to build a query

2006-10-10 Thread Richard Lynch
In MySQL, you can do explain $query to see what MySQL estimates will
be the workload.

Interpreting that output is more art than science, but with practice,
you can at least avoid SOME querie that will drive your server to its
knees.

I did work on a PostgreSQL search engine once where we did a similar
thing in the program and just bailed out if the search was clearly
going to take far too long.  Kind of nifty, really...

On Mon, October 9, 2006 3:50 pm, [EMAIL PROTECTED] wrote:
 while I was trying again I did something wrong (?) and my server is
 now
 busy and looks like it went down?!?

 The qestion is how can I check first query before I apply it to be
 sure
 I'm not goig to read every record in my DB or get into loop?

 thanks.

 -afan

 On 10/9/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 but I know there must be much better solution then this one.

 You're right: Simply JOIN your queries...

 SELECT order_id, order_date, order_status, file_name
 FROM orders
 JOIN uploaded_files AS uf ON orders.order_id = uf.order_id
 ORDER BY orders.order_id DESC
 LIMIT 100

 HTH,
 John W



 thanks for any help.

 -afan

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




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




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] ECHO $variable

2006-10-10 Thread benifactor
thank you for schooling me :)  i learn something new everyday!
- Original Message - 
From: Richard Lynch [EMAIL PROTECTED]
To: benifactor [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Monday, October 09, 2006 11:02 AM
Subject: Re: [PHP] ECHO $variable


 On Mon, October 9, 2006 7:45 am, benifactor wrote:
  the way i posted worked fine with out either... he doesn't need to use
  these
  to format the way his output is displayed, he only needs to use the
  proper
  php syntax if i am correct.
 
 You were wrong, and you're still wrong. :-)
 
 Try it and see.
 
 http://php.net/htmlentities is the correct solution.
 
 htmlspecialchars only catches a tiny subset of what *might* be in the
 string...   So it will work if you can guarantee that only those
 limited set of chars will ever be in there.
 
 -- 
 Some people have a gift link here.
 Know what I want?
 I want you to buy a CD from some starving artist.
 http://cdbaby.com/browse/from/lynch
 Yeah, I get a buck. So?
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP] Working with overly aggressive anti-spam measures

2006-10-10 Thread Travis Doherty
Dave M G wrote:

 1. Spamassassin says:

 Spam detection software, running on the system homebase, has
 identified this incoming email as possible spam.  [...]

 Content analysis details:   (0.3 points, 5.0 required)

 pts rule name  description
  --
 --
 0.3 AWLAWL: From: address is in the auto white-list

 I looked up about auto white-lists on the net, and it says that it's a
 comparison between the current and previous emails. But for testing
 purposes, I don't really want it to compare against previous emails,
 since previous test emails would be spammier and bias spamassassin
 the wrong way.

 How can I compensate for this?

Yup, as you mentioned the AWL (auto-white-list) is a comparison to
previous messages.  If that is the only rule that gets hit it looks like
you are doing pretty good.  You did include the body of the message in
the test right?  Not just the headers?

I expected you would have hit more rules than that.  Of course, that is
an 'out-of-the-box' install of SA, most people have special rules in
there, bayes training done, etc...  I believe there is also a website
that you can copy paste the message into to perform the same test (see
message on this list, Peter Lauri - PHP Mailer and SMTP = SPAM?)  That
site might have other rules configured (SARE... etc) that you might be
hitting.  Worth a shot.

Travis Doherty

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



Re: [PHP] Using mysql_real_escape_string

2006-10-10 Thread Richard Lynch
On Mon, October 9, 2006 1:53 pm, Alan Milnes wrote:
 $filename=input/w2wcheck.txt;

 echo h2$filename/h2;

 # Open file
 $fptr = fopen($filename, r);

 # Check if file is open
 if($fptr) {
 $current_line = fgets($fptr,4096);

 $retval = TRUE;
 echo open;

   while($current_line  $retval)
 {

It *might* be slightly faster/better to do:
array_walk($current_line, 'mysql_real_escape_string')
if you're sure you're not going to use $current_line for anything
other than putting the data into SQL.

If this is a CSV file, you may want to use fgetcsv() as it will handle
the grungy details of embedded commas and quotes and spiders and
snakes.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] need help to build a query

2006-10-10 Thread John Wells

On 10/10/06, Richard Lynch [EMAIL PROTECTED] wrote:


This is a lot more subtle problem than it seems at first glance, eh?


Yup, sure is.  Thanks for the detailed response, so helpful as always.

-John W



--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?




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



[PHP] OOP slow -- am I an idiot?

2006-10-10 Thread Chris de Vidal
I think perhaps I'm using classes and OOP incorrectly.  The last time I used 
them, they were slow.

I want to create a customer class which fetches its attributes from a MySQL 
database.  Something
like this pseudocode:

class customer
{
...
getName ($id)
{
$result = mysql_query (SELECT name FROM customers WHERE id = '$id');
return mysql_result ($result, 0);
}
getRevenue ($id,$department,$month,$year)
{
$result = mysql_query (SELECT revenue FROM customer_revenue WHERE 
customer_id = '$id' AND
department = '$department' AND month = '$month' AND year = '$year');
return mysql_result ($result, 0);
}
...
}

(Again, that's just psedocode.  Haven't written anything yet.)


That works great for just one revenue result, but what if I want to return 
several results?  What
if I want to build a report with hundreds of customers' revenues for a month?  
For several months?
 For an entire year?  Doesn't it slow wa down?  It seemed to in the past.  
The method above
doesn't seem to scale well.

I did something like the above a few years ago.  It was slow, and I think it's 
because it was
doing this for each single row:
* Instantiate the class
* Perform a query for the name
* Perform a query for the first department
* Perform a query for the next department
* Perform a query for the next department
* Perform a query for the next department
* Perform a query for the next department
* Perform a query for the next department
* Perform a query for the next department
...
* Destroy the instantiation
* Start over

I love using object-oriented programming, but it seems to me that's ALOT of 
performance burden
when I could just do something like this:
SELECT customers.name,
   customer_revenue.revenue
FROM   customers
INNER JOIN customer_revenue
ON customers.id = customer_revenue.customer_id
WHERE  customer_revenue.department = '$department'
ANDcustomer_revenue.month = '$month'
ANDcustomer_revenue.year  = '$year'

(PHP loop to display all results)


That seems like it would perform 20x faster.

It seems that the SQL economies of scale (ability to rapidly slurp large sets 
of data) are
completely bypassed when using OOP to view ALOT of objects together on one 
screen.  It seems if I
want decent performance I would have to ignore OOP rules of method hiding and 
access the data
directly when using anything more than just a few objects on one page.


A workaround -- I thought that perhaps I could fetch ALL of the data for a 
customer into memory
upon initial instantiation, wherein I perform something like this:
SELECT *
FROM   customers
INNER JOIN customer_revenue
ON customers.id = customer_revenue.customer_id
WHERE  customers.id = '$id'

And then use the results from memory as-needed.  It would be all data for a 
customer from all
years across all departments.

That might perform better but it'd suck ALOT of data into memory, and what if I 
add more than just
revenue to my customer class?  Each customer could potentially represent a 
limitless set of data. 
So this doesn't seem like an optimal solution.


* Where am I going wrong?
* Tell me how YOU fetch data from multiple objects to generate reports.
* Is this an instance where it's better to just ignore OOP rules and go 
straight to the data? 
Whew, that's not fun to think about, particularly if my queries ever get to be 
more complex.

Feedback, please.  The goal is to maintain complex queries in just one place -- 
inside a class.  I
want my data to _only_ be accessed from the black box called an OOP class.

CD

Think you're a good person?  Yeah, right!  ;-)
Prove it and get ten thousand dollars:
TenThousandDollarOffer.com

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-10 Thread Chris

Chris de Vidal wrote:

I think perhaps I'm using classes and OOP incorrectly.  The last time I used 
them, they were slow.


The examples you provided shows that it's not OOP that's the problem, 
it's how your getting the data as you suspected.


Doing tons of queries is going to be slow whether you're using OOP or 
functional programming.


Depending on your app, you could pass in arrays of data:

getRevenue($customer_id, $departments=array(), $years_to_fetch=array()) {
... sanitize $departments and $years_to_fetch

  $query = SELECT revenue FROM customer_revenue WHERE customer_id = 
'$customer_id' AND department IN ( . $departments . ) AND year IN ( . 
$years_to_fetch . );

}

Because php is loosely typed you can take advantage of that.

Only want to pass in one department? Change it to be an array and go 
from there:


if (!is_array($departments)) {
  $departments = array($departments);
}


Depends a lot on the situation as well. If it's for a report that's 
going to be run once a year, a few extra queries probably isn't going to 
make any difference. Something that gets called every time? Optimize it 
as much as possible.


I've used both methods and they both have their merits.

Context is important too :) If I need to create a queue of items to go 
through (eg the web interface creates a queue for a cron job to pick up 
and process), then I'll do everything straight in the database and 
nothing in PHP (well as much as possible anyway) by passing in 
everything I need and writing a query to handle it all.



After all that, I probably didn't help much ;)

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] OOP slow -- am I an idiot?

2006-10-10 Thread Larry Garfield
For your rudimentary example of object-relational mapping below, yes, 
performance is going to be atrocious.  That's because you're not taking any 
advantage of the features that using OOP gives you.  One could write a 
dissertation on this problem, but I will just give you some general 
guidelines.  (All code examples below assume PHP 5.)

1) OOP has overhead.  In most situations, if you can write something in a 
fully OOP fashion or a direct procedural fashion, the direct procedural will 
perform faster.  How much faster depends on the situation and the experience 
level of the programmer.  What OOP can get you is flexibility.  There are 
cases where OOP code is faster than the corresponding procedural, but none of 
them involve SQL. :-)

2) Burn some memory on private variables.  That's what they're there for.  Eg:

public class Foo {
  private $id=0;
  private $bar=0;
  private $baz='';

  function __construct($id) {
//  Do your type checking and escaping here
$result = mysql_query(SELECT * FROM Foo WHERE id={$id});  
$record = mysql_fetch_object($result);
$this-id = record-id;
$this-bar = record-bar;
$this-baz = record-baz;
  }

  function getBaz() {
return $this-baz;
  }
}

You'll want to be a lot smarter than the code above to avoid drudge work in 
the code, but you get the idea.  Front-load as much of the object's 
information has you can in the constructor, within reason.  A good rule of 
thumb is that anything you can get in the initial query (like above) you 
should and then cache.  That saves you putting wasteful SQL queries in your 
getters.

3) Data you have to load later from another table, delay until you need to get 
it but then cache that as well.

function getRevenue ($id,$department,$month,$year) {
  if (!$this-revenue) {
        $result = mysql_query (SELECT revenue FROM customer_revenue WHERE 
customer_id = '$id' AND
department = '$department' AND month = '$month' AND year = '$year');
 $this-revenue = mysql_result ($result, 0);
  }
  return $this-revenue;
}

Again, pull extra data if you can.  A somewhat larger result set is (usually) 
better than multiple queries.  How much you want to front-load in your object 
and how much you want to defer to later depends on your specific problem and 
how frequently the data will be used.  

4) You can optimize your SQL structure for easier object usage.  Often that 
just means proper normalization, sometimes you'll want to denormalize in 
specific places to improve performance.  Again, depends on your situation.

5) If you need to grab 100 objects at once, but just need basic data out of 
them, use a factory.  Vis, 

$myobjects = Foo::getObjects(array(1, 2, 3));

class Foo {

  static function getObjects($ids) {
$return = array();
$result = mysql_query(SELECT * FROM Foo WHERE id IN ( . implode(',', 
$ids) . ));
while ($record = mysql_fetch_object($result)) {
  $foo = new Foo();
  $foo-setProperties($record);
  $return[] = clone($foo);
   }
   return $return;
  }

  function setProperties($properties) {
// Left as an exercise to the reader
  }
}

6) If you need to do a complex query with a couple of joins and such, then 
don't waste your time or the computer's trying to shoe-horn it into SQL.  SQL 
is not inherently OO to start with!  Just write your query and loop it and be 
happy.  OOP is not the answer to all problems.  Sometimes it does just make 
matters worse, no matter what Sun tries to tell you. :-)

  I want my data to _only_ be accessed from the black box called an OOP
  class. 

That will work and is achievable in about 30% of all situations.  For the 
other 70%, you will have to just hunker down and *gasp* write SQL specific to 
the task at hand at least some of the time.  How much of the time once again 
depends on your situation and the problem you're trying to solve.

On Tuesday 10 October 2006 18:14, Chris de Vidal wrote:
 I think perhaps I'm using classes and OOP incorrectly.  The last time I
 used them, they were slow.

 I want to create a customer class which fetches its attributes from a
 MySQL database.  Something like this pseudocode:

 class customer
 {
 ...
 getName ($id)
 {
 $result = mysql_query (SELECT name FROM customers WHERE id =
 '$id'); return mysql_result ($result, 0);
 }
 getRevenue ($id,$department,$month,$year)
 {
 $result = mysql_query (SELECT revenue FROM customer_revenue WHERE
 customer_id = '$id' AND department = '$department' AND month = '$month' AND
 year = '$year'); return mysql_result ($result, 0);
 }
 ...
 }

 (Again, that's just psedocode.  Haven't written anything yet.)


 That works great for just one revenue result, but what if I want to return
 several results?  What if I want to build a report with hundreds of
 customers' revenues for a month?  For several months? For an entire year? 
 Doesn't it slow wa down?  It seemed to in the past.  The method above
 

Re: [PHP] OOP slow -- am I an idiot?

2006-10-10 Thread Johan Martin


On 10 Oct 2006, at 4:14 PM, Chris de Vidal wrote:

I think perhaps I'm using classes and OOP incorrectly.  The last  
time I used them, they were slow.


I want to create a customer class which fetches its attributes  
from a MySQL database.  Something

like this pseudocode:

class customer
{
...
getName ($id)
{
$result = mysql_query (SELECT name FROM customers WHERE id  
= '$id');

return mysql_result ($result, 0);
}
getRevenue ($id,$department,$month,$year)
{
$result = mysql_query (SELECT revenue FROM  
customer_revenue WHERE customer_id = '$id' AND

department = '$department' AND month = '$month' AND year = '$year');
return mysql_result ($result, 0);
}
...
}



You should look into getting Professional PHP5 by Lecky-Thompson,  
Eide-Goodman, Nowicki and Cove from WROX. It's a good introduction to  
using PHP5 with design patterns to solve problems similar to yours.  
Plus, the knowledge can be applied to other object oriented  
programming languages, not just PHP5. It's also been out for a while  
so it may be in the sale section already.


The collection class in chapter 5 discusses a programming problem  
just like yours.



Johan Martin
Catenare LLC
534 Pacific Ave
San Francisco, CA. 94133

http://www.catenare.com

http://www.linkedin.com/in/catenare

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



Re: [PHP] Working with overly aggressive anti-spam measures [SOLVED]

2006-10-10 Thread Dave M G

Travis, Richard, Chris,

Thank you for your helpful advice.

I've managed to set the Return-Path correctly now, and Spamassassin is 
now only giving me the whitelist error, which I don't think I'm going to 
get rid of.


It took me a little while to realize that the Spamassassin always says 
that an email is possible scam if it has any score above zero, but it 
takes a score of 5.0 to actually be deleted as spam. I checked through a 
bunch of emails in my inbox, and all of them got at least some score, 
usually between .5 and 1.5, even though they were all legitimate emails.


So compared to other emails I'm getting, I'm scoring very low at 0.2. My 
emails don't use HTML, don't have any common spam key words, and have 
correct spelling and grammar, so it all helps establish my email's 
legitimacy.


Here is the PHP code I'm using:

$fromAddress = [EMAIL PROTECTED];
$fromName = My Name;
$headers = From:  . $fromName .   . $fromAddress . \n;
$headers .= Reply-to:  . $fromName .   . $fromAddress . \n;
$extra = -f . $fromAddress;

mail($toAddress, $subject, $content, $headers, $extra);

Thank you all for your time and expert information.

--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2

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



Re: [PHP] Seperate HTML from PHP

2006-10-10 Thread Chris

Sancar Saran wrote:
Hi there, following words are my ideas about that HTML PHP parting. I hope you 
can understand my broken english and do not take personally.


SEPERATING html FROM php ARE USELESS


Try customising a CMS (any open source) with html embedded in the php...

Good luck and get back to us (in a few years) when you have it completed.

--
Postgresql  php tutorials
http://www.designmagick.com/

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



[PHP] Re: OOP slow -- am I an idiot?

2006-10-10 Thread Manuel Lemos
Hello,

on 10/10/2006 08:14 PM Chris de Vidal said the following:
 I think perhaps I'm using classes and OOP incorrectly.  The last time
I used them, they were slow.

Your problem has nothing to do with OOP . It is the number of queries
that are making it solow. Creating an object takes microseconds.
Executing a query can take seconds.

Your greatest problem is that you use a query to retrieve each database
table row. If you want to retrieve many or all rows, a single query
approach is obviously much more efficient. That is true regardless you
use OOP to execute the queries or not.

The problem of using a lot of memory has only to do with using MySQL
buffered queries. You can also use unbuffered queries like with most
other databases but while your whole result set is not retrieved, it may
keep your database table locked.

Another detail, for retrieving large result sets with data from multiple
tables for reports or any other form of read only bulk processing, using
ORM (Object-relational mapping) is not very efficient. Retrieving whole
data into arrays with a single query is a more adequate solution.

On a related subject, you may want to take a look at a Metastorage. This
is an ORM class generator tool. For storing and retrieving single table
rows into objects, it generates simple ORM classes. But for read only
bulk data processing, it can generate what is called report classes.

These classes execute compiled SQL queries picking whatever columns and
conditions that match your needs and return the data in arrays either
all rows at once or a single row at a time.

http://www.metastorage.net/


-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



Re: [PHP] Stored procs and transactions using Linux/PHP and Windows/MSSQL

2006-10-10 Thread Chris

Rick Emery wrote:
Is anyone using PHP5 on Linux to connect to MS SQL Server 2000 on 
Windows and execute stored procedures with output parameters within a 
transaction? If so, how?


I'm trying to do something like this in the PHP application:

begin transaction
execute a stored procedure, receiving an identity back
if certain conditions are met
   execute another stored procedure, getting an identity
if certain other conditions are met
   execute another stored procedure, getting an identity
if any of the above procedures fail
   rollback transaction
else
   commit transaction


Can you do this in mssql (ie take php out of the picture) ?

That is - if you execute a procedure, can you get the identity back?

I have no idea about mssql but that would be my first check..

--
Postgresql  php tutorials
http://www.designmagick.com/

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



[PHP] moving to other web server

2006-10-10 Thread Afan Pasalic

hi to all,
we are moving our web server from one to other hosting company. we have 
chance to request what version of php i want to be installed, 4 or 5. 
Current web server works on php 4.3.4 we don't use any classes, 
functions only. as far as I know, in our case moving from 4 to 5 
shouldn't be any problem, no concerns. but, anyway, where can I expect 
errors - except in oop?


thanks for any help.

-afan

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



[PHP] Re: moving to other web server

2006-10-10 Thread David Robley
Afan Pasalic wrote:

 hi to all,
 we are moving our web server from one to other hosting company. we have
 chance to request what version of php i want to be installed, 4 or 5.
 Current web server works on php 4.3.4 we don't use any classes,
 functions only. as far as I know, in our case moving from 4 to 5
 shouldn't be any problem, no concerns. but, anyway, where can I expect
 errors - except in oop?
 
 thanks for any help.
 
 -afan

If you currently use a variable named $this you can expect problems.


Cheers
-- 
David Robley

2 + 2 = 4 (for the time being).
Today is Prickle-Prickle, the 65th day of Bureaucracy in the YOLD 3172. 

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



Re: [PHP] Re: moving to other web server

2006-10-10 Thread Chris

David Robley wrote:

Afan Pasalic wrote:


hi to all,
we are moving our web server from one to other hosting company. we have
chance to request what version of php i want to be installed, 4 or 5.
Current web server works on php 4.3.4 we don't use any classes,
functions only. as far as I know, in our case moving from 4 to 5
shouldn't be any problem, no concerns. but, anyway, where can I expect
errors - except in oop?

thanks for any help.

-afan


If you currently use a variable named $this you can expect problems.


Care to elaborate? I use that all the time on both php4  php5 servers 
and it works fine.


--
Postgresql  php tutorials
http://www.designmagick.com/

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