Re: [PHP] PHP vs JAVA

2013-08-20 Thread Andy McKenzie
I'll chime in on this one.

I've been job hunting recently, and I can say that while I've seen a lot of
people asking for Java experience, I'm not sure I've seen a single posting
asking specifically for PHP.  There've been a few looking for Drupal, or
Wordpress, but no You must be able to write PHP code to work here.

I can also say that the more I work with Java-based programs, the more I
want to see Java written into history books as a terrible idea that sadly
persisted until nearly 2014.  As an example:  I need to provide IT support
to people using a tool written in Java.  It turns out that if you install
Java 7, the tool doesn't work at all.  If you install Java 6 with the
newest updates, it works, but occasionally crashes the entire computer.
No, you have to have Java 6 update 22 in order for this software to be
reliable.

There are other tools I've used that failed completely on minor version
switches, and that just plain SHOULDN'T HAPPEN.  Yes, there are going to be
minor changes when a language upgrades, that's why there are upgrades.  But
they're usually minor, in a This didn't work the way it was supposed to,
so we fixed it kind of way.  If you were taking advantage of that bug, you
get knocked down, but the vast majority of software will keep running.
Java doesn't seem to work that way, at least from an IT worker's
perspective.

Andy McKenzie


On Tue, Aug 20, 2013 at 10:00 AM, Tedd Sperling t...@sperling.com wrote:

 Hi guys:

 A teacher at my college made the statement that JAVA for Web Development
 is more popular than PHP.

 Where can I go to prove this right or wrong -- and/or -- what references
 do any of you have to support your answer? (sounds like a teacher, huh?)

 Here are my two references:

 http://w3techs.com/technologies/details/pl-php/all/all

 http://w3techs.com/technologies/history_overview/programming_language/ms/y

 But I do not know how accurate they are.

 What say you?

 Cheers,


 tedd

 ___
 tedd sperling
 t...@sperling.com






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




Re: [PHP] PHP vs JAVA

2013-08-20 Thread Andy McKenzie
On Tue, Aug 20, 2013 at 3:18 PM, Dan Munro d...@danmunro.com wrote:

  1. There are no statement terminators. Lose your indentation for ANY
  reason and your program is well and truly screwed, in ways you can't
  imagine.
 
  2. Python programs fail in the most ungraceful way I've ever seen in an
  interpreted programming language.

 1. Indent properly. In php, if you put an open or close brace out of place
 your code will break in unexpected ways as well. If it's hard to tell if
 something is indented properly, your code should be refactored so that it
 is.

 2. In my experience this has a lot to do with how some people use python
 and not python itself.


I can't argue on point two, since that's where all of my worst failure have
come from.  But as to indenting, I have had the problem of opening a file
on a new OS, only to find that the default editor there has wiped out my
formatting.  With PHP, that's not a big deal:  as long as I put my braces
in the right places, everything will continue to work.  With Python -- or
any whitespace delimited language -- it's fatal, and I have to hope I can
exit without saving anything.

Andy


Re: [PHP] Web dev, DB and proper db design.

2013-07-04 Thread Andy McKenzie
I think it depends on the application.

A lot of small web apps simply don't need any kind of normalization, and it
really does make sense to put everything in one table, or a couple of
unlinked tables.  Therefore, on those apps, there's no need for foreign
keys.  For instance:  I used one in-house application that had two tables:
A list of authorized users with their passwords and a couple of other
things (administrative role, security level, things like that), and a table
that contained information about computers used in the the department.
Sure, some of the users had a computer in the department, but not all of
them.  So there was really no need to link the tables.  And since the
information stored about the computers was stuff like owner, name, MAC, and
IP address, there was no need for foreign keys in that table either:  it
just wouldn't make sense.

Now, anything much more complex then that there's going to be some value in
using foreign keys, whether formally (constraints set in the DB) or
informally (constraints imposed in the web interface), but it's quite
possible the guy had never worked on something where they were needed.

-Andy
.


On Thu, Jul 4, 2013 at 10:20 AM, Lester Caine les...@lsces.co.uk wrote:

 Richard Quadling wrote:

 Is there a difference in those in 'startups' and web only situations, or
 those doing more traditional development (split that as you like - I'm
 just
 trying to get an understanding and not go off on one!).


 Depends if you consider MySQL is any use as a real database :)
 Building the constraints and many other core database features into the
 code was essential before MySQL had many of the features that real
 databases have had from the start ...

 --
 Lester Caine - G8HFL
 -
 Contact - 
 http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk
 Rainbow Digital Media - 
 http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk


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




Re: [PHP] Is there a PHP based authentication library?

2013-04-01 Thread Andy McKenzie
I started building one at my last job, though it was part of a framework I
was developing.  I knew I was going to need to authenticate against both
LDAP and old-fashioned database username/md5-password columns.  (Ah, legacy
user databases.)

If it would be useful, I could dig out what I had and try to make it into a
stand-alone set of functions, but I never got further than those two
options.  Basically there was a script that took in a username and password
from a web form, then looked at a config file to decide which set of the
sub-functions to use.  For a DB, it checked to see if the username and
hashed password matched a row in the database;  for LDAP, it did some
re-encoding to handle the weird encrypt that our OpenLDAP server used, then
ran through the process of checking to see if the user actually had that as
their password.

Like I said, let me know if anyone wants to see it... I'm unemployed right
now, and a project to work on this week (or next... this week is kind of
busy) might be a good thing.

-Andy McKenzie


On Mon, Apr 1, 2013 at 6:49 PM, Mark mark...@gmail.com wrote:

 On Tue, Apr 2, 2013 at 12:27 AM, Sorin Badea sorin.bade...@gmail.com
 wrote:
  Hi Mark,
  I think a simple Google search would be faster. Anyway, an unified way
 for
  3rd party authentication doesn't exist from my knowledge, but for Persona
  you could use the sample from mozilla github account
  https://github.com/mozilla/browserid-cookbook .
 
  Good luck,
  Sorin!
 
 
  On Tue, Apr 2, 2013 at 12:26 AM, Mark mark...@gmail.com wrote:
 
  Hi,
 
  I stumbled upon this payment library: http://ci-merchant.org/ which
  abstracts the different payment backends away and exposes a new easy
  to use interface for the app developer to use. Thus making it very
  easy to use different payment providers.
 
  I was wondering if something like that is also existing for
  authentication? For example, in authentication you have quite a few
  different ones:
  - Mozilla Persona
  - openid
  - facebook connect
  - google (openid?)
  - use/pass based authentication (a.k.a. the self made version that
  every dev begins with)
  - oauth
  - twitter connect
  - etc...
 
  Is there such a library in existence? I'm especially looking for one
  with mozilla persona implemented.
 
  Kind regards,
  Mark
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
  --
  Badea Sorin (unu.sorin)
  sorin.bade...@gmail.com
  unu_so...@yahoo.com
  Pagina personala:
  http://badeasorin.com

 I couldn't find it on google thus i asked in the one place where - if
 it exists - people would probably know. I find it quite surprising
 that a library like this isn't in existence yet. I can imagine tons of
 sites would certainly benefit from having one generic interface to
 use.

 Anyway, thank you for your pointer and reply. If you (or anyone else)
 finds a lib for this, please don't hesitate to post it in here. :)

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




Re: [PHP] PHP fails to install on Ubuntu 12.10. What's going on?

2013-02-14 Thread Andy McKenzie
On Thu, Feb 14, 2013 at 2:52 PM, Daniel Brown danbr...@php.net wrote:
 Remember to hit reply-all, Andy, so it goes to the list as well as
 the previous author.

 On Thu, Feb 14, 2013 at 2:49 PM, Andy McKenzie amckenz...@gmail.com wrote:
 On Thu, Feb 14, 2013 at 2:29 PM, Daniel Brown danbr...@php.net wrote:
 On Thu, Feb 14, 2013 at 2:20 PM, Chris Bergstresser ch...@subtlety.com 
 wrote:
 Hi all --

I've got a cloud server on Rackspace.  If I bring up a fresh Ubuntu
 12.10 machine image, and type apt-get install php5 it seems to
 install fine.  But if I then type php -version I get PHP Parse
 error:  syntax error, unexpected end of file in Command line code on
 line 1.

What went wrong?  How can I fix it?

 I'm pretty sure the php5 package in ubuntu doesn't include the cli
 client.  Try adding apt-get install php5-cli (or whatever they're
 calling the package these days) and see if the version command works
 then.  Also, you may need a second hyphen before the word version.

 Yes, it would be php5-cli, but since he's getting the response
 from PHP (parse error) and not the environment saying the command
 isn't found, it shows he's got the CLI installed.  Ubuntu is actually
 really helpful with a lot of that, too, since - if it can't find the
 command - it'll suggest packages from APT to install which match the
 command given.

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/

Can I just mention, as so many others have, how much I hate the fact
that this list is configured to not reply to the list by default?

Thanks for forwarding this on to the right address, Dan.

-Andy

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



Re: [PHP] Random 404 screens

2013-02-10 Thread Andy McKenzie
On Sat, Feb 9, 2013 at 11:51 AM, Geoff Shang ge...@quitelikely.com wrote:
 On Sat, 9 Feb 2013, Jim Giner wrote:

 Lately, my web pages are giving me some problems.  Once a day or so one or
 more of my pages/scripts will give me a 404 error page saying my web page
 has timed out.  Problem is that the page was just displayed.  I click on a
 link, the page shows up, I click on a button on it to trigger some activity
 and voila!  An error.  I hit refresh and my page is back and things work ok.


 Since someone mentioned network issues, I will ask this question.

 Is it actually a 404 page?  That is to say, does the string 404 actually
 appear in the error document?

 If it does, then this would rule out your home network, as 404 is a response
 code returned by the webserver.

 Geoff.



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


This is a good point, and one I hadn't thought of.  I saw Network
time out and thought network problems, but Geoff is right.  If it's
actually a 404, it's not a network problem between you and the server.

-Andy

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



Re: [PHP] Random 404 screens

2013-02-09 Thread Andy McKenzie
On Sat, Feb 9, 2013 at 10:41 AM, Jim Giner jim.gi...@albanyhandball.com wrote:
 This is a tough one.

 Lately, my web pages are giving me some problems.  Once a day or so one or
 more of my pages/scripts will give me a 404 error page saying my web page
 has timed out.  Problem is that the page was just displayed.  I click on a
 link, the page shows up, I click on a button on it to trigger some activity
 and voila!  An error.  I hit refresh and my page is back and things work ok.

 Some background.  My pages/appls/development does not do much of anything
 other than record/display stuff from my dbs and show off some pics.  Nothing
 fancy other than some js to enhance the viewing of these pages.  No playing
 with anything time-related and very few cookies.  So I don't have a clue as
 to what constitues a web page timeout.

 Can anyone enlighten me as to what I should be looking for here?  Or even if
 it is something I'm the cause of?

 For those who wish to experiment my site is jimginer dot net.  Can't
 guarantee you'll get the error, but you might.

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


Smart money is that it's nothing to do with you;  in my experience,
that's usually a network problem.  It could be on your end (I'm seeing
that a lot more often now that I've moved to a new house, or it could
be a problem with the server's connection.

I just loaded your page half a dozen times in short succession, and it
was fine, so that makes me think it's likely to be at your end...  or
somewhere between you and the server, you never know.

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



Re: [PHP] Re: limiting

2012-10-10 Thread Andy McKenzie
snip
 Have you read a book on php and perhaps one on CSS to help
 with your hiding problem?  (BTW - that last was a hint.)

 I've read plenty of PHP books I own at least 5 and ALL of them I've read
 hardly ever explain anything at all. They just throw some code in there and
 say this is what it does and gives a picture of the finished product. Total
 waste of my money! Also, how am I going to learn PHP if I've got to mix it all
 up with CSS. It's just going to make things harder and more confusing on me. I
 only threw lightbox in there because I knew I didn't have to do or learn
 anything special and to put a smile on my face if it worked. After all, if it
 can't be fun, why do it?
/snip

I rarely post anything to this list, because almost everything asked
is above my level of understanding.  But, speaking as a relative
beginner, I have a few comments here.

1) Books.  I, too, have read a lot of PHP books.  In the end, the ones
I've found most useful were by WROX press.  Their Beginning PHP4 by
Choi, Kent, Lea, Prasad, and Ullman was one of the best intro to
programming type books I've found for the way I learn.  It's now
obsolete, but the core information is still good.  I haven't read
through the Beginning PHP 5.3 version as thoroughly, but it also seems
to be pretty good.  You might also want to check with local community
colleges to see if someone offers a basic course -- PHP, C, C++,
something like that.  The language may be different, but the concepts
remain the same.

2)  They just throw some code in there and say this is what it does
and gives a picture of the finished product. Total waste of my money!
Also, how am I going to learn PHP if I've got to mix it all up with
CSS.

  This one's harder.  These days CSS is part of the web, and you're
stuck with it if you want to do anything complex.  So here's my
advice:  Find something simple to experiment with.  Don't start with a
complex project, start with something that doesn't actually do
anything useful.  When I start trying to understand a function I
haven't used before, I build a new page called something like
foo_test, where foo is the name of the function.  These days it
might be ip2long_test, or something like that, but I still have some
in my test folder with names like echo_test.php where I was trying
to figure out how that function worked.  Start there.  Do something
simple.  Lightbox may be too complex.  Maybe build a fortune cookie
webpage, where every time you click a button it reloads with a new
fortune.  Learn to pull fortunes out of a file and out of a database.
Once you've got the hang of that, start using CSS to change how it
looks.  Once THAT's working right, figure out how to use JavaScript
(you're going to need it sooner or later!) and AJAX to make it reload
the fortune without reloading the whole page.

  Yeah, it's a boring project.  But it's a stepping stone to doing
what you really want to do.  The alternative is to do what I did:
start with a big project, and accept that you're going to rewrite it
dramatically later.  I started with a book inventory system.  First I
built a login and authentication system -- that builds a form, and
queries the database to see if the userid and password are correct.
Then I built a system to list what was in the book table for the
database.  Around the time I finished that, I realized I needed more
granularity in user logins, so I went back and rebuilt the login tool.
 Then I realized I didn't actually have a way to add stuff to the DB,
so I built that tool and so on.  It ended up taking me something
like a year, because I'd never looked at PHP before, and I've now
scrapped the entire project and rebuilt it.  Why?  Because I did just
about everything wrong.  It just plain wasn't practical to try to fix
it.  I'd never learned the basics, I just threw myself at a big
project to see what would happen.

  Good luck!

-Andy McKenzie

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



Re: [PHP] Is this list less busy than it used to be?

2012-07-04 Thread Andy McKenzie
On Wed, Jul 4, 2012 at 6:04 AM, RGraph.net support supp...@rgraph.net wrote:
 Hi,

 https://docs.google.com/spreadsheet/ccc?key=0Ak1QF0ijPYbedDNvb19SQl80MHcxUWhhbTZOYm5FUlE

 Yikes. That's a littled bit worrying. Or does it really mean that
 everyone is getting much better with PHP? :-)

 --
 Richard, RGraph.net support
 RGraph: JavaScript charts for your website
 http://www.rgraph.net

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


My guess would be that it's just one of those things -- every list
I've ever been on goes through cycles of more and less activity.
Also, most of them wind down quite a lot in the North American summer
(the motorcycle forums being an exception).

They also tend to hit a peak around the end of the first/beginning of
the second year they exist, then taper off for a while, then come
back.  I'd bet when the next major version of PHP is released we'll
see an upswing in traffic for a while as people try to figure it out.

-Andy

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



Re: [PHP] book quest

2011-09-29 Thread Andy McKenzie
 Is there something wrong with the PHP.net manual?  Or you just want
 something physical to be able read any where and stay unplugged?  If the
 latter and there's nothing wrong with the official manual, try downloading
 the chm or single html file and print as you go.  No need to lug around
 thick that manual/reference ;)

 Regards,
 Tommy


I'm not the original poster, but I have a response to this:


I didn't find that there was anything wrong with the PHP.net manual,
except that it wasn't a book about learning to program.  It's a
fantastic reference guide;  if I can't remember what order the inputs
to that one function go in, it's my first resort.  But I prefer to
read paper for learning theory, and I find it more useful to flip
through pages trying to find something I half remember than to click
through links.  Put simply, I like to learn the basics from books
rather than web pages.

-Andy

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



Re: [PHP] book quest

2011-09-28 Thread Andy McKenzie
On Wed, Sep 28, 2011 at 6:20 PM, Kirk Bailey kbai...@howlermonkey.net wrote:
 The best book for a beginner? No, don't tell me php.net, I hear that one
 already, and while it is indeed good, I want something in a dead tree
 edition I can canny around and smoke as needed.

 --
 end

 Very Truly yours,
                 - Kirk Bailey,
                   Largo Florida

                       kniht
                      +-+
                      | BOX |
                      +-+
                       think


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



I agree with Bastien -- I've had great luck with the PHP books.
Beginning PHP4 has a permanent place on my shelf, even though PHP4
is outdated.  Beginning PHP5.3 hasn't quite supplanted it as a
concept book, but is my go-to for here's a way to solve this
particular problem using a new version of PHP book.

-Andy

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



Re: [PHP] Upgrade or Die?

2011-06-24 Thread Andy McKenzie
On Fri, Jun 24, 2011 at 1:30 PM,  ja...@nixsecurity.org wrote:
 Chrome. Enough said. Now, if we can only convince the rest of the world ...


Ugh.  I can't stand Chrome.  Of course, I gave up on Firefox years ago
and went back to Opera, so it doesn't bother me when Firefox does
something weird like this...

-Andy

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



Re: [PHP] the best 1 book for php

2011-04-07 Thread Andy McKenzie
On Thu, Apr 7, 2011 at 12:15 AM, Kirk Bailey kbai...@howlermonkey.net wrote:
 If I only had 1 book on php, what would it be?

 --
 end

 Very Truly yours,
                 - Kirk Bailey,
                   Largo Florida


My most common reference is, as other people have said, www.php.net.
But when I reach for a paper book for some reason, it's usually
because I can't remember something really basic, and I reach for
Beginning PHP4 from WROX press.  It's out of date, but the concepts
are still right, and the basic stuff still works the same way.  I
haven't bought the newer Beginning PHP5 yet, but if I were going to
buy just one, it would probably be that.

-Alex

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



Re: [PHP] Question about directory permissions

2011-03-21 Thread Andy McKenzie
Sure.  The script runs with the permissions of whoever is running it.

In general, a PHP script that's a web page in linux will run by a user
called something like apache, apache2, www-user, or something similar.
 If you give that user permissions -- either directly or through their
group, often of the same name -- to write to the directory in
question, then the script will be able to write to it.

For instance:  on my Ubuntu 10.04 server, I want my script DW3 to be
able to write to /var/www/DW3/logs.  I leave ownership of everything
else as it was, and do the following:

$ cd /var/www/DW3
$ chgrp www-data ./logs
$ chmod 770 ./logs

Now members of the group www-data (at the moment only apache) can
write to the directory, as can the owner, but no one else can.  In
reality, I could probably have set that to 660, but I don't much care
about the slight added risk of using 770 in this case.  (If you're
confused by the numbers I used, check here:
http://www.yolinux.com/TUTORIALS/LinuxTutorialManagingGroups.html)


I hope that helps!

-Andy

On Mon, Mar 21, 2011 at 1:58 PM, Al n...@ridersite.org wrote:
 I understand dir perms pretty well; but, have a question I can't readily
 find the answer to.

 Under a Linux system, scripts can't write, copy, etc. to other dirs unless
 the perms are set for writable for the script e.g., nobody.

 But, is there a way a script can write or copy within its own dir?

 Thanks...

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



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



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
On Mon, Mar 14, 2011 at 11:39 PM, Adam Richardson simples...@gmail.com wrote:

 This one's got me stumped.  I
 have the following line in a script:

 $this-bc = ($this-network | (~$this-netmask))  4294967295;

 $this-network and $this-netmask should both be of type long, and I
 should wind up with another long.  I didn't write the original method,
 and I can't remember what bc stands for at the moment, but it's part
 of a tool for working out first and last IP address, netmask, and a
 few other things from a subnet definition.

 On the old system, it works fine.  On the new system, I get the following
 error:

 PHP Fatal error:  Unsupported operand types in
 /var/www/test/common_subnet.inc on line 39


 Have you checked the types being operated on? I'm wondering if somehow one
 of the object properties you're operating on has changed has changed in
 terms of type.

 I'd try var_dumping each of the properties ($this-network and
 $this-netmask) the line above just to make sure they didn't somehow get
 switched to a type that bitwise operators complain about (array, Object.)

 Adam

 --
 Nephtali:  A simple, flexible, fast, and security-focused PHP framework
 http://nephtaliproject.com


I'll check when I get back to work, but I doubt that's it:  the last
time either is touched, it's being converted from an network address
or netmask to a long, using ip2long.  I would assume that if there was
a problem with that, it would show up there, not when it got further
down.  I'll check the values, though, as I say... I hadn't really
considered that something might be failing silently earlier on.

-Alex

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



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
On Tue, Mar 15, 2011 at 8:07 AM, Andy McKenzie amckenz...@gmail.com wrote:
 On Mon, Mar 14, 2011 at 11:39 PM, Adam Richardson simples...@gmail.com 
 wrote:

 This one's got me stumped.  I
 have the following line in a script:

 $this-bc = ($this-network | (~$this-netmask))  4294967295;

 $this-network and $this-netmask should both be of type long, and I
 should wind up with another long.  I didn't write the original method,
 and I can't remember what bc stands for at the moment, but it's part
 of a tool for working out first and last IP address, netmask, and a
 few other things from a subnet definition.

 On the old system, it works fine.  On the new system, I get the following
 error:

 PHP Fatal error:  Unsupported operand types in
 /var/www/test/common_subnet.inc on line 39


 Have you checked the types being operated on? I'm wondering if somehow one
 of the object properties you're operating on has changed has changed in
 terms of type.

 I'd try var_dumping each of the properties ($this-network and
 $this-netmask) the line above just to make sure they didn't somehow get
 switched to a type that bitwise operators complain about (array, Object.)

 Adam

 --
 Nephtali:  A simple, flexible, fast, and security-focused PHP framework
 http://nephtaliproject.com


 I'll check when I get back to work, but I doubt that's it:  the last
 time either is touched, it's being converted from an network address
 or netmask to a long, using ip2long.  I would assume that if there was
 a problem with that, it would show up there, not when it got further
 down.  I'll check the values, though, as I say... I hadn't really
 considered that something might be failing silently earlier on.

 -Alex


And, as Adam suggested, the problem is in fact with the input values.
On the old system, those variables have the following values:

this-network:
int(168566272)

this-netmask:
int(4294966784)

On the new system, they return:

this-network:
int(0)

this-netmask:
bool(false)


Clearly there's a problem there.  Here's the code that generates those values:

class subnet
 { # Begin class subnet
private $cidr;  # The CIDR format network definition
private $ip_array;  # An array with the IP and the CIDR netmask
private $ip;# The IP, as a decimal
private $netmask;   # The binary netmask
private $network;   # The network number
private $bc;# beats me, but it's used all
over the place.

public function __construct($cidr)
 { # Begin __construct
$this-cidr = $cidr;
$this-ip_array = explode('/', $this-cidr);
for($i = 1; $i = 32; $i++)
{ $this-bin .= $this-ip_array[1] = $i ? '1' : '0'; }
$this-ip_array[1] = bindec($this-bin);
$this-netmask = ip2long($this-ip_array[1]);
$this-network = ($this-ip  $this-netmask);

   $this-bc = ($this-network | (~$this-netmask))  4294967295;
 } # End __construct

From there it goes on to give me functions to return the first, last,
and total number of IPs in the range, the netmask, and so on.  They
can all be returned as either a standard ip (1.2.3.4) or a long int.

Now:  I did a little more looking around this morning, and it looks
like I may well run into problems here given that I'm moving from a
32-bit architecture to a 64-bit architecture.  Bitwise math is still
fairly obscure to me, so it's likely that I'm overlooking something
obvious, but maybe instead of asking How do I fix this? I should be
asking What would the right way to do this have been?  As I think I
said before, I didn't actually write most of this code, I inherited
it, and as long as the input and output of the class remain the same,
I don't actually care how the work is done.


If anyone has any useful input here, I'd appreciate it!

-Alex

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



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
 Now:  I did a little more looking around this morning, and it looks
 like I may well run into problems here given that I'm moving from a
 32-bit architecture to a 64-bit architecture.  Bitwise math is still
 fairly obscure to me, so it's likely that I'm overlooking something
 obvious, but maybe instead of asking How do I fix this? I should be
 asking What would the right way to do this have been?  As I think I
 said before, I didn't actually write most of this code, I inherited
 it, and as long as the input and output of the class remain the same,
 I don't actually care how the work is done.


 If anyone has any useful input here, I'd appreciate it!

 -Alex


As it turns out, the most important lesson here is:  Don't trust what
anyone tells you.  The old server is 64-bit.  The new server is
32-bit.  Once I stopped to check that myself, it all became clear.
For the archives, here's what happened.

Everything worked fine until I ran bindec() on the binary netmask;  at
that point it returned a float rather than an int, as it it used to.
Therefore, when I ran ip2long on the result, it choked, and returned
bool(false).  Which isn't really useful when you're trying to produce
a human-readable netmask, when you get right down to it.

I still don't have a solution that will work on a 32-bit server, but
now that I know what's going on, I should be able to either find
something that will work, or get things moved to a 64-bit machine.


-Alex

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



[PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-14 Thread Andy McKenzie
Greetings,

   I'm moving some scripts from an older server (SuSE who-knows-what,
running PHP 5.2.5) to a newer one (Ubuntu 10.10, running PHP 5.3.2).
For the most part there haven't been any problems, or they've been
things that I was able to fix easily.  This one's got me stumped.  I
have the following line in a script:

$this-bc = ($this-network | (~$this-netmask))  4294967295;

$this-network and $this-netmask should both be of type long, and I
should wind up with another long.  I didn't write the original method,
and I can't remember what bc stands for at the moment, but it's part
of a tool for working out first and last IP address, netmask, and a
few other things from a subnet definition.

On the old system, it works fine.  On the new system, I get the following error:

PHP Fatal error:  Unsupported operand types in
/var/www/test/common_subnet.inc on line 39

I've done a little searching without any luck:  if anyone can give me
a quick answer, or at least point me to something that will explain
what's going on, I'd appreciate it.

Thanks,
  Alex McKenzie

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



Re: [PHP] How to write code: how wrong am I?

2011-02-22 Thread Andy McKenzie
On Tue, Feb 22, 2011 at 6:29 AM, Dotan Cohen dotanco...@gmail.com wrote:
 I wrote a short page on how to actually type of code that one writes,
 it can be found here:
 http://dotancohen.com/howto/write_code.html

 The point that I stress on the page is that first you close an
 element, then you fill it's contents. The page has examples in HTML
 and PHP. I would like to know what the experienced programmers here
 think about this. Am I going about it wrong?

I'll be the first to tell you that I'm not a great programmer, so my
take may not be worth a lot.  However, this is pretty close to how I
write.  Not exactly, but close.  I also always label open and closing
brackets on everything, unless the brackets are less than three lines
apart.  For instance, I might find myself writing:

if($foo == 'bar')
{ # Begin foo=bar test
   # If foo=bar, do a lot of things.

} # End foo=bar test

Then I go back and fill in the conditional stuff.  I've found two sets
of benefits to doing things this way.

1) I don't forget to close the brackets later, and I know they're
indented properly.
2) The comments mean that if I get to the beginning of a section and
want to skip to the end, I can just search for whatever comes after
Begin, and know that the next instance will be the end of that
section.

I also tend to document my code in comments before I start writing
actual code.  I frequently find that that helps keep me on track,
rather than getting distracted by random new features that occur to me
after I start.  It also means that when the time comes to document
what I did, most of it is already there... that's saved me a few
times.  (I tend to wind up with about a 2:1 ratio of comments to code,
which at least means I can figure out later what I was thinking when I
wrote that horrible mess.)

So I can't say whether it's worthwhile practice for a good programmer
who writes on a regular basis:  for someone like me, who throws
together an occasional script to save time later, or a personal
web-site that needs a database backend, it can save a lot of
aggravation.

-Alex

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



[PHP] Cross-platform IDE

2011-01-26 Thread Andy McKenzie
Hey folks,

Hopefully this is enough on-topic not to annoy anyone.  Up until
now I've mostly written small one-off scripts -- a web page that needs
a few things dynamically generated, a shell script to do a small job,
things like that -- and vim has been more than adequate.  I'm
currently working on something a lot more complex -- a web based
front-end for a medium sized custom database -- and I'm finding that
my code is getting more and more scattered because I don't have a good
tool for looking at it.

   So:  does anyone have a recommendation for an IDE that works in
Windows, Mac, and Linux?  I spend roughly equal time in all three, and
I haven't found a tool I like yet that works in all of them.
Actually, I stopped looking three or four years ago, but at that point
there didn't seem to be anything.  If anyone has any advice, I'd love
to hear it!

Thanks,
  Alex

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



Re: [PHP] Cross-platform IDE

2011-01-26 Thread Andy McKenzie
On Wed, Jan 26, 2011 at 8:51 AM, Lester Caine les...@lsces.co.uk wrote:
 Andy McKenzie wrote:

 So:  does anyone have a recommendation for an IDE that works in
 Windows, Mac, and Linux?  I spend roughly equal time in all three, and
 I haven't found a tool I like yet that works in all of them.
 Actually, I stopped looking three or four years ago, but at that point
 there didn't seem to be anything.  If anyone has any advice, I'd love
 to hear it!

 I'm not running mac, but my windows/linux eclipse setup is more than
 transparent enough, at times I have to remember which machine I am on ;)
 phpeclipse gives me a suitable php based editor to go with it, and the other
 integrated editors such as html, javascript and css fill all the gaps.

 --
 Lester Caine - G8HFL
 -
 Contact - http://lsces.co.uk/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk//
 Firebird - http://www.firebirdsql.org/index.php

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



It sounds like Eclipse is the clear preference in this group... I'll
give it a try, and see how I like it!

Thanks,
  Alex

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



Re: [PHP] Command line PHP

2011-01-07 Thread Andy McKenzie
On Fri, Jan 7, 2011 at 11:55 AM, la...@garfieldtech.com
la...@garfieldtech.com wrote:
 Hi folks.  I have a project coming up that will involve writing a
 non-trivial command line PHP application.  Most of it will be nice and
 abstracted and standalone and all of that jazz, but it will need to do
 command line interation.  I'm not sure yet if it will be interactive or if I
 just need to parse lots of command line switches.

 Has anyone used a CLI-handling library they like?  I recall briefly using
 the PEAR CLI library many many years ago and disliking it because it was
 only barely a step above the raw PHP-CLI SAPI, and still required lots of
 if-else branching in my code.  I don't know if there's anything better since
 then, however.  I prefer clean OO to procedural, but can work with
 procedural if needs be.  The fewer dependencies it has the better as well.

 Any recommendations?

 (Open source, GPLv2-compatible required.)

 --Larry Garfield

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



If all you want is a way to handle command line arguments, I built a
library to do that a few years ago.  I got sick of needing to switch
languages to write a quick command-line script, and I hated the PEAR
CLI tools.  I haven't really looked at it since, and since it was just
about the first thing I wrote that was object oriented I suspect it's
got some problems, but you're welcome to give it a try.

http://people.chem.umass.edu/amckenzie/code/php/php_cli_io/

It handles flags both with and without short forms, and flags with
either zero, one or two arguments.  The demo file in the package has
the docs written into it -- read through it to see how the library
works.

If anyone tries it, let me know what you think, and what I've done
wrong.  It does everything I need, but I don't think anyone else has
ever used it.

-Alex

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



Re: [PHP] Reminder On Mailing List Rules

2010-10-22 Thread Andy McKenzie
 PHP is basically the only language I deal with any more - and it's the
 only language I -want- to deal with. I hate to see basic semantics
 such as top post you asshole scare off fresh blood and create a
 hostile or otherwise discriminatory environment. Keep PHP alive and
 well, at least until I retire. Don't let it die like Perl has! (ha,
 ha)

Hear, hear!  I've got to say, the knowledge present on this list has
been amazingly useful to me, but the rudeness -- come out in force in
this thread -- really makes me question remaining a member.  There are
already a few people on the list whose posts I just glance at to see
if there's code, and skip if there's not.

I know it's pretty common for programming lists to get rude, but it's
always seemed pretty unnecessary to me.  So far, on this list, the
balance is still  favoring the value of the knowledge here, but it's
been a close thing a few times in the last week.

-Andy

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



Re: [PHP] Reminder On Mailing List Rules

2010-10-22 Thread Andy McKenzie
On Fri, Oct 22, 2010 at 9:22 AM, Jay Blanchard jblanch...@pocket.com wrote:
 [snip]
 really makes me question remaining a member...it's been a close thing a
 few times in the last week.
 [/snip]

 $door = new door(large, heavy, swift);
 $door-open();
 $door-hitArse();
 $door-close();

 C'mon, the rudeness out weighs the good of this list?


Not yet, as I said.  But there've been a couple items in the last week
that made me wonder.

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



Re: [PHP] which one is faster

2010-10-06 Thread Andy McKenzie
On Wed, Oct 6, 2010 at 9:03 AM, Robert Cummings rob...@interjinn.com wrote:
 On 10-10-06 08:52 AM, Peter Lind wrote:

 Where exactly do you get the part about double quotes from? Can't seem
 to locate it in the any of the relevant specs (xhtml or xml). Also,
 never seen an xml or xhtml validator choke on single quotes.

 http://www.w3.org/TR/xhtml1/#h-4.2

 Cheers,
 Rob.

I don't see that it explicitly states a requirement for double quotes
there -- it certainly implies it, but the text never says anything
about either double-quotes being required or single-quotes being
disallowed.

Full text:  All attribute values must be quoted, even those which
appear to be numeric.

Is there a statement somewhere in the document that says quotes are
always double-quotes?

-Alex

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



Re: [PHP] which one is faster

2010-10-06 Thread Andy McKenzie
On Wed, Oct 6, 2010 at 9:25 AM, Peter Lind peter.e.l...@gmail.com wrote:
 On 6 October 2010 15:21, Andy McKenzie amckenz...@gmail.com wrote:
 On Wed, Oct 6, 2010 at 9:03 AM, Robert Cummings rob...@interjinn.com wrote:
 On 10-10-06 08:52 AM, Peter Lind wrote:

 Where exactly do you get the part about double quotes from? Can't seem
 to locate it in the any of the relevant specs (xhtml or xml). Also,
 never seen an xml or xhtml validator choke on single quotes.

 http://www.w3.org/TR/xhtml1/#h-4.2

 Cheers,
 Rob.

 I don't see that it explicitly states a requirement for double quotes
 there -- it certainly implies it, but the text never says anything
 about either double-quotes being required or single-quotes being
 disallowed.

 Full text:  All attribute values must be quoted, even those which
 appear to be numeric.

 Is there a statement somewhere in the document that says quotes are
 always double-quotes?

 No, there isn't. Both single quotes and double quotes are allowed for
 attributes in both XML and XHTML. What makes you think it's implied
 that double quotes are the only allowed form of quotes?

 Regards
 Peter


Double quotes are the only example given:  in most documentation if
there are two allowed forms, there are two examples, or at least a
note in the text.  I haven't read enough of this particular document
to know if they follow that form, but I've certainly seen it a lot of
places.

-Alex

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



[PHP] if/elseif being treated as if/if

2010-09-24 Thread Andy McKenzie
Hey folks,

  Here's the deal.  I have the following code:

if($col_vals[$i][$val['column']] == $search_result[0][$col])
  { echo ' selected=selected'; }
elseif($val['default'] == $col_vals[$i][$val['column']])
  { echo ' selected=selected'; }

  It's supposed to check whether there's a value in the db
($search_result[0][$col]) that matches the current column value, and
if not, check whether the default matches it.  It does that, sort of.
In fact, both statements trigger, which I would have said wasn't
possible.

  So the question is:  what causes both parts of an if/elseif
statement to trigger?  As far as I can see my punctuation is correct,
and I've confirmed through debugging statements that all the values
are what I expect, so how do I make the elseif stop acting like
another if?  Or, alternatively, have I just misunderstood all this
time what the if/elseif statement does?

Thanks,
  Alex

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



Re: [PHP] if/elseif being treated as if/if

2010-09-24 Thread Andy McKenzie
I found the problem while I was copying the code over.  The problem is
that the if triggers in loop one, and the elseif triggers in loop two.
 In other words, it does exactly what it's supposed to, I just didn't
think through what the loop would accomplish.  Now to figure out how
to make it do what I meant it to do.

For the benefit of people who screwed up the same way I did:


while($i  count($col_vals))
{ # Start populating drop box
$temp_column = $val['column'];
echo 'option value=' . $col_vals[$i][$val['column']] . '';
if($col_vals[$i][$val['column']] == $search_result[0][$col])
   { echo ' selected=selected'; }
elseif($val['default'] == $col_vals[$i][$val['column']])
  { echo ' selected=selected'; }echo '' .
$col_vals[$i][$val['column']] . '/option' . \n;
$i++;
   } # End populating drop box



And here's the output:

option value=vlan1201 selected=selectedvlan1201/option
option value=none selected=selectednone/option
option value=vlan1288vlan1288/option


While generating line one of the output:
$col_vals[$i][$val['column']] = 'vlan1201'
$search_result[0][$col] = 'vlan1201'
$val['default'] = 'none'

Naturally, in round one, it's selected -- that's the if statement.  In
round two, it's also selected -- that's the elseif statement.  In
round three, neither applies.

To fix it, I changed the elseif to be as follows:

elseif(($val['default'] == $col_vals[$i][$val['column']]) 
(!isset($search_result[0][$col])))

Now the elseif only triggers if there is a default, but there is no
value in the DB for that field.


Hope my failure to think saves someone else some trouble later!

-Alex





On Fri, Sep 24, 2010 at 1:56 PM, chris h chris...@gmail.com wrote:
 Andy I see no reason why both echo's would fire; unless this block of code
 gets executed multiple times.  can we see more of the code?

 Chris H.


 On Fri, Sep 24, 2010 at 1:50 PM, Andy McKenzie amckenz...@gmail.com wrote:

 Hey folks,

  Here's the deal.  I have the following code:

 if($col_vals[$i][$val['column']] == $search_result[0][$col])
          { echo ' selected=selected'; }
 elseif($val['default'] == $col_vals[$i][$val['column']])
          { echo ' selected=selected'; }

  It's supposed to check whether there's a value in the db
 ($search_result[0][$col]) that matches the current column value, and
 if not, check whether the default matches it.  It does that, sort of.
 In fact, both statements trigger, which I would have said wasn't
 possible.

  So the question is:  what causes both parts of an if/elseif
 statement to trigger?  As far as I can see my punctuation is correct,
 and I've confirmed through debugging statements that all the values
 are what I expect, so how do I make the elseif stop acting like
 another if?  Or, alternatively, have I just misunderstood all this
 time what the if/elseif statement does?

 Thanks,
  Alex

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




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



Re: [PHP] Auto-generating HTML

2010-09-21 Thread Andy McKenzie
On Tue, Sep 21, 2010 at 3:32 AM, Simcha Younger
simcha.youn...@gmail.com wrote:
 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:


 Hey folks,

  Here's the problem.  I'm writing a lot of pages, and I hate going in
 and out of PHP.  At the same time, I want my HTML to be legible.  When
 you look at it, that's kind of a problem, though... for instance
 (assume this had some PHP in the middle, and there was actually a
 reason not to just put this in HTML in the first place):

 Unless you are looking at the HTML alot, you can just paste the source into 
 an editor which can auto-format the code, or look at the code in firebug 
 (that is the usual place where I look at my HTML.)

 If there is a specific place you want to look at in the html, just change the 
 lines there to look like this:
 echo 'html
 ';
 but this will make your PHP quite messy if you do it alot.

 I would go with templating, as many here suggested.

 --
 Simcha Younger simcha.youn...@gmail.com


That's actually why this came up -- for the first time I AM looking at
the generated HTML a lot.  I'm building a frontend for a set of DBs we
use (for various reasons none of the pre-built ones I could find would
work for us), and I'm spending a fair amount of time trying to figure
out whether I messed up the code, or the output just doesn't display
as I expected.  I've never done anything quite this complex, and have
therefore never needed to look at the output html a lot.  I've also
just gotten tired of having my output completely unreadable... I'd
like to have this project done right, and to me that means the source
and the output should both be reasonably easy to parse, in addition to
other things (paying a lot more attention to security than I usually
do, for instance...).

-Alex

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Andy McKenzie
On Mon, Sep 20, 2010 at 3:47 PM, Steve Staples sstap...@mnsi.net wrote:
 On Mon, 2010-09-20 at 14:56 -0400, Andy McKenzie wrote:
 Hey folks,

   I have the feeling this is a stupid question, but I can't even find
 anything about it.  Maybe I'm just not searching for the right things.

   Here's the problem.  I'm writing a lot of pages, and I hate going in
 and out of PHP.  At the same time, I want my HTML to be legible.  When
 you look at it, that's kind of a problem, though... for instance
 (assume this had some PHP in the middle, and there was actually a
 reason not to just put this in HTML in the first place):

 Simple PHP:
 ?php

 echo 'html';
 echo 'head';
 echo '  titlePage Title/title';
 echo '/head';
 echo 'body';
 echo 'pThis is the page body/p';
 echo '/body';
 echo '/html';

 ?


 Output page source:
 htmlhead  titlePage Title/title/headbodypThis is the
 page body/p/body/html


 Now, I can go through and add a newline to the end of each line (echo
 'html' . \n; and so on), but it adds a lot of typing.  Is there a
 way to make this happen automatically?  I thought about just building
 a simple function, but I run into problem with quotes -- either I
 can't use single quotes, or I can't use double quotes.  Historically,
 I've dealt with the issue by just having ugly output code, but I'd
 like to stop doing that.  How do other people deal with this?

 Thanks,
   Alex



 Have you thought about SMARTY templates?

 easy to use, it's just a class, and you write your html in template
 files, which are easier to read than in your php files.

 Just a thought... i personally LOVE smarty template.

 Steve



I've never used it, but I may take a closer look.  Overall I tend to
find templates and pre-built frameworks frustrating, but it may be
time to break down and learn to use them.

-Alex

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Andy McKenzie
On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote:
 On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote:

 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:

  Hey folks,
 
   I have the feeling this is a stupid question, but I can't even find
  anything about it.  Maybe I'm just not searching for the right things.
 
   Here's the problem.  I'm writing a lot of pages, and I hate going in
  and out of PHP.  At the same time, I want my HTML to be legible.  When
  you look at it, that's kind of a problem, though... for instance
  (assume this had some PHP in the middle, and there was actually a
  reason not to just put this in HTML in the first place):
 
  Simple PHP:
  ?php
 
  echo 'html';
  echo 'head';
  echo '  titlePage Title/title';
  echo '/head';
  echo 'body';
  echo 'pThis is the page body/p';
  echo '/body';
  echo '/html';
 
  ?
 
 
  Output page source:
  htmlhead  titlePage Title/title/headbodypThis is the
  page body/p/body/html
 
 
  Now, I can go through and add a newline to the end of each line (echo
  'html' . \n; and so on), but it adds a lot of typing.  Is there a
  way to make this happen automatically?  I thought about just building
  a simple function, but I run into problem with quotes -- either I
  can't use single quotes, or I can't use double quotes.  Historically,
  I've dealt with the issue by just having ugly output code, but I'd
  like to stop doing that.  How do other people deal with this?
 
  Thanks,
   Alex

 Alex

 Just add a \n at the end as

 echo 'html\n';

 That will not work. Single quotes means that the '\n' is not interpreted
 as a new line so you'll see a bunch of '\n' in the output.

 What I sometimes do is:

 $out = array();
 $out[] = 'html';
 $out[] = 'head';
 $out[] = '  titlePage Title/title';
 $out[] = '/head';
 $out[] = 'body';
 $out[] = 'pThis is the page body/p';
 $out[] = '/body';
 $out[] = '/html';
 echo join(\n,$out);


Interesting.  I hadn't thought of that, but it could work.  It'd still
be quite a bit of extra typing, but at least I find it more
readable...

-Alex

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Andy McKenzie
On Mon, Sep 20, 2010 at 3:59 PM, Peter Lind peter.e.l...@gmail.com wrote:
 On 20 September 2010 21:56, Andy McKenzie amckenz...@gmail.com wrote:
 On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote:
 On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote:

 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:

  Hey folks,
 
   I have the feeling this is a stupid question, but I can't even find
  anything about it.  Maybe I'm just not searching for the right things.
 
   Here's the problem.  I'm writing a lot of pages, and I hate going in
  and out of PHP.  At the same time, I want my HTML to be legible.  When
  you look at it, that's kind of a problem, though... for instance
  (assume this had some PHP in the middle, and there was actually a
  reason not to just put this in HTML in the first place):
 
  Simple PHP:
  ?php
 
  echo 'html';
  echo 'head';
  echo '  titlePage Title/title';
  echo '/head';
  echo 'body';
  echo 'pThis is the page body/p';
  echo '/body';
  echo '/html';
 
  ?
 
 
  Output page source:
  htmlhead  titlePage Title/title/headbodypThis is the
  page body/p/body/html
 
 
  Now, I can go through and add a newline to the end of each line (echo
  'html' . \n; and so on), but it adds a lot of typing.  Is there a
  way to make this happen automatically?  I thought about just building
  a simple function, but I run into problem with quotes -- either I
  can't use single quotes, or I can't use double quotes.  Historically,
  I've dealt with the issue by just having ugly output code, but I'd
  like to stop doing that.  How do other people deal with this?
 
  Thanks,
   Alex

 Alex

 Just add a \n at the end as

 echo 'html\n';

 That will not work. Single quotes means that the '\n' is not interpreted
 as a new line so you'll see a bunch of '\n' in the output.

 What I sometimes do is:

 $out = array();
 $out[] = 'html';
 $out[] = 'head';
 $out[] = '  titlePage Title/title';
 $out[] = '/head';
 $out[] = 'body';
 $out[] = 'pThis is the page body/p';
 $out[] = '/body';
 $out[] = '/html';
 echo join(\n,$out);


 Interesting.  I hadn't thought of that, but it could work.  It'd still
 be quite a bit of extra typing, but at least I find it more
 readable...


 Ash already mentioned it: heredoc format. Much easier, less typing,
 easier to read, keeps formatting, etc, etc etc.

 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


You may well be right;  it's a format I haven't used much, but it may
well be the right choice here.


I think the main thing I'm seeing is that there isn't a single,
accepted, simple way to do this:  no matter what I do, it will be a
workaround of some type.  Either I'm adding complexity (a function to
convert everything), or I'm adding lines (heredoc/nowdoc seem to
require that the opening and closing tags be on lines without any of
the string on them), or I'm adding typing (adding ' . \n' to the end
of every line of HTML).  Perhaps I'll put some effort into building a
function to do it, but not this week... I think for now I'll keep
appending those newlines, and just have more code to fix at a later
date.  It's reasonably clean, it's just mildly annoying.

Thanks, all, and if anyone comes up with a really elegant solution,
please let me know!

-Alex

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Andy McKenzie
Here's a related question maybe one of you can answer:  is there any
place in HTML (not PHP, but actually in HTML) where there's a
difference between a single quote and a double quote?  As nearly as I
can tell, it shouldn't ever matter.  If that's the case, using
double-quotes to enclose an echo gets a lot simpler...

-Alex

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



Re: [PHP] 1984 (Big Brother)

2010-09-13 Thread Andy McKenzie
On Mon, Sep 13, 2010 at 8:11 PM, Micky Hulse mickyhulse.li...@gmail.com wrote:
 On Mon, Sep 13, 2010 at 5:05 PM, Daniel Brown danbr...@php.net wrote:
    It would be cheaper to employ the same method used on some
 lawnmowers and required on Jet Skis and Skidoos: a cable with a clip
 worn by the rider.  The rider falls off, the cable releases from the
 vehicle, disengaging the throttle and cutting the engine.  The boss
 stands up, his entire infrastructure collapses, everyone's connections
 are closed, and all PCs subsequently catch fire.

 Lol! That would make a great Dilbert and/or Farside cartoon. :)


It would, wouldn't it?

Anyway.  Something you could do is a script that turns mysqld on and
off:  set him up with an SSH connection to the server, and he can run
the script when he gets in to turn it on, and run it again whenever he
leaves to turn it off.  A cron job to turn mysqld off at whatever time
he usually leaves would probably be a reasonable failsafe.  If he
really wants you could probably link it to a swipe card system or just
a keyboard on his desk (enter your PIN to turn it on, enter it again
to turn it off).

All that aside, I can't help feeling that this has gotten into I'm
afraid you know too much for us to let you leave:  Guards!  Take him
away! territory.

-Alex

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



Re: [PHP] Standalone WebServer for PHP

2010-09-12 Thread Andy McKenzie

 A question, to clarify my fuzzy thinking about such things:

 Can a business have a server connected to the Internet but limit access to
 just their employees? I don't mean a password protected scheme, but rather
 the server being totally closed to the outside world other than to their
 internal employees? Or is this something that can only be provided by a LAN
 with no Internet connection?

 Cheers,

 tedd

Hey, one I can answer!

The short answer is Yes.  It can be done in a firewall:  for
instance, take the following network setups.

1) Internal machines on a single range (10.10.0.1-10.10.0-254),
gateway machine at 10.10.0.1, web server at 10.10.0.2.
  In this situation, the gateway passes traffic web traffic from
outside to 10.10.0.2/80 (destination NATing, in linux's iptables), and
traffic from inside to 10.10.0.2/8880.  There's no reasonable way for
outside traffic to reach the web server, but the web server can still
reach the outside world.  If you don't want to have ANYONE outside the
private network reach the web server, you can eliminate the dnat rule
so port 80 traffic isn't forwarded.  If the employees need access from
outside, a VPN would work best, as Ash suggested, but there are other
options.  The catch is that you need to either use virtual hosts,
which brings one set of problems, or two pieces of web-server software
(two instances of apache, for instance), which brings a different set
of problems.

2) All systems on publicly reachable addresses
(230.54.8.0-230.54.8.254, to pick at random).  The web server is at
230.54.8.2, there is no gateway.  The firewall here needs to be on the
web server, since there is no gateway, and it only allows port 8880
traffic in if it's from the range 230.54.8.0/24.  Again, if no
external access is necessary, it can be simplified somewhat.

In either instance, employees with permanent IP addresses at home can
be allowed in via the firewall.

-Alex

3)

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



Re: [PHP] Standalone WebServer for PHP

2010-09-12 Thread Andy McKenzie
On Sun, Sep 12, 2010 at 1:51 PM, tedd tedd.sperl...@gmail.com wrote:
 At 1:18 PM -0400 9/12/10, Andy McKenzie wrote:

  

  A question, to clarify my fuzzy thinking about such things:

  Can a business have a server connected to the Internet but limit access
 to
  just their employees? I don't mean a password protected scheme, but
 rather
  the server being totally closed to the outside world other than to their
  internal employees? Or is this something that can only be provided by a
 LAN
  with no Internet connection?

  Cheers,

  tedd

 Hey, one I can answer!

 The short answer is Yes.  It can be done in a firewall:  for
 instance, take the following network setups.

 1) Internal machines on a single range (10.10.0.1-10.10.0-254),
 gateway machine at 10.10.0.1, web server at 10.10.0.2.
  In this situation, the gateway passes traffic web traffic from
 outside to 10.10.0.2/80 (destination NATing, in linux's iptables), and
 traffic from inside to 10.10.0.2/8880.  There's no reasonable way for
 outside traffic to reach the web server, but the web server can still
 reach the outside world.  If you don't want to have ANYONE outside the
 private network reach the web server, you can eliminate the dnat rule
 so port 80 traffic isn't forwarded.  If the employees need access from
 outside, a VPN would work best, as Ash suggested, but there are other
 options.  The catch is that you need to either use virtual hosts,
 which brings one set of problems, or two pieces of web-server software
 (two instances of apache, for instance), which brings a different set
 of problems.

 2) All systems on publicly reachable addresses
 (230.54.8.0-230.54.8.254, to pick at random).  The web server is at
 230.54.8.2, there is no gateway.  The firewall here needs to be on the
 web server, since there is no gateway, and it only allows port 8880
 traffic in if it's from the range 230.54.8.0/24.  Again, if no
 external access is necessary, it can be simplified somewhat.

 In either instance, employees with permanent IP addresses at home can
 be allowed in via the firewall.

 -Alex

 3)

 -Alex:

 Many thanks -- now I need to figure what you said and how to implement it.
  :-)

 Does this mean that my client will need a physically local server with
 fire-wall software protection or can this be done in conventional remote
 hosting environment with htaccess (or whatever) directives?

 I really need to understand the basics.

 Thanks for your help.

 Cheers,

 tedd

 --
 ---
 http://sperling.com/


Tedd,

   First off, I don't recommend trying to build a secure firewall
yourself if you don't know what you're doing, much like I wouldn't
recommend building your own web server.  There are a lot of potential
pitfalls, and ways to make things look like they're secure when they
really aren't.

   That said, here's my take.

   It sounds from what you said like you have a client with the following setup:

-  Machines in the office, probably on a private subnet with a single
public IP showing (this is Network Address Translation, or NAT).

- A remote server rented from a hosting company.  Hopefully it's
running Linux/Apache, rather than Windows/anything, because it's
easier (for me, at least) if it's linux.  I'll assume it's running
Linux and Apache, since most hosting companies do things that way, in
my experience.

   This is potentially the hardest setup, security-wise.  You're
looking at all data having to travel over a network connection, which
means it's inherently insecure, and you may not have full access to
the server.  If you've got access to either the firewall or the apache
config on the server, though, you can make it work.  There are two
options.

1) Firewall.  You can use the firewall (iptables, in my assumed
scenario) to restrict who can reach the server.  Find someone who
knows what they're doing to set this up, or you can lock yourself out
of the server really easily -- I've done it several times at work, and
it's always embarrassing.

2) Apache config.  You can set a particular subdirectory of your
Apache install -- or the whole thing! -- to only be accessible to
people from certain domains or IPs.  The way to do this is to use a
Deny all directive, followed by, say Allow .myclient.com or Allow
231.30.8.17 if that's your gateway. See
http://articles.techrepublic.com.com/5100-22_11-5076696.html for some
basic information -- look at the section with the header Restrict
access.  This is easier, but I'm not sure whether it's as secure.
Best, of course, would be to do both.  That way no one unauthorized
should be able to reach the server, but if they manage, it should
still lock them out.


   Now:  this all works the same for an internal server.  The only
difference really is that you're in full physical control, and you can
drop the whole thing behind a gateway firewall as well as the internal
firewall.  It is generally a good idea to let a server access the
internet, since that's the easiest way to download and install

Re: [PHP] Re: Bitwise NOT operator?

2010-08-25 Thread Andy McKenzie
On Wed, Aug 25, 2010 at 9:46 AM, Colin Guthrie gm...@colin.guthr.ie wrote:
 'Twas brillig, and Andy McKenzie at 24/08/10 21:42 did gyre and gimble:
 Even if I'd thought about it in terms of the architecture, I
 would have assumed that PHP would treat a two-bit number as a two-bit
 number

 You two-bit hustler!

 In all seriousness tho', where do you ever provide a two bit number?

 $n = 2;

 The above is a number, it's not implicitly a two bit number...

 I mean, if I do:

 $n = 2;
 $n += 2;

 What do I get then? $n == 0? That's what *should* happen if $n was
 indeed two bits. It would overflow and wrap around.

 Your number in $n is in fact represented by whatever the variable type
 is. In this case it's a 32 bit integer number.

 Col


You're right, of course:  internally, PHP has to treat every number as
being some specific number of bits.  My point was that, not knowing a
lot about the low-level systems and internals, it's easy to assume
that something I enter as two bits (or three, or four, or whatever)
will be treated as such and returned as such.

My background isn't computer architecture:  what little relevant
experience I've had was two years in an electrical engineering program
(I decided it wasn't for me, and got out), but I never looked at
computer system architecture.  Based on my background, I tend to think
of a string of bits as just that -- a string of bits, basically
disconnected from anything else.  Therefore, if I feed five bits into
a NOT gate, I should get five bits back, and they should be the
opposite of what I fed it.  ~(10110) = 01001.  What I do with it after
that is up to me.  Math is different, and may require adding extra
bits, but a NOT isn't a mathematical function in my mind, it's a
function performed one bit at a time on exactly what you feed it.

As Gary points out, there ARE languages and places where that's doable
-- I've used the bit-field tool he mentioned, I think, although it was
a long time ago in that EE program -- so I had some reason for my
(incorrect) assumption.

However:  As Peter says, this is all fairly pointless, and totally
unnecessary on this list.  Colin gave me a meaningful answer in his
first response, and we've strayed pretty far from the topic.  At this
point, I'm not going to convince anyone of my view, and no one else is
going to convince me more than they have of their view, so let's let
the thread die in peace.  If other people want to continue the
discussion, go for it, but I'm going to try to keep quiet. 8-)

Thanks again to everyone who chimed in, though -- I appreciate the help.

-Alex McKenzie

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



Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Andy McKenzie
On Tue, Aug 24, 2010 at 11:06 AM, Richard Quadling rquadl...@gmail.com wrote:
 On 20 August 2010 17:00, Andy McKenzie amckenz...@gmail.com wrote:
  Thanks to everyone who responded.  I've dealt with binary math
 before, but it never occurred to me (and doesn't seem to be anywhere
 in the document page at php.net!) that it would automatically pad the
 number I entered.

 There is no padding.

 php -r echo decbin(~2), PHP_EOL, decbin(-3);
 1101
 1101

 That's 100% correct and proper. Not padded.

 The example in [1] regarding E_ALL  ~E_NOTICE is a perfect example.

 Richard.

 [1] http://docs.php.net/manual/en/language.operators.bitwise.php
 --
 Richard Quadling.



If I feed it 10 and it assumes 0011,
it's padding the number with zeros.

From your example, this would have shown me what I needed to know:

Then taking the value of E_NOTICE...
1000
... and inverting it via ~:
0111

As it was, I assumed the 32-bit number was there because the author
wanted it there, not because PHP assumes those extra bits.  As other
people have said, it probably would have been obvious if I'd known
more about how the system dealt with binary numbers, but coming from
my background, it wasn't at all obvious.  Not a big deal, and I can
work with it now that I know what's going on, but it would have taken
me a long time to figure it out on my own, if I ever had.  The tests I
was doing probably would have led me to the right answer eventually,
but Colin's original answer gave me the explanation and the solution
much faster.

-Alex

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



Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Andy McKenzie
On Tue, Aug 24, 2010 at 3:55 PM, Ford, Mike m.f...@leedsmet.ac.uk wrote:
 -Original Message-
 From: Andy McKenzie [mailto:amckenz...@gmail.com]
 Sent: 24 August 2010 17:24
 To: php-general@lists.php.net
 Subject: Re: [PHP] Bitwise NOT operator?


 From your example, this would have shown me what I needed to know:

 Then taking the value of E_NOTICE...
 1000
 ... and inverting it via ~:
 0111

 As it was, I assumed the 32-bit number was there because the author
 wanted it there, not because PHP assumes those extra bits.

 That's not PHP. That's the underlying computer architecture, and PHP has no 
 choice in the matter. (Well, assuming you leave BCMath and so on out of the 
 equation!)

 Cheers!

 Mike


True, but largely irrelevant from my point of view:  I'm talking to
PHP.  Even if I'd thought about it in terms of the architecture, I
would have assumed that PHP would treat a two-bit number as a two-bit
number, even if it had to do some weirdness in the background because
it's not.  If I enter a decimal two, I know the computer deals with it
as binary, and now I know it probably deals with it as a 32-bit binary
number, but it doesn't show me all the extra bits:  it just shows me a
two.

My point here, much as it might sound like it, isn't that PHP is wrong
for doing things the way it does.  Even if I thought it is, I don't
know what I'm talking about, and I know it.  What I'm saying is that
the documentation doesn't even begin to indicate to people like me
that things won't work the way we expect.  Maybe that's not necessary;
certainly I've never needed it until now, and the confusion was easily
cleared up.  But adding to the docs might avoid a lot of confusion for
the next guy who doesn't really know what he's doing.

-Alex

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



[PHP] Bitwise NOT operator?

2010-08-20 Thread Andy McKenzie
Hey everyone,

  I'm really not sure what's going on here:  basically, the bitwise
NOT operator seems to simply not work.  Here's an example of what I
see.

Script

$ cat bintest2.php

?php

$bin = 2;
$notbin = ~$bin;

echo Bin:  . decbin($bin) .   !bin:   . decbin($notbin) . \n;
echo Bin: $bin  !bin:  $notbin\n;


?
=


Output

$ php bintest2.php
Bin: 10  !bin:  1101
Bin: 2  !bin:  -3

=


Obviously that's not the expected response.  I expect to get something
more like this:

Bin: 10  !bin:  01
Bin: 2  !bin:  1


Can anyone shed some light on this for me?  The server is running an
old version of OpenSUSE, and php --version returns:

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Dec 12 2007 03:51:56)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies


I get the same response on an Ubuntu 8.04 LTS server with PHP
5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2.

Thanks in advance,

  Alex McKenzie
  amckenz...@gmail.com

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



Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Andy McKenzie
  Thanks to everyone who responded.  I've dealt with binary math
before, but it never occurred to me (and doesn't seem to be anywhere
in the document page at php.net!) that it would automatically pad the
number I entered.

  The example I gave was essentially a test I was running:  in the
real script, I'm trying to calculate the number of IP addresses in a
given subnet, and I was getting some seriously weird results.  I'm
still not entirely sure what's going on, but this should help.

Thanks again!
-Alex


On Fri, Aug 20, 2010 at 11:42 AM, Peter Lind peter.e.l...@gmail.com wrote:
 On 20 August 2010 17:41, Peter Lind peter.e.l...@gmail.com wrote:
 On 20 August 2010 17:10, Andy McKenzie amckenz...@gmail.com wrote:
 Hey everyone,

  I'm really not sure what's going on here:  basically, the bitwise
 NOT operator seems to simply not work.  Here's an example of what I
 see.

 Script

 $ cat bintest2.php

 ?php

 $bin = 2;
 $notbin = ~$bin;

 echo Bin:  . decbin($bin) .   !bin:   . decbin($notbin) . \n;
 echo Bin: $bin  !bin:  $notbin\n;


 ?
 =


 Output

 $ php bintest2.php
 Bin: 10  !bin:  1101
 Bin: 2  !bin:  -3

 =


 Obviously that's not the expected response.  I expect to get something
 more like this:

 Bin: 10  !bin:  01
 Bin: 2  !bin:  1


 Can anyone shed some light on this for me?  The server is running an
 old version of OpenSUSE, and php --version returns:


 You probably need to read up on computer architechture and CS theory -
 the ~ operator works fine, your understanding does not. What you're
 looking at is the following:

 $bin = 2 = 0010 (64 bit number)

 32-bit number, as Colin pointed out.

 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