[PHP] ip2long and ipv6

2012-01-09 Thread Arno Kuhl
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



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



Re: [PHP] ip2long and ipv6

2012-01-09 Thread TR Shaw

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


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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Marc Guay
 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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Ashley Sheridan


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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Ashley Sheridan


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

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



[PHP] php sendmail_from

2012-01-09 Thread alexus
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/

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



Re: [PHP] Strange foreach reference issue

2012-01-09 Thread David Harkness
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


Re: [PHP] Strange foreach reference issue

2012-01-09 Thread Tim Behrendsen

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


Re: [PHP] php sendmail_from

2012-01-09 Thread Fatih P
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


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



[PHP] Re: php sendmail_from

2012-01-09 Thread Jim Giner
And how are you generating the email? 



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



Re: [PHP] php sendmail_from

2012-01-09 Thread alexus
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/

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



Re: [PHP] Re: php sendmail_from

2012-01-09 Thread alexus
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/

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



[PHP] Re: php sendmail_from

2012-01-09 Thread Jim Giner
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. 



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



Re: [PHP] Re: php sendmail_from

2012-01-09 Thread Matijn Woudt
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

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Paul M Foster
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 prebr/\n;
print_r($var);
print /prebr/\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

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Donovan Brooke
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 = $valuebr /;
}


Cheers,
Donovan



--
D Brooke

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