php-general Digest 25 Jun 2010 13:06:20 -0000 Issue 6815
php-general Digest 25 Jun 2010 13:06:20 - Issue 6815 Topics (messages 306409 through 306423): Re: Unexpected behaviour from define() 306409 by: James Long 306410 by: Tim Schofield 306411 by: Ashley Sheridan 306412 by: Tim Schofield 306422 by: Richard Quadling Re: Quick session question 306413 by: Danny 306414 by: Danny 306416 by: Danny Re: Quick session question [SOLVED] 306415 by: Danny in_array - what the... 306417 by: Gary . 306418 by: Ford, Mike 306419 by: Gary . 306420 by: Ford, Mike Re: Making a Password Confirmation in PHP 306421 by: Richard Quadling 306423 by: Andrew Ballard Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On Thu, Jun 24, 2010 at 02:41:51PM -0700, James Long wrote: Perhaps I am missing something basic here. Why does the LOG_WARNING constant take on a value of 4, when it is defined with a value of 1? Thank you! Jim Answering my own question here LOG_WARNING is already defined elsewhere it seems, by the Network function define_syslog_variables: $ cat bug.php ? //define( 'LOG_NORMAL', 0 ); //define( 'LOG_WARNING', 1 ); //define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? $ php bug.php LOG_NORMAL LOG_NORMAL LOG_WARNING 4 LOG_ERROR LOG_ERROR $ ---End Message--- ---BeginMessage--- On 24/06/10 22:41, James Long wrote: Perhaps I am missing something basic here. Why does the LOG_WARNING constant take on a value of 4, when it is defined with a value of 1? Thank you! Jim $ cat bug.php ? define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNING', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? $ php bug.php LOG_NORMAL 0 LOG_WARNING 4 LOG_ERROR 2 $ Very strange, as ? define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNiNG', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNiNG ' . LOG_WARNiNG . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? seems to work fine Tim ---End Message--- ---BeginMessage--- On Thu, 2010-06-24 at 23:02 +0100, Tim Schofield wrote: On 24/06/10 22:41, James Long wrote: Perhaps I am missing something basic here. Why does the LOG_WARNING constant take on a value of 4, when it is defined with a value of 1? Thank you! Jim $ cat bug.php ? define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNING', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? $ php bug.php LOG_NORMAL 0 LOG_WARNING 4 LOG_ERROR 2 $ Very strange, as ? define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNiNG', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNiNG ' . LOG_WARNiNG . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? seems to work fine Tim It would, you misspelt LOG_WARNING with a lowercase 'i' ;) Thanks, Ash http://www.ashleysheridan.co.uk ---End Message--- ---BeginMessage--- On 24/06/10 23:08, Ashley Sheridan wrote: On Thu, 2010-06-24 at 23:02 +0100, Tim Schofield wrote: Very strange, as ? define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNiNG', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL .\n; echo 'LOG_WARNiNG ' . LOG_WARNiNG .\n; echo 'LOG_ERROR ' . LOG_ERROR .\n; ? seems to work fine Tim It would, you misspelt LOG_WARNING with a lowercase 'i' ;) Thanks, Ash http://www.ashleysheridan.co.uk Thats what I was trying to illustrate, it worked with lower case i but not with upper case, but James has explained it. Thanks Tim ---End Message--- ---BeginMessage--- On 24 June 2010 22:41, James Long p...@umpquanet.com wrote: ?php error_reporting(-1); ini_set('display_errors', 1); define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNING', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? outputs ... Notice: Constant LOG_WARNING already defined in - on line 4 LOG_NORMAL 0 LOG_WARNING 5 LOG_ERROR 2 I'm on Win32 PHP 5.3.3-RC1 (cli) (built: Jun 17 2010 22:43:29) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
[PHP] in_array - what the...
If I have an array that looks like array(1) { [mac_address]= string(2) td } and I call if (in_array($name, self::$aboveArray)) with $name as string(11) mac_address what should be the result? Because it is *false* and it is driving me nuts! This despite the fact that if I do $foo = self::$aboveArray[$name]; $foo then has the value string(2) td Am I not understanding what in_array does? Is there some bug in php that has been present since 5.2.12 and still is? *bangs head against desk* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] in_array - what the...
-Original Message- From: Gary . [mailto:php-gene...@garydjones.name] Sent: 25 June 2010 08:18 To: PHP Subject: [PHP] in_array - what the... If I have an array that looks like array(1) { [mac_address]= string(2) td } and I call if (in_array($name, self::$aboveArray)) with $name as string(11) mac_address what should be the result? FALSE -- in_array checks the *values*, not the keys, so would be looking at the td for this element. To do what you want to do, simply do an isset(): if (isset($array['mac_address'])): // do stuff with $array['mac_address'] else: // it doesn't exist endif; Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] in_array - what the...
Ford, Mike writes: -Original Message- If I have an array that looks like array(1) { [mac_address]= string(2) td } and I call if (in_array($name, self::$aboveArray)) with $name as string(11) mac_address what should be the result? FALSE -- in_array checks the *values*, not the keys, so would be looking at the td for this element. Agh! So it does. You know what's worse? I even looked at the documentation of the function this morning wondering if that's what the problem was and *still* didn't see it! *slinks away in embarrassment* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] in_array - what the...
-Original Message- From: Gary . [mailto:php-gene...@garydjones.name] Sent: 25 June 2010 09:14 To: PHP Subject: Re: [PHP] in_array - what the... Ford, Mike writes: -Original Message- If I have an array that looks like array(1) { [mac_address]= string(2) td } and I call if (in_array($name, self::$aboveArray)) with $name as string(11) mac_address what should be the result? FALSE -- in_array checks the *values*, not the keys, so would be looking at the td for this element. Agh! So it does. You know what's worse? I even looked at the documentation of the function this morning wondering if that's what the problem was and *still* didn't see it! *slinks away in embarrassment* Not to worry -- happens to the best of us. (Been there, done that, got a wardrobe full of T-shirts!) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Password Confirmation in PHP
On 24 June 2010 19:46, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, 2010-06-24 at 20:37 +0200, David Česal wrote: Yes, it is. D -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Thursday, June 24, 2010 8:32 PM To: Floyd Resler Cc: PHP Subject: Re: [PHP] Making a Password Confirmation in PHP On Thu, 2010-06-24 at 14:29 -0400, Floyd Resler wrote: On Jun 24, 2010, at 2:22 PM, Michael Calkins wrote: This is very straight forward, if password a and b are not equal to each other, how can I let the user know that with out losing all of the entered information on the registration form? I was trying this: ---$p1 = input type=\password\ name=\usr_p1\ /; $p2 = input type=\password\ name=\usr_p2\ /; // if they didn't match return $p1 = input type=\password\ name=\usr_p1\ value=\ . $p1 . \/;--- I was trying to change the value of the variable which shows the input field to have the password already in it. and either one would just be echo'd depending on the result. Any ideas please? From,Michael calkinsmichaelcalk...@live.com If you aren't opposed to using JavaScript, I'd do it there. If you don't want to use JavaScript then you can load the form data from the $_POST (or $_GET) array that was passed back to your script. Take care, Floyd Is Javascript allowed to read the value of password boxes? I was of the understanding that it couldn't, so checking if a password field matches another is pretty moot. Thanks, Ash http://www.ashleysheridan.co.uk Yes, so it does. That seems like a bit of a flaw in Javascript on security grounds. And the fact that a browser will transmit input type=password as plain text isn't a security issue? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unexpected behaviour from define()
On 24 June 2010 22:41, James Long p...@umpquanet.com wrote: ?php error_reporting(-1); ini_set('display_errors', 1); define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNING', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? outputs ... Notice: Constant LOG_WARNING already defined in - on line 4 LOG_NORMAL 0 LOG_WARNING 5 LOG_ERROR 2 I'm on Win32 PHP 5.3.3-RC1 (cli) (built: Jun 17 2010 22:43:29) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Password Confirmation in PHP
On Fri, Jun 25, 2010 at 5:35 AM, Richard Quadling rquadl...@gmail.com wrote: And the fact that a browser will transmit input type=password as plain text isn't a security issue? That's what SSL is for. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Attachment to email from form.
I am trying to have an attachment to an email from a form. Email is working fine, am unable to get attachment. The attachment will be a word.doc. I am getting error message Warning: file_get_contents(attachment.zip) [function.file-get-contents]: failed to open stream: No such file or directory in /home/oneonel1/public_html/emailreminderresult.inc.php on line 24 Mail failed Line 24 reads: $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); here is the all of the code that I have removed the email addresses such. Can someone point me in the right direction? Thank you Gary ?php $fname=stripslashes($_POST['fname']); $lname=stripslashes($_POST['lname']); $email=stripslashes($_POST['email']); $comments=stripslashes($_POST['comments']); $ip= $_SERVER['REMOTE_ADDR']; $attachment = $_POST['attachment']; $attachment = $_FILES['attachment']['name']; $attachment_type = $_FILES['attachment']['type']; $attachment_size = $_FILES['attachment']['size']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = From: myemail\r\nReply-To: myemail.com; //add boundary string and mime type specification $headers .= \r\nContent-Type: multipart/mixed; boundary=\PHP-mixed-.$random_hash.\; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24 //define the body of the message. ob_start(); //Turn on output buffering //--PHP-mixed- echo $random_hash; //Content-Type: multipart/alternative; boundary=PHP-alt- echo $random_hash; //--PHP-alt- echo $random_hash; /* Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; /* Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; //--PHP-mixed- echo $random_hash; /* Content-Type: application/zip; name=attachment.zip Content-Transfer-Encoding: base64 Content-Disposition: attachment */ echo $attachment; //--PHP-mixed- echo $random_hash; //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print Mail sent. Otherwise print Mail failed echo $mail_sent ? Mail sent : Mail failed; echo Thank you for contacting b888!/bbr /br /; echo You have submitted the following information:br /br /; echo Name: $fname $lnamebr /; echo E-Mail Address: $emailbr /; echo Your comments or request: $commentsbr /br /br /; echo We have also sent you an e-mail to $email with the submitted information as well as our contact information for your convienience. br /br / Thank you for the opportunity to serve you!; /*This is the email message to submitter*/ $contact=888\n 888\n 888; $from_d=$email; $to_d=$email; $subject_d='Thank you from 888'; $msg_d=Thank you $fname for your submission, find our contact information listed for your convenience.\n\n .$contact\n\n . You have submitted the following information\n\n . Name: $fname $lname \n . E-Mail Address: $email\n . Comments: $comments\n ; mail($to_d, $subject_d, $msg_d, 'From:' . $from_d); /*this is to form owner, */ $from=$email; $to=myemail; $subject=Submission from 888; $msg= This is a submission from 888com. \n\n . Clients Name: $fname . $lname \n . Email Address: $email\n . Comments: $comments\n ; mail($to, $subject, $msg, 'From:' .$from); ? __ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Returning a Recordset from a Funtion
Hi Folks, Upon occasion, I have the need to hit our MS MSL database from our PHP/mySQL server. So I've created a function, but I'm not sure if you can return a recordset from a function. My code is below... In the calling page I code: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? The mssql.php include file is: ?php function hitMSSQL($server,$db,$login,$pass,$query){ $conn = new COM (ADODB.Connection) or die(Cannot start ADO); $connStr = PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.; DATABASE=.$db; $conn-open($connStr); $rs = $conn-execute($query); return $rs; } ? If I have the echo statement in the function, it works. And of course I can return a single value like: Return $rs-Fields(value); But I can't return the whole recordset... Does anyone have any good ideas so I can access the recordset in the calling page? Thanks!
Re: [PHP] Attachment to email from form.
First of all, take a look at http://docs.php.net/manual/en/features.file-upload.php You are trying to open a named file (attachment.zip), but that may not be what was uploaded. The 2 main functions to get to grips with are ... is_uploaded_file() and move_uploaded_file(). Uploaded files are not best directly accessed. Instead they should be moved from the temp directory (assuming the server is set to temporarily store uploaded files there) to a proper location for use later on in the script. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Returning a Recordset from a Funtion
On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? You are not catching the result of the hitMSSQL() function. Try ... ?php include('../includes/mssql.php'); $rs = hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attachment to email from form.
On Fri, 2010-06-25 at 09:51 -0400, Gary wrote: I am trying to have an attachment to an email from a form. Email is working fine, am unable to get attachment. The attachment will be a word.doc. I am getting error message Warning: file_get_contents(attachment.zip) [function.file-get-contents]: failed to open stream: No such file or directory in /home/oneonel1/public_html/emailreminderresult.inc.php on line 24 Mail failed Line 24 reads: $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); here is the all of the code that I have removed the email addresses such. Can someone point me in the right direction? Thank you Gary ?php $fname=stripslashes($_POST['fname']); $lname=stripslashes($_POST['lname']); $email=stripslashes($_POST['email']); $comments=stripslashes($_POST['comments']); $ip= $_SERVER['REMOTE_ADDR']; $attachment = $_POST['attachment']; $attachment = $_FILES['attachment']['name']; $attachment_type = $_FILES['attachment']['type']; $attachment_size = $_FILES['attachment']['size']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = From: myemail\r\nReply-To: myemail.com; //add boundary string and mime type specification $headers .= \r\nContent-Type: multipart/mixed; boundary=\PHP-mixed-.$random_hash.\; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24 //define the body of the message. ob_start(); //Turn on output buffering //--PHP-mixed- echo $random_hash; //Content-Type: multipart/alternative; boundary=PHP-alt- echo $random_hash; //--PHP-alt- echo $random_hash; /* Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; /* Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; //--PHP-mixed- echo $random_hash; /* Content-Type: application/zip; name=attachment.zip Content-Transfer-Encoding: base64 Content-Disposition: attachment */ echo $attachment; //--PHP-mixed- echo $random_hash; //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print Mail sent. Otherwise print Mail failed echo $mail_sent ? Mail sent : Mail failed; echo Thank you for contacting b888!/bbr /br /; echo You have submitted the following information:br /br /; echo Name: $fname $lnamebr /; echo E-Mail Address: $emailbr /; echo Your comments or request: $commentsbr /br /br /; echo We have also sent you an e-mail to $email with the submitted information as well as our contact information for your convienience. br /br / Thank you for the opportunity to serve you!; /*This is the email message to submitter*/ $contact=888\n 888\n 888; $from_d=$email; $to_d=$email; $subject_d='Thank you from 888'; $msg_d=Thank you $fname for your submission, find our contact information listed for your convenience.\n\n .$contact\n\n . You have submitted the following information\n\n . Name: $fname $lname \n . E-Mail Address: $email\n . Comments: $comments\n ; mail($to_d, $subject_d, $msg_d, 'From:' . $from_d); /*this is to form owner, */ $from=$email; $to=myemail; $subject=Submission from 888; $msg= This is a submission from 888com. \n\n . Clients Name: $fname . $lname \n . Email Address: $email\n . Comments: $comments\n ; mail($to, $subject, $msg, 'From:' .$from); ? __ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Your script can't find the attachment.zip file. As you're using a relative path to it, it should be in the same directory as your php script, or somewhere directly in the path environment variable. Also, make sure that the file has read properties set to allow Apache to read it. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] Returning a Recordset from a Funtion
Tried that - I finally got it - in the function I had to return the actual query execute, instead of the recordset. This did not work: $rs = $conn-execute($query); Return $rs; This DID work: Return $conn-execute($query); Thanks for the reply! -Original Message- From: Richard Quadling [mailto:rquadl...@gmail.com] Sent: Friday, June 25, 2010 9:59 AM To: David Stoltz Cc: php-general@lists.php.net Subject: Re: [PHP] Returning a Recordset from a Funtion On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? You are not catching the result of the hitMSSQL() function. Try ... ?php include('../includes/mssql.php'); $rs = hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
Re: [PHP] Returning a Recordset from a Funtion
On 25 June 2010 15:07, David Stoltz dsto...@shh.org wrote: Tried that - I finally got it - in the function I had to return the actual query execute, instead of the recordset. This did not work: $rs = $conn-execute($query); Return $rs; This DID work: Return $conn-execute($query); Thanks for the reply! -Original Message- From: Richard Quadling [mailto:rquadl...@gmail.com] Sent: Friday, June 25, 2010 9:59 AM To: David Stoltz Cc: php-general@lists.php.net Subject: Re: [PHP] Returning a Recordset from a Funtion On 25 June 2010 14:55, David Stoltz dsto...@shh.org wrote: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? You are not catching the result of the hitMSSQL() function. Try ... ?php include('../includes/mssql.php'); $rs = hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling Can you ... var_dump($rs); in the function? I'd be very surprised that ... return $rs; with $rs = your_func(); didn't work. So much so, I'm guessing you are not showing the whole story somewhere. Pretty much without exception, $rs = $conn-execute($query); return $rs; is the same as ... return $conn-execute($query); Richard. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Returning a Recordset from a Funtion
On Fri, Jun 25, 2010 at 9:55 AM, David Stoltz dsto...@shh.org wrote: Hi Folks, Upon occasion, I have the need to hit our MS MSL database from our PHP/mySQL server. So I've created a function, but I'm not sure if you can return a recordset from a function. My code is below... In the calling page I code: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? The mssql.php include file is: ?php function hitMSSQL($server,$db,$login,$pass,$query){ $conn = new COM (ADODB.Connection) or die(Cannot start ADO); $connStr = PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.; DATABASE=.$db; $conn-open($connStr); $rs = $conn-execute($query); return $rs; } ? If I have the echo statement in the function, it works. And of course I can return a single value like: Return $rs-Fields(value); But I can't return the whole recordset... Does anyone have any good ideas so I can access the recordset in the calling page? Thanks! Is there a reason you need to work with COM/ADODB to get the information from SQL Server as opposed to one of the PHP libraries? If your are using COM you must be running under Windows which means you should be able to use Microsoft's SQL Server Driver for PHP, which is the best tool I've seen to date for the task. There are also the older mssql and the newer PDO_MSSQL libraries, or even odbc or PDO_ODBC that will work OK in many cases as well. Any of these are much simpler to work with than COM variants in PHP. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attachment to email from form.
On Fri, Jun 25, 2010 at 9:59 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 09:51 -0400, Gary wrote: I am trying to have an attachment to an email from a form. Email is working fine, am unable to get attachment. The attachment will be a word.doc. I am getting error message Warning: file_get_contents(attachment.zip) [function.file-get-contents]: failed to open stream: No such file or directory in /home/oneonel1/public_html/emailreminderresult.inc.php on line 24 Mail failed Line 24 reads: $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); here is the all of the code that I have removed the email addresses such. Can someone point me in the right direction? Thank you Gary ?php $fname=stripslashes($_POST['fname']); $lname=stripslashes($_POST['lname']); $email=stripslashes($_POST['email']); $comments=stripslashes($_POST['comments']); $ip= $_SERVER['REMOTE_ADDR']; $attachment = $_POST['attachment']; $attachment = $_FILES['attachment']['name']; $attachment_type = $_FILES['attachment']['type']; $attachment_size = $_FILES['attachment']['size']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = From: myemail\r\nReply-To: myemail.com; //add boundary string and mime type specification $headers .= \r\nContent-Type: multipart/mixed; boundary=\PHP-mixed-.$random_hash.\; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 24 //define the body of the message. ob_start(); //Turn on output buffering //--PHP-mixed- echo $random_hash; //Content-Type: multipart/alternative; boundary=PHP-alt- echo $random_hash; //--PHP-alt- echo $random_hash; /* Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; /* Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit */ //--PHP-alt- echo $random_hash; //--PHP-mixed- echo $random_hash; /* Content-Type: application/zip; name=attachment.zip Content-Transfer-Encoding: base64 Content-Disposition: attachment */ echo $attachment; //--PHP-mixed- echo $random_hash; //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print Mail sent. Otherwise print Mail failed echo $mail_sent ? Mail sent : Mail failed; echo Thank you for contacting b888!/bbr /br /; echo You have submitted the following information:br /br /; echo Name: $fname $lnamebr /; echo E-Mail Address: $emailbr /; echo Your comments or request: $commentsbr /br /br /; echo We have also sent you an e-mail to $email with the submitted information as well as our contact information for your convienience. br /br / Thank you for the opportunity to serve you!; /*This is the email message to submitter*/ $contact=888\n 888\n 888; $from_d=$email; $to_d=$email; $subject_d='Thank you from 888'; $msg_d=Thank you $fname for your submission, find our contact information listed for your convenience.\n\n .$contact\n\n . You have submitted the following information\n\n . Name: $fname $lname \n . E-Mail Address: $email\n . Comments: $comments\n ; mail($to_d, $subject_d, $msg_d, 'From:' . $from_d); /*this is to form owner, */ $from=$email; $to=myemail; $subject=Submission from 888; $msg= This is a submission from 888com. \n\n . Clients Name: $fname . $lname \n . Email Address: $email\n . Comments: $comments\n ; mail($to, $subject, $msg, 'From:' .$from); ? __ Information from ESET Smart Security, version of virus signature database 5228 (20100625) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Your script can't find the attachment.zip file. As you're using a relative path to it, it should be in the same directory as your php script, or somewhere directly in the path environment variable. Also, make sure that the file has read properties set to allow Apache to read it. Thanks, Ash http://www.ashleysheridan.co.uk Consider using something like phpmailer to handle the emails. Makes attaching things really simple. http://phpmailer.worxware.com/ -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Returning a Recordset from a Funtion
The only reasons are I'm a PHP newbie ;-) I'm not really familiar with all the ways to hit a MS SQL server, this particular way always worked for me. It's not difficult to code, and has been working for years, so I've grown accustom to it. There are only a few instances left to connect to MS MSQL for me, so it's not used too often - we're now developing with mySQL. Thanks for the info. -Original Message- From: Andrew Ballard [mailto:aball...@gmail.com] Sent: Friday, June 25, 2010 10:38 AM To: David Stoltz Cc: php-general@lists.php.net Subject: Re: [PHP] Returning a Recordset from a Funtion On Fri, Jun 25, 2010 at 9:55 AM, David Stoltz dsto...@shh.org wrote: Hi Folks, Upon occasion, I have the need to hit our MS MSL database from our PHP/mySQL server. So I've created a function, but I'm not sure if you can return a recordset from a function. My code is below... In the calling page I code: ?php include('../includes/mssql.php'); hitMSSQL(server,database,username,password,SELECT * FROM TABLE1); echo $rs-Fields(1); ? The mssql.php include file is: ?php function hitMSSQL($server,$db,$login,$pass,$query){ $conn = new COM (ADODB.Connection) or die(Cannot start ADO); $connStr = PROVIDER=SQLOLEDB;SERVER=.$server.,1433;UID=.$login.;PWD=.$pass.; DATABASE=.$db; $conn-open($connStr); $rs = $conn-execute($query); return $rs; } ? If I have the echo statement in the function, it works. And of course I can return a single value like: Return $rs-Fields(value); But I can't return the whole recordset... Does anyone have any good ideas so I can access the recordset in the calling page? Thanks! Is there a reason you need to work with COM/ADODB to get the information from SQL Server as opposed to one of the PHP libraries? If your are using COM you must be running under Windows which means you should be able to use Microsoft's SQL Server Driver for PHP, which is the best tool I've seen to date for the task. There are also the older mssql and the newer PDO_MSSQL libraries, or even odbc or PDO_ODBC that will work OK in many cases as well. Any of these are much simpler to work with than COM variants in PHP. Andrew
Re: [PHP] Unexpected behaviour from define()
Thank you very much! Once I realized the source of the problem, I was dismayed that one could declare a constant and have the interpreter absolutely ignore it without warning. I already had error_reporting to E_ALL in php.ini, so was unaware of what else I could do. Didn't think to look for 'display_errors = 1' in php.ini since I was seeing error messages for other errors. Thanks again. Jim On Fri, Jun 25, 2010 at 10:38:39AM +0100, Richard Quadling wrote: On 24 June 2010 22:41, James Long p...@umpquanet.com wrote: ?php error_reporting(-1); ini_set('display_errors', 1); define( 'LOG_NORMAL', 0 ); define( 'LOG_WARNING', 1 ); define( 'LOG_ERROR', 2 ); echo 'LOG_NORMAL ' . LOG_NORMAL . \n; echo 'LOG_WARNING ' . LOG_WARNING . \n; echo 'LOG_ERROR ' . LOG_ERROR . \n; ? outputs ... Notice: Constant LOG_WARNING already defined in - on line 4 LOG_NORMAL 0 LOG_WARNING 5 LOG_ERROR 2 I'm on Win32 PHP 5.3.3-RC1 (cli) (built: Jun 17 2010 22:43:29) -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using fopen or SQL to check image
Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl
RE: [PHP] in_array - what the...
-Original Message- From: Gary . [mailto:php-gene...@garydjones.name] Sent: Friday, June 25, 2010 1:14 AM To: PHP Subject: Re: [PHP] in_array - what the... Ford, Mike writes: -Original Message- If I have an array that looks like array(1) { [mac_address]= string(2) td } and I call if (in_array($name, self::$aboveArray)) with $name as string(11) mac_address what should be the result? FALSE -- in_array checks the *values*, not the keys, so would be looking at the td for this element. Agh! So it does. You know what's worse? I even looked at the documentation of the function this morning wondering if that's what the problem was and *still* didn't see it! *slinks away in embarrassment* Why do this in_array() business?? Just do this... if (self::$aboveArray[$name]) { //something interesting here } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using fopen or SQL to check image
On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] in_array - what the...
From: Daevid Vincent Why do this in_array() business?? Just do this... if (self::$aboveArray[$name]) { //something interesting here } Does that gibberish actually do something? It doesn't make any sense to me, while in_array() actually looks like what it does. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Website content question CMS
Need a some help from the group. I'm adding some wordpress template programs to my site. I added a contact page contact.php to wordpress on my site. http://digitalbiz4u.com/wordpress/ When I click the contact button on the home page I get an 404 error. http://digitalbiz4u.com/wordpress/contact.php . The actionscript in the Flash is: on (release) { getURL(contact.php); } If someone could help point to what needs to be done here it would be appreciated. Thanks, .../Ernie ...man will occasionally stumble over the truth, but usually manages to pick himself up, walk over or around it, and carry on. Winston S. Churchill
Re: [PHP] Website content question CMS
On Fri, 2010-06-25 at 14:00 -0400, Ernie Kemp wrote: Need a some help from the group. I’m adding some wordpress template programs to my site. I added a contact page “contact.php” to wordpress on my site. http://digitalbiz4u.com/wordpress/ When I click the “contact” button on the home page I get an 404 error. http://digitalbiz4u.com/wordpress/contact.php . The actionscript in the Flash is: on (release) { getURL(contact.php); } If someone could help point to what needs to be done here it would be appreciated. Thanks, .../Ernie ...man will occasionally stumble over the truth, but usually manages to pick himself up, walk over or around it, and carry on. Winston S. Churchill It's because there is no contact.php file where the Wordpress install expects it to be. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] in_array - what the...
On 25 June 2010 19:58, Bob McConnell r...@cbord.com wrote: From: Daevid Vincent Why do this in_array() business?? Just do this... if (self::$aboveArray[$name]) { //something interesting here } Does that gibberish actually do something? It doesn't make any sense to me, while in_array() actually looks like what it does. Gibberish?? Probably a good time to go look up some php tutorials. Apart from that, it's rather bad form as a missing index will create a notice at the least. The isset snippet is better, though if you care about finding null values you need to go the route of array_keys(). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using fopen or SQL to check image
On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk Might be quicker to do with a .htaccess file - you can avoid loading php at all. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using fopen or SQL to check image
On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote: On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk Might be quicker to do with a .htaccess file - you can avoid loading php at all. Regards Peter PHP can do things that .htaccess can't, like verify a specific ID has access to an image, etc. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Using fopen or SQL to check image
On 25 June 2010 20:59, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote: On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk Might be quicker to do with a .htaccess file - you can avoid loading php at all. Regards Peter PHP can do things that .htaccess can't, like verify a specific ID has access to an image, etc. I must've missed the part in the code where the ID was checked ... Nope, still can't find it. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using fopen or SQL to check image
On Fri, 2010-06-25 at 21:01 +0200, Peter Lind wrote: On 25 June 2010 20:59, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote: On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk Might be quicker to do with a .htaccess file - you can avoid loading php at all. Regards Peter PHP can do things that .htaccess can't, like verify a specific ID has access to an image, etc. I must've missed the part in the code where the ID was checked ... Nope, still can't find it. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype It wasn't in the example, but generally I've found the only reason someone ever thinks of doing something like this rather than directly link to the image is for some sort of validation reason. I assumed it was a slimmed-down code sample that only showed us what we needed. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] in_array - what the...
From: Peter Lind On 25 June 2010 19:58, Bob McConnell r...@cbord.com wrote: From: Daevid Vincent Why do this in_array() business?? Just do this... if (self::$aboveArray[$name]) { //something interesting here } Does that gibberish actually do something? It doesn't make any sense to me, while in_array() actually looks like what it does. Gibberish?? Probably a good time to go look up some php tutorials. No thanks. I tried to figure out that double colon nonsense over a decade ago as part of an OOP development team. I still don't understand most of the code written during those two years, even though I still maintain parts of it. All I see is a lot of unnecessary overhead with no significant return on the investment. I'll stick with the tried and true procedural notation, at least until I retire next year. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using fopen or SQL to check image
On 25 June 2010 21:02, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 21:01 +0200, Peter Lind wrote: On 25 June 2010 20:59, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote: On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote: Hi, I'm making a Facebook application that can generate images to user's albums. To publish a story a thumbnail of this image is stored on my server. Since this server currently is very limited I want to be able to clean these thumbnails pretty often. To not get broken links in older facebook stories the address to the thumbnail is a php script that checks if the thumbnail is available and returns it, or otherwise returns a default thumbnail. I have solved this using the following code: $tImage = $_GET['i']; $tURL = upload/$tImage.jpg; if(!($fp=fopen($tURL,rb))){ header(Location: thumb.jpg); }else{ header(Location: upload/$tImage.jpg); fclose($fp); } My question is if it would be better to have a mysql database with information about the thumbnail and check if the image is there, instead of checking if the image file can be loaded? What is the most optimized approach if I start to gain traffic? Thanks, /Karl I think checking for the existence of a file is probably going to be the quicker approach. Unless you have a server with loads of RAM and your DB is very small, it's unlikely your DB will exist entirely in memory, so you will at some point have to access the files that the DB uses, even though this is done by the server automatically. On another note, I would try to sanitise that $_GET variable a bit, as it could lead to issues down the line later. Maybe limit the string to patterns you expect for an image URL. Thanks, Ash http://www.ashleysheridan.co.uk Might be quicker to do with a .htaccess file - you can avoid loading php at all. Regards Peter PHP can do things that .htaccess can't, like verify a specific ID has access to an image, etc. I must've missed the part in the code where the ID was checked ... Nope, still can't find it. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype It wasn't in the example, but generally I've found the only reason someone ever thinks of doing something like this rather than directly link to the image is for some sort of validation reason. I assumed it was a slimmed-down code sample that only showed us what we needed. Ahh, I see. I assumed the OP would have told us if that was the case - I prefer answering the stated questions instead of guessing at what they are. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Website content question CMS
That may be part of my problem. I could put the contact.php program in the http://digitalbiz4u.com/wordpress/ directory and the program will find it but the CMS Edit this entry part gives me the error Fatal error: Call to undefined function have_posts() in /home/ekemp/public_html/wordpress/contact.php on line 100 Any other thoughts on where to direct the on (release) { getURL(contact.php); } Reading the docs but haven't found what I should use for the url. Thanks, .../Ernie -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: June-25-10 2:03 PM To: Ernie Kemp Cc: 'PHP General List' Subject: Re: [PHP] Website content question CMS On Fri, 2010-06-25 at 14:00 -0400, Ernie Kemp wrote: Need a some help from the group. I’m adding some wordpress template programs to my site. I added a contact page “contact.php” to wordpress on my site. http://digitalbiz4u.com/wordpress/ When I click the “contact” button on the home page I get an 404 error. http://digitalbiz4u.com/wordpress/contact.php . The actionscript in the Flash is: on (release) { getURL(contact.php); } If someone could help point to what needs to be done here it would be appreciated. Thanks, .../Ernie ...man will occasionally stumble over the truth, but usually manages to pick himself up, walk over or around it, and carry on. Winston S. Churchill It's because there is no contact.php file where the Wordpress install expects it to be. Thanks, Ash http://www.ashleysheridan.co.uk No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.830 / Virus Database: 271.1.1/2962 - Release Date: 06/25/10 02:35:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Website content question CMS
On Fri, Jun 25, 2010 at 15:38, Ernie Kemp ernie.k...@sympatico.ca wrote: That may be part of my problem. I could put the contact.php program in the http://digitalbiz4u.com/wordpress/ directory and the program will find it but the CMS Edit this entry part gives me the error Fatal error: Call to undefined function have_posts() in /home/ekemp/public_html/wordpress/contact.php on line 100 Ernie, with all due respect, you need to understand that, though WordPress is written in PHP, we're not here to support that. Instead, please check the official WordPress support options - all free, no worries - at http://wordpress.org/support/. If it becomes a PHP-specific question, then this would be the place to ask. -- /Daniel P. Brown UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Website content question CMS
-Original Message- From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel Brown Sent: June-25-10 4:05 PM To: Ernie Kemp Cc: a...@ashleysheridan.co.uk; PHP General List Subject: Re: [PHP] Website content question CMS On Fri, Jun 25, 2010 at 15:38, Ernie Kemp ernie.k...@sympatico.ca wrote: That may be part of my problem. I could put the contact.php program in the http://digitalbiz4u.com/wordpress/ directory and the program will find it but the CMS Edit this entry part gives me the error Fatal error: Call to undefined function have_posts() in /home/ekemp/public_html/wordpress/contact.php on line 100 Ernie, with all due respect, you need to understand that, though WordPress is written in PHP, we're not here to support that. Instead, please check the official WordPress support options - all free, no worries - at http://wordpress.org/support/. If it becomes a PHP-specific question, then this would be the place to ask. -- /Daniel P. Brown UNADVERTISED DEDICATED SERVER SPECIALS SAME-DAY SETUP Just ask me what we're offering today! daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ + I understand Daniel. I have tried thehttp://wordpress.org/support/ but I haven't much of a response from them. I know on the PHP list there are others that are using wordpress so put out the call. I'll abide by the list mandate and only make requests for PHP issue. Thanks, .../Ernie -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.830 / Virus Database: 271.1.1/2962 - Release Date: 06/25/10 02:35:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php