php-general Digest 10 Jan 2012 03:16:18 -0000 Issue 7642
Topics (messages 316223 through 316237):
Re: ip2long and ipv6
316223 by: TR Shaw
Re: Variable Troubleshooting Code
316224 by: Marc Guay
316225 by: Ashley Sheridan
316226 by: Ashley Sheridan
316236 by: Paul M Foster
316237 by: Donovan Brooke
php sendmail_from
316227 by: alexus
316230 by: Fatih P
316231 by: Jim Giner
316232 by: alexus
316233 by: alexus
316234 by: Jim Giner
316235 by: Matijn Woudt
Re: Strange foreach reference issue
316228 by: David Harkness
316229 by: Tim Behrendsen
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
----------------------------------------------------------------------
--- Begin Message ---
On Jan 9, 2012, at 4:44 AM, Arno Kuhl wrote:
> My dev and test tools are windows based and the apps deployed on linux, and
> it's been working well. But moving to win7 created problems because it uses
> ipv6 and code for ratings is for ipv4. Specifically, using ip2long to save
> the ip as an int (to prevent duplicate votes) doesn't work in test
> (win7/php5.3). I've got a quick-n-dirty workaround ("::1" converted to "0")
> but it seemed a good opportunity to add code to handle ipv6 properly when
> it's deployed.
>
> I found a reference to do that in the help
> (http://php.net/manual/en/function.ip2long.php), but the referenced site no
> longer exists. I also found a page where Daniel Brown mentions that user
> notes referencing external sites are normally removed
> (http://www.lmpx.com/nav/article.php/news.php.net/php.notes/177158/read/inde
> x.html) but that the note added enough value to make an exception. I'd be
> very grateful if anyone could please point me to any other record of this
> code, or could post it if they have a copy.
>
> Also, I'm assuming the code returns 2 ints because of the size of ipv6, and
> it's fine to change my code to store that, but I'd like to know if there's a
> standard way to store ip addresses in sql for quick lookup?
>
> Cheers
> Arno
Arno
I use
http://us.php.net/manual/en/function.inet-pton.php
and
http://us.php.net/manual/en/function.inet-ntop.php
Tom
--- End Message ---
--- Begin Message ---
> some pretty natives php functions exists to do the job :
But how many times in my life will I have write echo "<pre>"; ???
Does anyone have a handy solution? (Make this the default behavior?
Add a "even more human-readable" flag to the function? Create a
simple macro in Aptana 3?)
Argz,
Marc
--- End Message ---
--- Begin Message ---
Marc Guay <marc.g...@gmail.com> wrote:
>> some pretty natives php functions exists to do the job :
>
>But how many times in my life will I have write echo "<pre>"; ???
>Does anyone have a handy solution? (Make this the default behavior?
>Add a "even more human-readable" flag to the function? Create a
>simple macro in Aptana 3?)
>
>Argz,
>Marc
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
I prefer car_dump with the xdebug module installed, the output is nicely
formatted, which might be what you're looking for?
Thanks,
Ash
http://ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
>
>
>Marc Guay <marc.g...@gmail.com> wrote:
>
>>> some pretty natives php functions exists to do the job :
>>
>>But how many times in my life will I have write echo "<pre>"; ???
>>Does anyone have a handy solution? (Make this the default behavior?
>>Add a "even more human-readable" flag to the function? Create a
>>simple macro in Aptana 3?)
>>
>>Argz,
>>Marc
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>I prefer car_dump with the xdebug module installed, the output is
>nicely formatted, which might be what you're looking for?
>
>Thanks,
>Ash
>http://ashleysheridan.co.uk
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
That should have been var_dump(), stupid phone auto correct!
Thanks,
Ash
http://ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Mon, Jan 09, 2012 at 10:42:59AM -0500, Marc Guay wrote:
> > some pretty natives php functions exists to do the job :
>
> But how many times in my life will I have write echo "<pre>"; ???
> Does anyone have a handy solution? (Make this the default behavior?
> Add a "even more human-readable" flag to the function? Create a
> simple macro in Aptana 3?)
I have an init file that I include in every site that contains a few
routines I use over and over. One such is:
function instrument($legend, $var)
{
print $legend . "<br/>\n";;
print "<pre><br/>\n";
print_r($var);
print "</pre><br/>\n";
}
I use this routine wherever I want to see what's going on. It formats
(particularly) array output so that I can read it, instead of having
everything look like JSON, which is much harder to read.
Feel free to use the above yourself as needed.
Paul
--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com
--- End Message ---
--- Begin Message ---
Just to share, a Mr. Harkness forwarded me a consolidated version of my
code.. basically substituting the innards for:
if (!isset($pmatch) || substr($key,0,strlen($pmatch)) == $pmatch) {
print "$key = $value<br />";
}
Cheers,
Donovan
--
D Brooke
--- End Message ---
--- Begin Message ---
I need to change sendmail from field, I added following to my .htaccess:
php_value sendmail_from 'x...@xxx.xxx'
and tried to send out an email, but it still comes from apache@FQDN
through phpinfo(); I see as local value my email address x...@xxx.xxx
--
http://alexus.org/
--- End Message ---
--- Begin Message ---
On Mon, 2012-01-09 at 13:53 -0500, alexus wrote:
> I need to change sendmail from field, I added following to my .htaccess:
>
> php_value sendmail_from 'x...@xxx.xxx'
>
> and tried to send out an email, but it still comes from apache@FQDN
>
> through phpinfo(); I see as local value my email address x...@xxx.xxx
>
> --
> http://alexus.org/
>
try this before sending mail:
$sender = 'some...@somewhere.com';
if (ini_get("sendmail_from") == null || ini_get("sendmail_from") == "")
{
ini_set("sendmail_from", $sender);
}
it is working fine for me
--- End Message ---
--- Begin Message ---
And how are you generating the email?
--- End Message ---
--- Begin Message ---
do you know if Drupal uses that too?
On Mon, Jan 9, 2012 at 10:16 PM, Fatih P <fatihpirist...@gmail.com> wrote:
> On Mon, 2012-01-09 at 13:53 -0500, alexus wrote:
>> I need to change sendmail from field, I added following to my .htaccess:
>>
>> php_value sendmail_from 'x...@xxx.xxx'
>>
>> and tried to send out an email, but it still comes from apache@FQDN
>>
>> through phpinfo(); I see as local value my email address x...@xxx.xxx
>>
>> --
>> http://alexus.org/
>>
>
>
>
> try this before sending mail:
>
> $sender = 'some...@somewhere.com';
>
> if (ini_get("sendmail_from") == null || ini_get("sendmail_from") == "")
> {
> ini_set("sendmail_from", $sender);
> }
>
> it is working fine for me
>
--
http://alexus.org/
--- End Message ---
--- Begin Message ---
using Drupal
On Mon, Jan 9, 2012 at 2:48 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> And how are you generating the email?
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
http://alexus.org/
--- End Message ---
--- Begin Message ---
I guess I'm asking to see your code pertaining to sending the email.
Telling us about a couple of ini settings doesn't really present us a
picture of your problem.
--- End Message ---
--- Begin Message ---
On Mon, Jan 9, 2012 at 8:50 PM, alexus <ale...@gmail.com> wrote:
> using Drupal
>
If you're using Drupal to send the mail, or any module installed in
Drupal, than there are most likely settings in Drupal (module) that
allow you to set the from address. If these functions call the mail
command with a different From address, than that address will be used,
and not the one in php.ini, .htaccess or set with ini_set.
Matijn
--- End Message ---
--- Begin Message ---
On Sat, Jan 7, 2012 at 5:01 PM, Tim Behrendsen <t...@behrendsen.com> wrote:
> The first loop is leaving a reference to the final element. But then the
> second foreach is doing a straight assignment to the $row variable, but
> $row is a reference to the final element. So the foreach is assigning its
> iterated value to the final element of the array, instead of a normal
> variable.
>
Exactly, and the fact that it shows "1, 2, 2" in the second loop adds more
confusion, but it makes sense. In the second loop, it assigns the indexed
row value into the third row and displays it. Thus it displays row 1, row
2, and then ... row 3, but row 3 is the one that keeps getting overwritten.
And in the third iteration, it overwrites the third row with the third row
which currently holds what was in row 2.
The moral is always unset the iterator variable when doing foreach with a
> reference, like the manual says. :)
>
While you can certainly follow the above advice, in my view it's dangerous
to have these two loops a) reuse the same variable name for a different
purpose and b) exist in the same scope. More and more I find myself
dropping the subtle tricks I've learned over the years in favor of writing
code that is as easy to understand as possible. Code gets read and modified
a lot more than it gets written, and all those tricks just trip up more
junior teammates--and often even myself. :)
David
--- End Message ---
--- Begin Message ---
On 1/9/2012 10:35 AM, David Harkness wrote:
On Sat, Jan 7, 2012 at 5:01 PM, Tim Behrendsen <t...@behrendsen.com
<mailto:t...@behrendsen.com>> wrote:
The first loop is leaving a reference to the final element. But
then the second foreach is doing a straight assignment to the $row
variable, but $row is a reference to the final element. So the
foreach is assigning its iterated value to the final element of
the array, instead of a normal variable.
Exactly, and the fact that it shows "1, 2, 2" in the second loop adds
more confusion, but it makes sense. In the second loop, it assigns the
indexed row value into the third row and displays it. Thus it displays
row 1, row 2, and then ... row 3, but row 3 is the one that keeps
getting overwritten. And in the third iteration, it overwrites the
third row with the third row which currently holds what was in row 2.
The moral is always unset the iterator variable when doing foreach
with a reference, like the manual says. :)
While you can certainly follow the above advice, in my view it's
dangerous to have these two loops a) reuse the same variable name for
a different purpose and b) exist in the same scope. More and more I
find myself dropping the subtle tricks I've learned over the years in
favor of writing code that is as easy to understand as possible. Code
gets read and modified a lot more than it gets written, and all those
tricks just trip up more junior teammates--and often even myself. :)
David
Agreed, in fact, I decided to create a new style naming convention where
"_ref" is always suffixed to variable names that are references, along
with doing the unset, just in case. This goes to show that references
can be a recipe for subtle bugs to creep in, so best to isolate them as
much as possible to their own convention. If the convention is followed,
it should eliminate the possibility of this bug, even if the unset is
left out.
Tim
--- End Message ---