php-general Digest 17 Jan 2007 10:11:32 -0000 Issue 4574

Topics (messages 247187 through 247200):

Re: sms through teleflip and php?
        247187 by: Jochem Maas

Re: More efficient thumbnail script
        247188 by: Jochem Maas
        247189 by: Curt Zirzow
        247190 by: Jochem Maas

Re: I lied, another question / problem
        247191 by: Jochem Maas
        247192 by: Chris
        247194 by: Beauford
        247199 by: Roman Neuhauser

Re: odbc_execute
        247193 by: Chris

Re: Bug? (_ENV in PHP v5.2.0)
        247195 by: Eli

Re: $_SESSION variable gets lost on FORM action
        247196 by: Stut

Where can I get the Printer extension?
        247197 by: Chuck Anderson

Storing values in arrays
        247198 by: Ryan A
        247200 by: Robert Cummings

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


----------------------------------------------------------------------
--- Begin Message ---
blackwater dev wrote:
> Thanks for all the insights.  It appears that it might have thought my
> email
> was spam as I sent it from another server and it worked fine.

which makes it even more likely that the 'bad' server doesn't have it's
relevant MX DNS records setup properly - I can't really tell you what properly
entails - it's a responsiblity I hand off to the relevant sys admin :-)

> 
> Thanks!
> 
> On 1/16/07, Jochem Maas <[EMAIL PROTECTED]> wrote:
>>
>> also consider that there maybe a reverse lookup being done on the sending
>> MTA
>> that the sms gateway doesn't consider kosher .. and/or that the IP of the
>> sending MTA is grey-listed/black-listed.
>>
>> also a check may be being done to see if the sender's account exists
>> on the sender's [your servers] domain.
>>
>> check the relevant logs on your server to see what (if anything)
>> the sms gateway is asking your server. (no idea what/where those logs
>> are hiding out).
>>
>> sorry if this all sounds vague, I'm mostly parroting what others have
>> said
>> in the past - I'm hardly what you would call knowledgable with regard to
>> mail servers
>> and all that jazz.
>>
>> [EMAIL PROTECTED] wrote:
>> > Maybe phpMailer isn't sending the correct headers either.  Sometimes
>> all
>> it takes is one missing header that a system is looking for and it may
>> filter it as spam or something.
>> >
>> > Again, I encourage you to examine the headers from your Thunderbird
>> "good" email and compare it to your PHP and/or phpMailer headers that are
>> getting sent.  Possibly try to emulate the successful email as much as
>> possible by copying the headers from a known successful message.
>> >
>> > If that doesn't work, then you may contact teleflip or whatever service
>> you're trying to send text messages to and ask them if they can
>> provide any
>> information as to why it may not be going through.  Never know, might
>> find
>> someone with half a brain who can help.
>> >
>> > -TG
>> >
>> > = = = Original message = = =
>> >
>> > I tried using phpMailer and all and it nothing seems to work right.  I
>> can
>> > send it fine through thunderbird but it just seems to complain via
>> php.  Not
>> > sure why.
>> >
>> > On 1/16/07, [EMAIL PROTECTED]
>> <[EMAIL PROTECTED]
>> >
>> > wrote:
>> >> I'm guessing the SMS system is rejecting the email because it's
>> lacking
>> >> some headers that mail programs tend to use... and spammers sometimes
>> >> forget.
>> >>
>> >> You might send your email from Thunderbird.. CC yourself on it. 
>> Verify
>> >> that it went through as a text message, then open the CC'd copy and
>> look at
>> >> the headers.  You can start by taking all those headers and putting
>> them
>> >> into your PHP script then slowly commenting some out until you get
>> just
>> what
>> >> you need and not a lot of extra garbage (to keep it simple and
>> >> semi-elegant).
>> >>
>> >> That's where I'd start at least.
>> >>
>> >> -TG
>> >>
>> >> = = = Original message = = =
>> >>
>> >> Has anyone been able to successfully send a text message using php and
>> the
>> >> mail function?
>> >>
>> >> It works fine if I open up thunderbird and send a message to
>> >> [EMAIL PROTECTED] but if I use the mail function:
>> >>
>> >> mail("[EMAIL PROTECTED]", "test", "test");
>> >>
>> >> It doesn't work.  I've tried several different approaches so was
>> curious
>> >> if
>> >> others have used it successfully.
>> >>
>> >> Thanks!
>> >
>> >
>> > ___________________________________________________________
>> > Sent by ePrompter, the premier email notification software.
>> > Free download at http://www.ePrompter.com.
>> >
>>
>>
> 

--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
> 
> On Jan 16, 2007, at 4:10 PM, Jochem Maas wrote:
> 
>> generating/resampling image data is a relatively heavy job for a script
>> to perform. there maybe optimizations available in the script itself but
>> generally caching the results the generation/resampling action is the
>> way to
>> increase performance ... you need a mechanism to check/store/retrieve
>> cached
>> images [and a way to automatically regenerate a cached image when the
>> source
>> image has changes].
>>
>> another thing to consider on top of caching is to store the cached
>> data on a
>> 'ram' drive ... on linux I often use a sub directory on /dev/shm
>> (which is
>> a part of the filesystem which actually exists only in shared memory -
>> more than
>> likely that you dont have access to this on a shared hosting environment.
> 
> Luckily I'm not in a shared hosting environment. :) I sit about 3 feet
> away from the server that is running my script. I will look into caching
> the info though to see if I can figure out what I would have to
> change/add/delete to accomplish this.

I wouldn't bother with worrying about stored cached image output on
/dev/shm until you have got caching working - although disk access is relatively
slow it's not half as slow as regenerating a thumbnail on every request.

here is a class that might help you when it comes to caching images,
assuming you can work out how it works ;-)

(I'm sure this class is not perfect but it works for me :-)

<?php

class ImageCache
{
    var $validTypes = array('png','gif','jpeg');

    var $cacheFileName;
    var $cacheFileType;
    var $cacheDir;

    var $im;

    /* you must give a valid 'cache' dir  */
    function ImageCache($cDir)
    {
        $this->cacheDir         = $cDir;
    }

    /* generate a cache file name for the image your are generating
     * if your generated output image is dependent on the values of one or more 
request
     * variables then you should add the names to the $args array e.g.
     *
     * your script take width/height parameter: /image.php?width=200&height=160
     *
     * $args should be the following array: array('width', 'height');
     */
    function genCacheFileName($args = array(), $type = '', $prefix = '')
    {
        /* name/val pair delimiter in the string that results in the hash for 
the cache id */
        $qHashMark = '%~^*';

        $qry  = array();
        $args = (array)$args; natsort($args);
        foreach ($args as $arg) {
            if (($val = $this->getR( $arg, false )) !== false) {
                $qry[] = "{$arg}=".str_replace($qHashMark,'',$val);
            }
        }

        $sep  = '-:-';
        $hash = md5($_SERVER['HTTP_HOST'] .$sep. $_SERVER['SCRIPT_NAME'] .$sep. 
join($qHashMark,$qry));

        if (!in_array($type, $this->validTypes)) {
            if ($type == 'jpg') {
                $type = 'jpeg';
            } else {
                $type = 'png';
            }
        }

        $this->cacheFileType = $type;

        if (!$prefix) {
            $prefix = 'cacheimg';
        }

        return ($this->cacheFileName = "{$prefix}_{$hash}.{$type}");
    }

    /* get the fullpath to the location where the cache file is saved/stored */
    function getCacheFilePath()
    {
        return $this->cacheDir . '/' . $this->cacheFileName;
    }

    /* Return true if the cache file is younger than the source file(s),
     * false otherwise.
     *
     * if this func returns true you can output the relevant cache file,
     * if false is returned it's your responsibility to generate the output file
     * and save it to the location given by $this->getCacheFilePath()
     *
     * the (array of) files passed to this function should be complete paths,
     * not just filesnames.
     */
    function checkCache( $files = array() )
    {
        $cacheState = true;

        $cf           = $this->getCacheFilePath();
        $mTime        = is_readable($cf) ? filemtime($cf): 0;
        $lastModified = gmdate("D, d M Y H:i:s ", $mTime)."GMT";
        $files        = (array) $files;

        if (!count($files) || !$mTime) {
            $cacheState = false;
        } else {
            foreach($files as $file) {
                if ($mTime < filemtime( $file )) {
                    $cacheState = false;
                    break;
                }
            }
        }

        if ($cacheState) {
            $headers = getallheaders();
            if (isset($headers['If-Modified-Since']) && 
($headers['If-Modified-Since'] == $lastModified)) {
                /* The UA has the exact same image we have. */
                header("HTTP/1.1 304 Not Modified");
                exit;
            } else {
                unset($headers);
                header("Last-Modified: ".$lastModified);
                return true;
            }
        } else {
            // not cached - or cache invalidated
            // must cache the (new) data.
            return false;
        }
    }

    function showImage($type = '', $quality = 100)
    {
        header( "Content-type: image/{$this->cacheFileType}" );
        readfile( $this->getCacheFilePath() );
        exit;
    }

    function getR($v = '', $r = null, $t = null)
    {
        if (!empty($v)) { if (isset($_REQUEST[$v])) 
{$r=!is_null($t)?$t:$_REQUEST[$v];} }
        return $r;
    }
}

?>

> 
> Would upgrading to PHP 5* be of any help? 

not specifically in this case, but I would recommended using php5
if your starting out and developing new stuff.

php4 is not being actively developed (security & bug fixes still occur).

it's not wrong to use php4, and many people have no choice, but I recommend
trying to stay on top of whats current and given that your not (AFAICT) running
any legacy code there is nothing really stopping you.

> I've thought about upgrading
> but not knowing much about how to run the server from the command
> line(Part of what I'm learning) I didn't want to screw anything up.
> 
> 

test servers are there to be screwed up, kind of. when your learning and trying 
things
out thing break occasionally. ommelettes, breaking eggs, all that jazz.

--- End Message ---
--- Begin Message ---
On 1/16/07, Jochem Maas <[EMAIL PROTECTED]> wrote:
...
        if ($cacheState) {
            $headers = getallheaders();
            if (isset($headers['If-Modified-Since']) && 
($headers['If-Modified-Since'] == $lastModified)) {

I was waiting for this to be mentioned...

I would use a more detailed approach: http://pastebin.ca/319054

Curt.

--- End Message ---
--- Begin Message ---
Curt Zirzow wrote:
> On 1/16/07, Jochem Maas <[EMAIL PROTECTED]> wrote:
>> ...
>>         if ($cacheState) {
>>             $headers = getallheaders();
>>             if (isset($headers['If-Modified-Since']) &&
>> ($headers['If-Modified-Since'] == $lastModified)) {
> 
> I was waiting for this to be mentioned...
> 
> I would use a more detailed approach: http://pastebin.ca/319054

could you clarify alittle? (beyond not using the apache specific getallheaders()
function - I chose to go that route because I never run on anything other than 
apache)

is the value of $headers['If-Modified-Since'] identical to
$_SERVER['HTTP_IF_MODIFIED_SINCE'] or *can* they differ (i.e. would
it be stupid to assume that apache 'normalized' the modidfied-since string?)

is my code borked or merely not covering a number of edge cases related
to older or more exotic browsers - my code does output 304 headers
at the right time AFAIHT.

but going by your code there could, it seems, be improvement ...
i'd like to understand what exactly the improvement is (would be) about.

tia & rgds,
Jochem


> 
> Curt.

--- End Message ---
--- Begin Message ---
Beauford wrote:
>  
...

>>> function invalidchar($strvalue)
>>> {
>>>     if(!ereg("^[[:alpha:][:space:]\'-.]*$", $strvalue)) {


>> That regexp matches if $strvalue consists of zero or more 
>> ocurrences of a letter, a whitespace character, and any 
>> character whose numeric value lies between the numeric values 
>> of "'" and "." in your locale.
>> Zero or more means it also matches an empty string.
>>
>>

..


> 
> Further to my previous email, there is something weird going on here. I just
> tried using this:
> 
>       if (!ereg('^[A-Za-z0-9]', $strvalue)) {
>                return "error";
>       }

stop using bleeding ereg*() function - move to preg_*() funcs like the rest of
the world did 5+ years ago.

> 
> When I enter the word Test, which is valid, I am still getting an error

'Test' is not valid according to the regexp your using.

<?php

$strs = array("Test", "Jochem", "@##^%", "", "Test1", "Test!", "J*nk");

// match a non-empty string containing *only* alpha numeric chars
foreach ($strs as $s) {
        if (!preg_match("#^[A-Z0-9]+\$#i", $s)) {
                echo "error in string: \"$s\" \n";
        } else {
                echo "no problemo: \"$s\" \n";
        }
}

?>

(ps the above is a crappy regexp for real world use imho, but it serves
the purpose of example)

you need to read up and do lots of practicing with regexps - we do realise that
regexps are not easy, unfortunately there is no shortcut to learning how to use 
them.
I doubt many on this list could be considered expert in the field of regexps, 
but
you have to get yourself a basic grasp or these things will bite you in the ass 
until
the cows come home.

start here:

http://php.net/pcre
http://php.net/manual/en/reference.pcre.pattern.modifiers.php
http://php.net/manual/en/reference.pcre.pattern.syntax.php

> returned - but only on this one page. So there has got to be something on
> this page that is screwing this up, but what. I have been over and over this
> and can't see a problem.
> 
> I could really use another pair of eyes on this as it is driving me nuts. I

regexps drives everyone nuts to start with. first there is only the mountain, 
then the
mountain is not a mountain, finally there is just mountain.

> am now into hour 6 with this. Absolutely ridiculous.

thats nothing. most people take months to get anywhere useful with regexps,
well okay I'm speaking for myself - I was in your position somewhere back in 
2001,
I was regularly sweating it for weeks trying to understand and getting certain 
regexps
work 'properly'.

don't give up.

--- End Message ---
--- Begin Message ---
Beauford wrote:
This is a bad way to test for a value also, unless you expecting only TRUE or FALSE and you are sure that it will always be set.

Otherwise you should do something like this

if ( isset($formerror) && $formerror != '' ) {
    // Display Error
}

The problem here is this. formerror is an array

Then check it as an array.


$formerror = array();

... do your validation here which may/may not add to the array.

if (!empty($formerror)) {
  echo "Something went wrong!";
  print_r($formerror);
} else {
  echo "Everything is ok!";
}

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

--- End Message ---
--- Begin Message ---
 
> $formerror = array();
> 
> ... do your validation here which may/may not add to the array.
> 
> if (!empty($formerror)) {
>    echo "Something went wrong!";
>    print_r($formerror);
> } else {
>    echo "Everything is ok!";
> }

As I said the problem is that a value is being returned, how I check it is
really not an issue as I know there is value there. I guess I need to figure
out how to only return something if there is an error, and not return
anything if there is no error, or just totally revise the way I am doing
this period.

I have corrected the problem, but it is messy and it is cumbersome, but it
will have to do until I can work out something better. At least now I can
take my time and work on this.

I appreciate all the suggestions and maybe I can incorporate some of them
once I do a rewrite.  

--- End Message ---
--- Begin Message ---
# [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100:
> Beauford wrote:
> > Further to my previous email, there is something weird going on here. I just
> > tried using this:
> > 
> >     if (!ereg('^[A-Za-z0-9]', $strvalue)) {
> >              return "error";
> >     }
> 
> stop using bleeding ereg*() function - move to preg_*() funcs like the rest of
> the world did 5+ years ago.

Or even better: how about using the right tool for the job? :)

    if (!ctype_isalnum($strvalue)) {
        return "error";
    }

>       if (!preg_match("#^[A-Z0-9]+\$#i", $s)) {

> (ps the above is a crappy regexp for real world use imho, but it serves
> the purpose of example)
 
It's dangerous.

-- 
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

--- End Message ---
--- Begin Message ---
ANZOLA Silvio wrote:
Hi; I'm e newbie in PHP. I have to reda data from an AS400 system; I use
an ODBC connection and I have to read data from a table with
This the SQL Statement "

$query_stm = "SELECT * " .
        "FROM cordo.plavt " .
         "where atcdim = ? " .
         "and atdtvf = 9999999";

This is the prepare statement :

$result = odbc_prepare ($dbconn, $query_stm);

This is the execute statement

$exc = odbc_execute ($result, array($Targa));

I test the execution of the odbc_execute and I have TRUE, so all works
fine;

But now how can retrieve the data from the result set? ; It seems thet
all the fetch function work with the odbc_exec statement;

See comment here: http://www.php.net/manual/en/function.odbc-prepare.php#71616

You need to pass the $result from the prepare statement to the _fetch_* functions.

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

--- End Message ---
--- Begin Message ---
Frank M. Kromann wrote:
Hi Eli,

Check variable_order in php.ini
(http://us2.php.net/manual/en/ini.core.php#ini.variables-order) if the E is
missing you will not get any environment variables.

- Frank


Thanks, Frank.. That worked! :-)

-thanks, Eli

--- End Message ---
--- Begin Message ---
Nuno Oliveira wrote:
Sometimes in my code I use the Header('Location: index.php?var=value'); and I've found out (I think) that when one of these headers are executed by PHP, the rest of the script gets executed.

I'm thinking that this is the problem because I've eliminated all the occurrences where the SESSION var was cleared until only one exists and it was after a Location Header.

I've put an exit(); after the header and the problem was gone... :)

Is this the correct PHP/HTML behavior or is there another problem? Am I supposed to put an exit(); after a header "Location" to make sure that no more code gets executed?

Redirecting using a Location header is not the only thing you can do with the header() function. It will never end processing of the script no matter what you pass to it. The example on the manual page for the header() function says as much (http://php.net/header), you read that right?

<?php
header("Location: http://www.example.com/";); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

-Stut

--- End Message ---
--- Begin Message --- It thought it would be bundled with my Windows version pf Php 4.4.1, but it is not.

I've searched for it and can't find it at php.net.

How do get a copy of php_printer.dll for Php4.4.1 for Windows?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************

--- End Message ---
--- Begin Message ---
Hi,

I think its easier to explain what I want to do.. so here goes:
I want to store values in arrays for one minute and then write them to file.

For example, everytime someone logs in I want their username to be in an 
array....
1 or 100 or X people may login in 60 seconds...but it should only write all the 
usernames that logged in to disk every 1 minute.

Ideas? suggestions? starting points or a link to a specific spot in the manual 
with a RTFM would be appreciated :)

Thanks in advance,
Ryan


------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
 
---------------------------------
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.

--- End Message ---
--- Begin Message ---
On Wed, 2007-01-17 at 00:35 -0800, Ryan A wrote:
> Hi,
> 
> I think its easier to explain what I want to do.. so here goes:
> I want to store values in arrays for one minute and then write them to file.
> 
> For example, everytime someone logs in I want their username to be in an 
> array....
> 1 or 100 or X people may login in 60 seconds...but it should only write all 
> the usernames that logged in to disk every 1 minute.
> 
> Ideas? suggestions? starting points or a link to a specific spot in the 
> manual with a RTFM would be appreciated :)

Might be able to do it with shared memory and a cron job. I'm just not
sure if shared memory works between web module and cli. If not, I guess
you could use wget in the cron job to pull a special page from your
website that does the write.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---

Reply via email to