<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:series="http://unfoldingneurons.com/"
><channel><title>Larry Ullman &#187; security</title> <atom:link href="http://www.larryullman.com/tag/security/feed/" rel="self" type="application/rss+xml" /><link>http://www.larryullman.com</link> <description>Translating Geek Into English</description> <lastBuildDate>Sun, 05 Feb 2012 17:48:42 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>What is Larry Thinking? #50 =&gt; OOP Design, Part 1</title><link>http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/</link> <comments>http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#comments</comments> <pubDate>Mon, 30 Jan 2012 06:58:39 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[jsdd]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[oop]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2987</guid> <description><![CDATA[In this edition… What Were You Thinking? =&#62; Bimonthly Newsletters On the Web =&#62; Security and Privacy Made Simpler On the Blog =&#62; My January 2012 Non-Resolutions List Q&#38;A =&#62; How do you go about designing the main OOP classes for a project? Larry Ullman&#8217;s Book News =&#62; “Modern Javascript: Develop and Design” Done! What [...]]]></description> <content:encoded><![CDATA[<p>In this edition…</p><ul><li><a
href="http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#you">What Were You Thinking? =&gt; Bimonthly Newsletters</a></li><li><a
href="http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#web">On the Web =&gt; Security and Privacy Made Simpler</a></li><li><a
href="http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#web">On the Blog =&gt; My January 2012 Non-Resolutions List</a></li><li><a
href="http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#qa">Q&amp;A =&gt; How do you go about designing the main OOP classes for a project?</a></li><li><a
href="http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/#news">Larry Ullman&#8217;s Book News =&gt; “Modern Javascript: Develop and Design” Done!</a></li></ul><p><span
id="more-2987"></span></p><h2 id="you">What Were You Thinking? =&gt; Bimonthly Newsletters</h2><p>In <a
href="http://www.larryullman.com/2012/01/07/what-is-larry-thinking-49-a-new-year/#you">the previous newsletter</a>, I asked for input on the idea of changing the newsletter from going out every 3-4 weeks but being longer to going out every 2 weeks but being shorter. You were also able to vote in <a
href="http://www.larryullman.com/2012/01/06/newsletter-opinion-poll/">an online poll</a>. About two-thirds of the votes were for the change, although the more passionate responses were against the change, as those recipients already felt they received too many newsletters and emails. I think what I’m going to do, as a happy medium, is to shoot for a schedule where the newsletters come out slightly faster, like every 2-3 weeks, and are slightly shorter. This should be feasible for me to pull off without overwhelming you.</p><p>Towards that end, you may note that there’s no “What is Larry Thinking?” section in this particular newsletter. With the new plan for the newsletter, I’m not going to be quite so rigid about what goes into each newsletter, limiting myself to just five or so significant pieces. The bulk of this newsletter answers a question on OOP design.</p><p>My thanks to everyone for their input. And please always feel free to provide any feedback, questions, comments, etc., that you may have. (Postscript: Several of you rightfully pointed out that I misused “biweekly” in the text of the newsletter, despite correctly using “bimonthly” in the heading. I indeed meant “bimonthly”, although “biweekly” has the same inexactitude in that it can mean both every two weeks and twice a week.)</p><h2 id="web">On the Web =&gt; Security and Privacy Made Simpler</h2><p>When I was writing my <a
href="http://www.larryullman.com/books/effortless-e-commerce-with-php-and-mysql/">Effortless E-Commerce with PHP and MySQL</a> book, I naturally did a bunch of research, particularly with regards to the various laws that apply. Understanding the programming behind an e-commerce site is relatively simple; understanding all the applicable laws and implications of doing e-commerce is complex. One of the sites I found to be quite useful was the United States <a
href="http://www.bbb.org/">Better Business Bureau</a> (BBB).</p><p>I’m currently going through some items in my “to read” folder, and am reading, or perhaps re-reading, the Better Business Bureau’s PDF titled “<a
href="http://www.bbb.org/us/corporate-engagement/security/">Security &amp; Privacy – Made Simpler</a>. If you do any e-commerce, or even just Web development, in the U.S. or not, it’s worth your time. It’s a 22-page document that discusses almost every facet of e-commerce, such as:</p><ul><li>Developing a security and privacy plan</li><li>Creating and communicating your security and privacy policies</li><li>Good employee screening and policies</li><li>Common hack/theft strategies</li><li>General Internet security</li><li>Proper handling of customer data</li><li>Payment processing</li><li>What to do in the event of a data breach</li><li>A preview of international e-commerce considerations</li></ul><p>The document also has many resources listed in these and other categories. You can download the PDF from that page, but there are also related FAQs and more on the BBB’s site.</p><h2 id="blog">On the Blog =&gt; My January 2012 Non-Resolutions List</h2><p>I’ve never been much of a New Year’s Resolution person: if something is important enough to do, start today, not on some arbitrary date that happens to be the first day of the year. (Or, you know, January 2nd, because the first is a holiday and all.) But this year I happen to have quite a long non-resolutions list. The timing is entirely coincidental: I just happen to be done with my “Modern JavaScript: Develop and Design” book around this time, and I always have a long list of things to do between books. I recently <a
href="http://www.larryullman.com/2012/01/03/my-january-2012-non-resolutions-list/">posted on my blog</a> about my immediate plans (aka, my non-resolutions list).</p><h2 id="qa">Q&amp;A =&gt; How do you go about designing the main OOP classes for a project?</h2><p>While “diving into” Object-Oriented Programming development in PHP, Chris had emailed me about how one sets up the core classes for an OOP-based site. The specific example—user management with login/logout, roles, etc.—is common and not complex, but Chris didn’t know where to start. In my opinion, OOP is easy enough to <em>use</em> once the classes have been defined; the difficulties arise from coming up with the proper classes in the first place. So let’s look at that process, in the abstract.</p><p><em>Programming is a matter of taking actions with data.</em> In a linguistic sense, it’s very much a noun-verb relationship: the user submits form data to a server; the server stores data in a database; the user requests another page; the server pulls data from a database. Whether you’re using OOP or procedural code, you need to identify both the actions and the data first. What are all the <em>verbs</em> that the user or Web site needs to be able to do? What are all the <em>nouns</em> that will be involved in those actions? Once you’ve identified those attributes of the site, procedural programming focuses first on the verbs, OOP focuses first on the nouns.</p><p>To start designing OOP classes, one must first organize the types of data the site will work with, in detail. In a user management system, there’s one obvious noun: a <strong>User</strong>. The properties of a User include: userId, username, userPass, userRole, dateRegistered, and so forth. (Conventionally, OOP uses camel-case for variable and property names.) When you think you’ve identified the nouns involved, go back and see if all of the actions now have the data that needs to be involved. When a new person registers, a User is created (as both a PHP variable and a record in the database). When a person logs in, a User is retrieved from the database and created as a PHP variable. When a person logs out, the User PHP variable can be destroyed. To see if a person has authority to do X, you’d check the <strong>User-&gt;userRole</strong> property.</p><p>In some situations, there will be nouns with overlapping roles and properties, which would suggest that you should create a hierarchy of classes. I think of shapes as being the easiest example to comprehend. All two-dimensional shapes have some common attributes, such as area and perimeter, but triangles have three sides, rectangles have four, and circles have none (but do have a radius). When you find yourself in situations like this, you’ll want to design one master class, in this case, <strong>Shape</strong>, which you never create instances of. Then you define derived classes—<strong>Triangle</strong>, <strong>Rectangle</strong>, and <strong>Circle</strong>—that you would create instances of. Admittedly, knowing when to create a hierarchy can be tough. You might think with a user roles situation that you’d want common users and administrators as two separate classes, but the only difference between the two types is in what actions each can take, which is easily managed using Access Control Lists (ACLs) or the like. Or, put another way, everything about the two users is exactly the same except for the type, so there’s no need to create separate classes (unlike, by comparison, circles and triangles that have some overlapping properties but other very different ones).</p><p>Another common class to use on a site would be one for interacting with the database. You could create your own class for this purpose, or just use the <a
href="http://www.php.net/mysqli">MySQLi object</a> or <a
href="http://www.php.net/pdo">PDO</a> or the like.</p><p>Even in a simple site with content and users, there are other clear nouns: the pages of content. Going back to the language analogy, there are some sentences that have a single noun—<em>Johnny runs</em> or <em>A User logs out</em>—but many have more than one noun—<em>Johnny reads a book</em> or <em>A User views a page of content</em>. The content, then, would also be represented by one or more classes, depending upon the variety in the content displayed. If the content is just information displayed within a template of HTML, then <strong>Content</strong> might have these attributes: contentId, title, body, createdBy, dateCreated, and dateUpdated. The createdBy could be as simple as a userID integer, or more formally be an actual User instance.</p><p>Depending upon how OOP-y you want to be, you may also create classes for generating the HTML pages (i.e., View classes) and for handling actions (i.e., Controller classes). Those move you into the realm of a true MVC architecture, which isn’t always necessary, though.</p><p>In asking the question, Chris didn’t originally know how to handle the logging in and logging out and registration and such, not knowing if one makes classes for those. Those are actions performed on, or using, objects, and don’t get represented as classes themselves.</p><p>Because I’m going to be writing the third edition of my “<a
href="http://www.larryullman.com/books/php-5-advanced-visual-quickpro-guide-2nd-edition/">PHP 5 Advanced: Visual QuickPro Guide</a>” this year, I expect I’ll be doing a lot of writing on the subject of OOP, design patterns, and the like. If anyone has any more questions or comments regarding these topics, let me know.</p><h2 id="news">Larry Ullman’s Book News =&gt; “Modern Javascript: Develop and Design” Done!</h2><p>I am very, very happy to say that my latest book, “Modern JavaScript: Develop and Design”, is officially done. Like done, done. Last week Monday, I submitted the last chapter to be written, Chapter 13, Frameworks. In it, I quickly discuss how to choose a framework, when you should use a framework, and some common libraries (as a framework alternative). The bulk of the chapter introduces and uses <a
href="http://jquery.com/">jQuery</a> and the <a
href="http://yuilibrary.com/">Yahoo! User Interface (YUI) Library</a>. For both I explain how to perform common tasks—selecting DOM elements, DOM manipulation, event handling, and Ajax, and then walk through more advanced examples. For both, the chapter explains an autocomplete example, using a PHP script as the data source. For jQuery, I also discuss the <a
href="http://datatables.net/">DataTables</a> plug-in. For YUI, I also discuss and demonstrate the <a
href="http://developer.yahoo.com/yql/">Yahoo! Query Language</a> (YQL). For it, I go through a couple of examples, including fetching a weather report and a stock quote. (For the record, I specifically target YUI3, which is an improvement over YUI1 and 2, even if some of the framework is currently in beta.)</p><p>Chapter 13 is the first chapter in Part 3 of the book, Next Steps. I already wrote Chapter 14, Advanced JavaScript, which has a heavy focus on closures. Chapter 15, A PHP and JavaScript Example, creates a pseudo-complete auction system. Auctions are set to expire on a certain date and time. Logged-in users can bid on items. All dates and times are shown using Coordinated Universal Time (UTC) or the user’s timezone, if the user is logged-in. Then, JavaScript used to enhance the experience. This includes using Ajax for the login and bid forms, retrieving the latest bids via Ajax (and updating the table of bids with them), and creating countdown timers that show the amount of time left in an auction, when that’s less than an hour. I think the chapter turned out well, and it emphasizes the various ways to pass data back and forth between PHP and JavaScript, a common point of confusion.</p><p>Not only is all of the initial writing is complete, but I’ve also done the rewrites on the entire book, and I just—moments ago—finished reviewing the PDF layouts, which is the last step before the book goes to the printer. (As you can tell, there are a lot of overlapping steps here at the end.) I believe the book will still ship, as originally planned, at the end of February.</p><p>In support of the book, I’ll also be writing a couple of articles (published online for free) and create some screencasts (to be provided in various places).</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/01/30/what-is-larry-thinking-50-oop-design-part-1/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Security &amp; Privacy Made Simpler</title><link>http://www.larryullman.com/2011/12/24/security-privacy-made-simpler/</link> <comments>http://www.larryullman.com/2011/12/24/security-privacy-made-simpler/#comments</comments> <pubDate>Sat, 24 Dec 2011 15:42:04 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[e-commerce]]></category> <category><![CDATA[ecom]]></category> <category><![CDATA[ecommerce]]></category> <category><![CDATA[privacy]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2931</guid> <description><![CDATA[When I was writing my book, I naturally did a bunch of research, particularly with regards to the various laws that apply. Understanding the programming behind an e-commerce site is relatively simple; understanding all the applicable laws and implications of doing e-commerce is complex. One of the sites I found to be quite useful was the U.S. [...]]]></description> <content:encoded><![CDATA[<p>When I was writing my <em></em><a
href="http://www.larryullman.com/books/effortless-e-commerce-with-php-and-mysql/">Effortless E-Commerce with PHP and MySQL</a> book, I naturally did a bunch of research, particularly with regards to the various laws that apply. Understanding the programming behind an e-commerce site is relatively simple; understanding all the applicable laws and implications of doing e-commerce is complex. One of the sites I found to be quite useful was the U.S. <a
href="http://www.bbb.org">Better Business Bureau</a> (BBB).</p><p>I&#8217;m currently going through some items in my &#8220;to read&#8221; folder, and am reading, or perhaps re-reading, the Better Business Bureau&#8217;s PDF titled &#8220;<a
href="http://www.bbb.org/us/corporate-engagement/security/">Security &amp; Privacy &#8211; Made Simpler</a>&#8220;. If you do any e-commerce, or even just Web development, it&#8217;s worth reading. It&#8217;s a 22-page document that discusses almost every facet of e-commerce, such as:</p><ul><li>Developing a security and privacy plan</li><li>Creating and communicating your security and privacy policies</li><li>Good employee screening and policies</li><li>Common hack/theft strategies</li><li>General Internet security</li><li>Proper handling of customer data</li><li>Payment processing</li><li>What to do in the event of a data breach</li><li>A preview of international e-commerce considerations</li></ul><p>The document also has many resources listed in these and other categories. You can download the PDF from that page, but there are also related FAQs and more on the BBB&#8217;s site.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/12/24/security-privacy-made-simpler/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>What Is Larry Thinking? #46 =&gt; JavaScript, Sexism, and Bad User Interface</title><link>http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/</link> <comments>http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#comments</comments> <pubDate>Fri, 21 Oct 2011 05:22:00 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[Amazon]]></category> <category><![CDATA[apple]]></category> <category><![CDATA[books]]></category> <category><![CDATA[file]]></category> <category><![CDATA[jsdd]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[permissions]]></category> <category><![CDATA[security]]></category> <category><![CDATA[silk]]></category> <category><![CDATA[ui]]></category> <category><![CDATA[user interface]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2845</guid> <description><![CDATA[In this edition… About This Newsletter What Are You Thinking? =&#62; Using JavaScript On the Web =&#62; Amazon Silk: A New Mobile Browser On the Web =&#62; Steve Jobs and Dennis Ritchie, in Memoriam On the Blog =&#62; Why There Are Few (No?) Good JavaScript Books Q&#38;A =&#62; Could You Explain File Permissions? What is [...]]]></description> <content:encoded><![CDATA[<p> In this edition…</p><ul><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#about">About This Newsletter</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#you">What Are You Thinking? =&gt; Using JavaScript</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#web1">On the Web =&gt; Amazon Silk: A New Mobile Browser</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#web2">On the Web =&gt; Steve Jobs and Dennis Ritchie, in Memoriam</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#blog">On the Blog =&gt; Why There Are Few (No?) Good JavaScript Books</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#qa">Q&amp;A =&gt; Could You Explain File Permissions?</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#thinking">What is Larry Thinking =&gt; Sexism and Bad User Interface</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#giveaway">Book Giveaway =&gt; &#8220;PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide&#8221; (4th Edition)</a></li><li><a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#news">Larry Ullman&#8217;s Book News =&gt; &#8220;Modern JavaScript: Develop and Design&#8221;</a></li></ul><p> <span
id="more-2845"></span></p><h2 id="about">About This Newsletter</h2><p>Life is busy here and I&rsquo;m well behind schedule on all fronts, so this newsletter is getting out about a week to ten days late. I&rsquo;m taking consolation in the fact that I&rsquo;ve kept pretty close to a three-week schedule for the past year (about 15 newsletters sent in that time). Rather than blather on, let’s get on with the show!</p><p>As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!</p><h2 id="you">What Are You Thinking? =&gt; Using JavaScript</h2><p>So I&rsquo;m working on my next book, &ldquo;Modern JavaScript: Develop and Design.&rdquo; As I write about in a blog post (also mentioned later in this newsletter), JavaScript is kind of a tricky language to write a book about, as a lot of information is required just to do a basic thing such as form validation. Like any of my books, I&rsquo;m working hard to use lots of good, real-world examples to demonstrate the new information being taught. Thus far, with two real code chapters in the bank, most examples are based upon form validation and data manipulation. These are obviously crucial uses of JavaScript, and good ways to practice some of the early material. Some readers have let me know that they&rsquo;re hoping to see lots and lots of examples, so I thought I&rsquo;d go ahead and send a direct request out asking what, if any, specific examples or topics you&rsquo;d like to see in the book. What do you know you need to use JavaScript for? What are you curious about? What have you seen that you know is confusing to you and you&rsquo;d like clarification on?</p><p>All thoughts and suggestions are welcome and very much appreciated. As an incentive, I&rsquo;ll go ahead and give away ten copies of &ldquo;Modern JavaScript: Develop and Design&rdquo; to people with the best responses.</p><h2 id="web1">On the Web =&gt; Amazon Silk: A New Mobile Browser</h2><p>As you may have seen, <a
href="http://www.amazon.com/?tag=larrullm09-20">Amazon</a> announced their new lineup of Kindles recently, from the <a
href="http://amzn.to/qQREgw">$79 base version</a> to the <a
href="http://amzn.to/oZyxhk">$199 Kindle Fire</a>, a rival to Apple&rsquo;s iPad. One thing that piqued my interest about the Kindle Fire is that it includes a new, custom Web browser, named <a
href="http://amazonsilk.wordpress.com/">Silk</a>. Amazon posted <a
href="http://amazonsilk.wordpress.com/2011/09/28/introducing-amazon-silk/">an introduction to Silk</a>, along with a six-minute video, on their site, too. A lot on that page and in the video is marketing hype, but they raise some interesting points about the fact that Web browsers are fundamentally the same as they were 15 years ago, and aren&rsquo;t ideal for today&rsquo;s use, especially with all the mobile devices. Now the solution they came up with seems to be something akin to a reverse CDN: Whereas a CDN takes the load off of one server and shares it across a network of servers, Amazon Silk uses Amazon Web Services (AWS) to reduce the load on the device. From just what I&rsquo;ve seen, it doesn&rsquo;t seem like they&rsquo;ve addressed a problem with browsers, but rather with the HTTP protocol, introducing their own gateway to improve the communications. It&rsquo;ll be interesting to see what impact this new approach has, and how, if at all, it affects Web development in the years to come.</p><h2 id="web2">On the Web =&gt; Steve Jobs and Dennis Ritchie, in Memoriam</h2><p>As I&rsquo;m sure you&rsquo;re all aware, Steve Jobs, one of the founders of Apple, passed away just recently. You may also know that I&rsquo;m a pretty big fan of Apple. I first learned to program Basic on an Apple IIe, the first computer I purchased was a Macintosh Color Classic, and I&rsquo;m probably on my 10th or 12th Mac by now. I&rsquo;m not saying Macs are better than PCs, and they&rsquo;re certainly not cheaper, but I definitely prefer them. A lot has been said and written about Jobs since his passing, such that I have little to add, except I would offer that I what I think was the most brilliant thing that happened during Jobs&rsquo;s tenure was the ability to get non-Mac people to buy Apple products. For decades, if you purchased an Apple product, you were buying either a Mac or Apple software to run on a Mac. This accounted for at best about 5% of the computing population. Thanks to the iPod, iPhone, and iPad, almost all computer users and a majority of mobile phone users have one or more Apple products, whether or not they ever bought an Apple computer (and many of these people have since started buying Macs, too). Just brilliant, and the clear reason why Apple has become one of the most valuable companies in the world. Had you told me 15 years ago that Apple would become a dominant computer company and Bill Gates a prominent philanthropist, I wouldn&rsquo;t have believed you.</p><p>Jobs&rsquo;s other huge success was with Pixar, although he probably had less directly to do with Pixar&rsquo;s success than the brilliant talents employed there. Jobs purchased what became Pixar from George Lucas, helped build it up, and when Pixar was purchased by Disney, Jobs became the single largest shareholder of Walt Disney. Quite the life. If you&rsquo;d like one more little blip about Jobs, check out his <a
href="http://www.youtube.com/watch?v=D1R-jKKp3NA">Stanford commencement address</a> from 2005. In it, Jobs talks candidly about work, life, and death.</p><p>Days after Steve Jobs passed away, <a
href="http://www.nytimes.com/2011/10/14/technology/dennis-ritchie-programming-trailblazer-dies-at-70.html">Dennis Ritchie</a> died, garnering much, much less media attention. Dennis Ritchie arguably had a bigger impact on computing and the world than Jobs, but is no household name. If you&rsquo;re not familiar with Ritchie, all he did was create the C programming language, and helped develop the Unix operating system. C is one of the most important programming languages of all time. It has greatly influenced many other languages, and is still used widely today. In fact, PHP, Python, and Perl are all written in C! Unix, and its inspired variants such as Linux, is running most of the Internet, along with Apple&rsquo;s iOS devices, Tivo&rsquo;s, and many other devices.</p><h2 id="blog">On the Blog =&gt; Why There Are Few (No?) Good JavaScript Books</h2><p>Just yesterday, I <a
href="http://www.larryullman.com/2011/10/18/why-there-are-few-no-good-javascript-books/">posted a blog article</a> discussing my thoughts on why there are so few good JavaScript books. In part this post stems from time spent skimming through other JavaScript books and thinking &ldquo;Really, you&rsquo;re doing that in this book?&rdquo; And, in part, in formally writing a JavaScript book now myself, I&rsquo;m aware of some of the unique challenges that JavaScript poses for writers.</p><h2 id="qa">Q&amp;A =&gt; Could You Explain File Permissions?</h2><p>File permissions and file paths are probably two of the things that I get the most questions on, and that beginners are most often confused about. Some time back, Martin had asked if I&rsquo;d explain file permissions, and even though a previous newsletter <a
href="http://www.larryullman.com/2011/01/06/what-is-larry-thinking-35-securing-content-and-more/#qa1">touched upon the subject</a>, it&rsquo;s worth going into again and in more detail. For a couple of reasons, I&rsquo;m going to ignore Windows permissions and focus on *nix, which includes Unix, Linux, and Mac OS X. First, all these operating systems share the same permissions scheme. Second, statistically, most Web servers are running one of these operating systems. Third, permissions in Windows rarely need to be altered or cause problems, in my experience. And, fourth, you&rsquo;re much more likely to be confused by *nix permissions, which are as follows…</p><p>File and folder permissions are an operating system&rsquo;s way of dictating who can do what to that file or folder. There are three permissions that can be granted or denied: <em>read</em>, <em>write</em>, and <em>execute</em>. For files, read means the ability to literally open and read the file; write means the ability to modify the file; and execute means the ability to run the file (e.g., as an executable or a script). For directories, read means the ability to see the names of the files in the directory; write means the ability to modify the directory (such as create, rename, or delete files and folders therein); and execute means the ability to traverse the directory (i.e., be able to go into it). You&rsquo;ll see these permissions represented by both letters—r, w, and x—and octal (base-8) numbers: 4 (read), 2 (write), and 1 (execute). These numeric values correspond to bits, meaning that different sums from 0 to 7 represent unique permission combinations. For example, 5 has to be read plus execute; 6 has to be read plus write; and, 7 is all three (5, 6, and 7 are the most common permissions digits you&rsquo;ll see).</p><p>Now for every file and folder, these permissions can be set for three types of users: the owner, the owner&rsquo;s group, and everyone. For example, on a Web server, you may have an account under the username <em>trout</em>. Your username will also be associated with a group, such as <em>clients</em>. Other people with accounts on the same server will have different usernames but may be part of the same group. There will also be other groups, such as <em>staff</em> or <em>mysql</em>. The permissions on any file or folder can be set as three octal digits, where the first digit represents the owner&rsquo;s permissions, the second represents the owner&rsquo;s group&rsquo;s permissions (i.e., the permissions for other people in that group), and the third digit represents the permissions for everyone else. 644 permissions mean that you can read from and write to that file or folder, while everyone else can only read from it. Written using letters instead of octal numbers, you&rsquo;ll see a file or folder&rsquo;s permissions represented using 10 characters: the first reflects other details about the file or folder (I won&rsquo;t get into that here); the next three are for the owner&rsquo;s read, write, and execute permissions; the next three for the owner&rsquo;s group&rsquo;s read, write, and execute permissions; and the last three for everyone&rsquo;s. Thus, the octal 644 becomes -rw-r&#8211;r&#8211;. The octal 755 is -rwxr-xr-x.</p><p>So there are the basics and the hieroglyphics you&rsquo;ll occasionally see; what does this mean in actual application? For starters, you need to understand that the third category—everyone else—means everyone else <em>on the computer</em>, not everyone else in the universe. For example, if you create a directory with open permissions—777 or -rwxrwxrwx, that doesn&rsquo;t mean anyone with an Internet connection can modify that directory&rsquo;s contents. No. You can only modify a directory&rsquo;s contents if you have access to the server&rsquo;s file system, which means you&rsquo;ve connected to the server via FTP or command line (SSH, telnet) access. And that kind of access requires using an account recognized by the server. But what about loading a Web page in the browser? Well, that is a type of server access, but not <em>file system access</em>. When a user goes to a Web site in the browser, the user isn&rsquo;t interfacing with the server&rsquo;s file system, but actually with the Web server software, such as Apache. Apache then does the actual accessing of the file system. So don&rsquo;t fret that assigning open permissions to a file or directory means that anyone in the universe has access. That&rsquo;s not the case.</p><p>But it is the case that an open file or directory on the server is accessible by any valid user on that server, assuming that other restrictions are not in place and that the user knows about its existence. For examples of restrictions, PHP can easily be limited as to which directories it can access and which it cannot. The same goes for Apache. In fact, the biggest security concern isn&rsquo;t that <em>people</em> can access and manipulate your files and folders, but rather that <em>software running on the server can</em>. And this is where you have to be careful. Many hacks take advantage of security holes in scripts or applications to make Apache and PHP—the software already running on the server—do something malicious. All things considered, this doesn&rsquo;t mean you should be cavalier about assigning open permissions, but it does mean that it&rsquo;s not out-and-out irresponsible to use them when needed. Speaking of which…</p><p>The last real-world issue you&rsquo;ll come across, which is a big complication for many, is establishing the correct permissions to allow for file uploads, or for PHP to write a text file, and the like. When you upload files to the server using FTP, or even create a directory using FTP, the owner of the uploaded file or folder will be you. The PHP script that needs to write to that text file or directory (in this case, &ldquo;write&rdquo; means to modify the directory by moving a file into it), will be running as a different user, namely the user that the Web server software (e.g., Apache) is running as (Apache commonly runs as &ldquo;nobody&rdquo;). In order for PHP to do what it needs to do, permissions need to be modified so that the Apache user can write to it. Normally this means using 755 as the permissions.</p><p>If you do need to create open directories and files, there are ways you can improve the security of using them, most of which I highlighted <a
href="http://www.larryullman.com/2011/01/06/what-is-larry-thinking-35-securing-content-and-more/#qa1">in that previous newsletter</a>. For starters, always try to put these directories outside of the Web root directory, and then use a <a
href="http://www.larryullman.com/2011/01/06/what-is-larry-thinking-35-securing-content-and-more/#thinking">proxy script</a> to safely fetch the contents. By doing so, you&rsquo;re able to mitigate the increased security risk of having open directories and files by adding a layer of protection against accessing the content therein.</p><h2 id="thinking">What is Larry Thinking? =&gt; Sexism and Bad User Interface</h2><p>About fifteen years ago, when I was working at Borders bookstores (RIP), a co-worker got married. Afterward, she was talking one day about how she had gone into her bank to add her new husband to her account. The bank added her husband to the account and let her know that her husband would have to come in and authorize her before she could access the account herself. Wait, what? Yes, she went in, added her husband, and was no longer able to use the account that only moments earlier had been hers. This is because the bank&rsquo;s policy was for men to be the primary account holders. As soon as her husband was added to the account, it became his account. This is just a lovely bit of institutional sexism, I think, especially when you consider that I&rsquo;m talking about the mid-1990&rsquo;s here, not 1950! I do not know what happened beyond that—I would hope she&rsquo;d change banks, but beyond the sexism, it amazed me that a system was in place in which a person has the power to disempower themselves. A very strange concept.</p><p>My wife works in the field of education, which in the United States is known for many things, among them having broad, institutional dictums imposed upon schools and faculty. A frequent cause of problems is the software people are forced to use. Having software forced upon you is a hazard all employees face, but given the situation of public schools, such software is inevitably created under the worst of all possible situations:</p><ul><li>The software needs are identified by a committee of people, none of whom will actually be using the software.</li><li>Undoubtedly a requirement is that the software can run on old, outdated computers.</li><li>The budget will be tight.</li></ul><p>Take these three things together, and you can plan on getting software that takes way too long to complete, that will be outdated and impractical upon its released, and that will be used for far too long from there. This sounds jaded, perhaps, and I&rsquo;m certainly exaggerating some, but this is essentially the situation the American education system, if not the entire American government, is in when it comes to developing custom software.</p><p>The reason I&rsquo;m thinking about this now, is that my wife was using one of these less-than-ideal applications the other day. The application itself is kind of like project management software and she was responsible for maintaining a project&rsquo;s particulars through this system. Due to a lack of good documentation, she had misidentified her role on the project (within the system) and went back in to change her role. She selected what she thought was the right role for her account on that project and ended up removing her own administrative ability to manage the project. In other words, she locked herself out, and she was ostensibly the project manager! Again, why would someone create the ability for an administrator to de-administer themselves? And, what&rsquo;s worse, absolutely no warning was given to my wife (i.e., the user) that this would be a consequence of the action about to be taken.</p><p>By comparison, my role on a project was just turned over to someone else, and part of that project involved making use of Amazon&rsquo;s resources. Amazon, which I feel generally does everything right, did not allow me, the administrator, to just remove my name and email address from the system, thereby shutting out anyone&rsquo;s access. Instead, to make the switch from me to this other person, I had to add her to the system and give her administrative access. She, then, could go in and remove my administrative access. Was this a bit more complicated? Yes. But it was the right way to handle this scenario and it worked without problem.</p><p>This, then, is a call to you: the next time you&rsquo;re working on a Web site or application, think about the user interface and make sure it makes logical sense. Write the functionality so that administrators cannot disable their own access to the system. And include great documentation, and provide many, clear warnings when actions are about to be taken that are permanent. Oh, and if you&rsquo;re running a bank, how about letting a person know that she is about to be blocked out of her own account? Or, you know, just make your policies less sexist.</p><h2 id="giveaway">Book Giveaway =&gt; &#8220;PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide&#8221; (4th Edition)</h2><p>As I expected, there was a wonderful response to my &ldquo;PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide&rdquo; (4th edition) giveaway. Unfortunately, I haven&rsquo;t yet had the time to respond to everyone, or really anyone. For this I apologize, and I hope to do that within the week. So if you wrote in hoping for a book, rest assured that just because you haven&rsquo;t heard from me yet means you won&rsquo;t be getting a copy (conversely, it doesn&rsquo;t mean you necessarily will, either). What really happened is that I&rsquo;m just swamped. Apologies again!</p><p>I&rsquo;ll be able to give away a few more copies of this book in a future newsletter.</p><h2 id="news">Larry Ullman&#8217;s Book News =&gt; &#8220;Modern JavaScript: Develop and Design&#8221;</h2><p>I just submitted Chapter 5 of &ldquo;Modern JavaScript: Develop and Design&rdquo;, which means I&rsquo;m about 30% done with the first draft (well, first submitted draft: there are multiple internal drafts prior to that). Progress is going more slowly than I&rsquo;d like, but I&rsquo;ve had sick kids and other personal issues making it harder to get to work. I always hope I&rsquo;m about to turn a corner and speed up. One of these days, I will!</p><p>The first three chapters cover Part 1 of the book, which represents the fundamentals of JavaScript. Chapter 1 is a bit of an introduction to JavaScript overall. Chapter 2 provides a sneak peak at how JavaScript is used in a Web browser. Chapter 3 discusses and demonstrates several tools you&rsquo;ll want to use.</p><p>The second part of the book is the heart of JavaScript as a true programming language. Chapter 4 covers simple data types (numbers, strings, and Booleans). Chapter 5 is on control structures: conditionals and loops. Now I&rsquo;m turning to the fun stuff, and the topics that differentiate JavaScript from other languages. This includes objects (Chapter 6), functions (Chapter 7), events (Chapter 8), and the browser (Chapter 9). Hopefully by the next newsletter I&rsquo;ll have those four chapters written. Hopefully!</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Using Cookies in the Yii Framework</title><link>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/</link> <comments>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/#comments</comments> <pubDate>Sat, 04 Jun 2011 14:28:06 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[cookie]]></category> <category><![CDATA[csrf]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[security]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2552</guid> <description><![CDATA[In a previous post, I wrote about . In this one, I&#8217;ll look at using cookies. Neither is that difficult, but as with all things regarding frameworks, the solution may not be obvious at first. And there are some ways to make use cookies in Yii in a more secure manner.To create a cookie in [...]]]></description> <content:encoded><![CDATA[<p>In a previous post, I wrote about <a
href="http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/">using sessions in Yii-based sites</a>. In this one, I&#8217;ll look at using cookies. Neither is that difficult, but as with all things regarding frameworks, the solution may not be obvious at first. And there are some ways to make use cookies in Yii in a more secure manner.<span
id="more-2552"></span>To create a cookie in PHP without using a framework, you just call the <a
href="http://us.php.net/setcookie">setcookie()</a> function. To create a cookie while using the Yii framework, you don&#8217;t use <strong>setcookie()</strong>, but rather create a new element in the <strong>Yii::app()-&gt;request-&gt;cookies</strong> array. (Note that sessions are stored in <strong>Yii::app()-&gt;session</strong>, but cookies are in <strong>Yii::app()-&gt;request-&gt;cookies</strong>, because cookies are part of the HTTP request a browser makes of a Web server).</p><p>What you&#8217;ll want to do to create a cookie is create a new object of type <a
href="http://www.yiiframework.com/doc/api/1.1/CHttpCookie/">CHttpCookie</a>: Yii&#8217;s class for cookies. Here, then, is the syntax for setting a cookie in Yii:</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies['name'] = new CHttpCookie('name', 'value');</pre><p>You must use the same <em>name</em> value in both places, replacing it with the actual cookie name. Remember that the cookie&#8217;s name, and value, are visible to users in their browsers, so one ought to be prudent about what name you use and be extra mindful of what values are being stored.</p><blockquote><p>Tip: Because the cookie&#8217;s name must be used twice in the code, you may want to consider assigning the cookie&#8217;s name to a variable that is used in both instances instead.</p></blockquote><p>Once you&#8217;ve created a cookie, you can access it (on subsequent pages, because cookies are never immediately available to the page that set them), using <strong>Yii::app()-&gt;request-&gt;cookies['name']-&gt;value</strong>. You have to use the extra <strong>-&gt;value</strong> part, because the &#8220;cookie&#8221; being created is actually an object of type <strong>CHttpCookie</strong> (and Yii, internally, takes care of actually sending the cookie to the browser and reading the received cookie from the browser).</p><p>To test if a cookie exists, just use <strong>isset()</strong> on <strong>Yii::app()-&gt;request-&gt;cookies['name']</strong>, as you would any other variable.</p><p>To delete an existing cookie, just unset the element as you would any array element:</p><pre class="brush: php; title: ; notranslate">unset(Yii::app()-&gt;request-&gt;cookies['name']);</pre><p>To delete all existing cookies (for that site), use</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies-&gt;clear();</pre><p>By default, cookies will be set to expire when the browser window is closed. To change that, you need to modify the properties of the cookie. You can&#8217;t do so when you create the <strong>CHttpCookie</strong> object (i.e., the only arguments to the constructor are the cookie&#8217;s name and value), so you must separately create a new object of type <strong>CHttpCookie</strong>, to be assigned to <strong>Yii::app()-&gt;request-&gt;cookies</strong> later:</p><pre class="brush: php; title: ; notranslate">$cookie = new CHttpCookie('name', 'value');</pre><p>Then adjust the <strong>expire</strong> attribute:</p><pre class="brush: php; title: ; notranslate">$cookie-&gt;expire = time() + (60*60*24); // 24 hours</pre><p>Then add the cookie to the application:</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies['name'] = $cookie;</pre><p>You can manipulate other cookie properties using the above syntax: <strong>domain</strong>, <strong>httpOnly</strong>, <strong>path</strong>, and <strong>secure</strong>. Each of these correspond to the arguments to the <strong>setcookie()</strong> function. (You can also manipulate the value of the cookie through <strong>$cookie-&gt;value</strong> and the cookie&#8217;s name through <strong>$cookie-&gt;name</strong>). For example, if you want to limit a cookie to a specific domain, or subdomain, use <strong>domain</strong>; to limit it to a specific folder, use <strong>path</strong>; and to only transmit the cookie over SSL, set <strong>secure</strong> to <strong>true</strong>.</p><p>You can also improve the security of your cookies by setting Yii&#8217;s <strong>enableCookieValidation</strong> to <strong>true</strong>, in the Yii configuration file:</p><pre class="brush: php; title: ; notranslate">return array(
    'components'=&gt;array(
        'request'=&gt;array(
            'enableCookieValidation'=&gt;true,
        ),
    ),
);</pre><p>Cookie validation prevents cookies from being manipulated in the browser. To accomplish that, Yii stores a hashed representation of the cookie&#8217;s value when it gets sent, and then compares the received cookie&#8217;s value to ensure they are the same. Obviously there&#8217;s extra overhead required to do this, but in some instances, the extra effort is justified by the extra security.</p><p>Finally, one good reason to use cookies in a Yii-based site, even if the site is otherwise using sessions, is to prevent <a
href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-site Request Forgery (CSRF)</a> attacks. A CSRF works like this: malicious site A has some code on it, such as an image tag whose <strong>src</strong> attribute points to a page on site B that does something meaningful: <em>http://www.example.com/page.php?action=this</em>. When any viewer loads the page on site A, the use of that <strong>src</strong> attribute has the effect of that user performing a request of the page on site B.</p><p>As an example, let&#8217;s say that an administrator at your site logs in and does whatever but doesn&#8217;t log out. The administrator therefore still has a cookie in her or his browser indicating access to the site (i.e., the user could open the browser and perform admin tasks without logging in again). Now let&#8217;s say that the <strong>src</strong> attribute on malicious site A points to a page on your site that deletes a blog posting. If the administrator with the live cookie loads that page on site A, it will have the same effect as if that administrator went to your site and requested that page directly. This is not good.</p><p>To prevent a CSRF attack on your site, first make sure that all significant form submissions use POST instead of GET. You should be using POST for any form that changes server content anyway, but a CSRF POST attack is a bit harder to pull off than a GET attack.</p><p>Second, set <strong>enableCsrfValidation</strong> to <strong>true</strong> in your configuration file:</p><pre class="brush: php; title: ; notranslate">return array(
    'components'=&gt;array(
        'request'=&gt;array(
            'enableCsrfValidation'=&gt;true,
        ),
    ),
);</pre><p>By doing this, Yii will send a cookie with a unique identifier to the user. All forms will then store that same identifier in a hidden input. The form submission will only be handled then if the two identifiers match. With the case of a CSRF attack, the two identifiers will not match because the form&#8217;s identifier will not be passed as part of the request (I hope this is clear; if not, let me know). Note that this only works if you&#8217;re using <a
href="http://www.yiiframework.com/doc/api/1.1/CHtml">CHtml</a> to create your forms (if you manually create the form tags, Yii won&#8217;t insert the necessary code for preventing CSRF attacks).</p><p>The most important thing to remember about cookies, which I&#8217;ve already stated, is that cookies are visible to the user in the browser. And unless you&#8217;re using SSL for the cookies, they are also visible to anyone else while being transmitted back and forth between the server and the client (which happens on every page request). So be careful of what gets stored in a cookie! If the data is particularly sensitive, use sessions instead of cookies.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Five Critical E-Commerce Security Tips in Five Days</title><link>http://www.larryullman.com/2011/02/26/five-critical-e-commerce-security-tips-in-five-days/</link> <comments>http://www.larryullman.com/2011/02/26/five-critical-e-commerce-security-tips-in-five-days/#comments</comments> <pubDate>Sat, 26 Feb 2011 16:59:17 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[article]]></category> <category><![CDATA[blog]]></category> <category><![CDATA[ecom]]></category> <category><![CDATA[file upload]]></category> <category><![CDATA[hosting]]></category> <category><![CDATA[security]]></category> <category><![CDATA[validate]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2361</guid> <description><![CDATA[Peachpit Press has published on their Web site my &#8220;Five Critical E-Commerce Security Tips in Five Days&#8221; series of blog postings. The specific postings are: Maintaining Secure Passwords: Five Critical E-Commerce Security Tips in Five Days Securely Handling File Uploads: Five Critical E-Commerce Security Tips in Five Days Have a Emergency Plan: Five Critical E-Commerce [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://www.peachpit.com">Peachpit Press</a> has published on their Web site my &#8220;Five Critical E-Commerce Security Tips in Five Days&#8221; series of blog postings. The specific postings are:</p><ul><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Maintaining-Secure-Passwords-Five-Critical-E-Commerce-Security-Tips-in-Five-Days">Maintaining Secure Passwords: Five Critical E-Commerce Security Tips in Five Days</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Securely-Handling-File-Uploads-Five-Critical-E-Commerce-Security-Tips-in-Five-Days">Securely Handling File Uploads: Five Critical E-Commerce Security Tips in Five Days</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Have-a-Emergency-Plan-Five-Critical-E-Commerce-Security-Tips-in-Five-Days">Have a Emergency Plan: Five Critical E-Commerce Security Tips in Five Days</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Validate-Validate-Validate-Five-Critical-E-Commerce-Security-Tips-in-Five-Days">Validate, Validate, Validate: Five Critical E-Commerce Security Tips in Five Days</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Understand-Your-Hosting-Five-Critical-E-Commerce-Security-Tips-in-Five-Days">Understand Your Hosting, Five Critical E-Commerce Security Tips in Five Days</a></li></ul><p>The postings are in concert with my “Effortless E-Commerce with PHP and MySQL” book, although the information provided, from theory to actual code, should be useful whether you&#8217;ve read that book or not.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/02/26/five-critical-e-commerce-security-tips-in-five-days/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Email Validation in PHP</title><link>http://www.larryullman.com/2010/06/10/email-validation-in-php/</link> <comments>http://www.larryullman.com/2010/06/10/email-validation-in-php/#comments</comments> <pubDate>Thu, 10 Jun 2010 01:15:47 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=1094</guid> <description><![CDATA[A very common need in PHP-based Web applications is to validate email addresses. An email address, at its most basic contains the @ and a dot and no spaces or special characters, so it&#8217;s pretty easy coming up with a regular expression that will fit this most simple restriction. However, if you want a full-on [...]]]></description> <content:encoded><![CDATA[<p>A very common need in PHP-based Web applications is to validate email addresses. An email address, at its most basic contains the @ and a dot and no spaces or special characters, so it&#8217;s pretty easy coming up with a regular expression that will fit this most simple restriction. However, if you want a full-on precise regular expression, that takes an immense amount of code (the full email validation pattern takes up almost a page of code). An alternative, then is to use the <strong>EmailAddressValidation</strong> class, created by <a
href="http://www.addedbytes.com/blog/email-address-validation-v2/">Added Bytes</a> and now hosted on <a
href="http://code.google.com/p/php-email-address-validation/">Google Code</a>.</p><p>After you&#8217;ve downloaded the code and put it on your server, you use it like so:</p><pre>require('/path/to/EmailAddressValidator.php');
$emailValidator = new EmailAddressValidator();
if ($emailValidator-&gt;check_email_address('test@example.org')) {
    // Email address is technically valid.
} else {
    // Email not valid.
}</pre>]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2010/06/10/email-validation-in-php/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Security is Next to Godliness</title><link>http://www.larryullman.com/2010/05/01/security-is-next-to-godliness/</link> <comments>http://www.larryullman.com/2010/05/01/security-is-next-to-godliness/#comments</comments> <pubDate>Sat, 01 May 2010 19:33:53 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Flex]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=1031</guid> <description><![CDATA[I&#8217;ve been trying to write more about Web development security lately, in part because I&#8217;m going to be writing an &#8220;E-Commerce with PHP and MySQL&#8221; book this summer, so security is at the top of my mind. , I made some suggestions as to how one develops and tests a site from a security perspective. [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been trying to write more about Web development security lately, in part because I&#8217;m going to be writing an &#8220;E-Commerce with PHP and MySQL&#8221; book this summer, so security is at the top of my mind. <a
href="http://www.larryullman.com/2010/04/17/a-simple-approach-to-site-security/">In a previous post</a>, I made some suggestions as to how one develops and tests a site from a security perspective. Here I want to cover security as a general philosophy, so you understand that approach I take (and, therefore, the approach I would recommend you take). When I explain things, I think in terms of analogies. I&#8217;m pretty sure they don&#8217;t always work or help, but still, it&#8217;s what I do. And the analogy I have for Web site (or application) security is: <em>Security is Next to Godliness</em>. Which is to say, think of security the way you might think about cleanliness.<span
id="more-1031"></span>Say you go to eat at a restaurant&#8230;the restaurant may or may not <strong>look</strong> clean and it may or may not <strong>be</strong> clean. But if the restaurant doesn&#8217;t look clean, then it probably isn&#8217;t actually clean and you don&#8217;t want to eat there. The same goes for a Web site&#8217;s security: if it doesn&#8217;t give the appearance of being secure, it probably isn&#8217;t secure, and users won&#8217;t want to use the site (or shouldn&#8217;t). A Web site can look secure by looking professional, giving proper error messages, and by not looking obviously unsecure. This last quality is really the most important, as the common person may not really know the difference between a secure looking and unsecure looking site. But if they go to a site and get alerts from their browser due to a lack of a good certificate, or whatever, that&#8217;s like seeing a rodent go across the restaurant floor.</p><p>The second part of this analogy is that while it&#8217;s important for a restaurant to look clean (so people will eat there), it&#8217;s more important that it&#8217;s actually clean (so that diner&#8217;s don&#8217;t get sick, so that the inspector doesn&#8217;t shut you down, etc.). And so your Web site must actually be secure, so that nothing bad can happen to the users, your clients, the Easter bunny, and so forth.</p><p>The final reason I think this analogy works is that like security, like cleanliness, isn&#8217;t an absolute and the amount of effort you put into it should depend upon the situation. Your front porch doesn&#8217;t need to be that clean, but your bathrooms and kitchens sure do. And maybe you&#8217;re the kind of person that would thoroughly clean monthly, weekly, or daily. Maybe you&#8217;re the kind that will take cleaning to the disinfecting level. There&#8217;s no right answer in these situations: there&#8217;s better and there&#8217;s worse and there&#8217;s what&#8217;s right for you and your situation. The same goes for security. A site that handles no money has one level of security requirements; a site that performs online banking has a totally different level. Most importantly, just because you cleaned today, doesn&#8217;t mean your place will stay clean forever. And the Web site or application you ship today without any issues could become vulnerable tomorrow (most likely because of a found concern with underlying software or third-party applications).</p><p>So there&#8217;s my simple, yet overly-described, analogy for Web site or application security. Hopefully it&#8217;ll help you in the way you think about your Web site (or the next meal out!).</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2010/05/01/security-is-next-to-godliness/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>A Simple Approach to Site Security</title><link>http://www.larryullman.com/2010/04/17/a-simple-approach-to-site-security/</link> <comments>http://www.larryullman.com/2010/04/17/a-simple-approach-to-site-security/#comments</comments> <pubDate>Sat, 17 Apr 2010 13:31:24 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=1009</guid> <description><![CDATA[There are two kinds of security that Web sites, applications, and operating systems can provide: perceived security and actual security. Perceived security is still important, because that&#8217;s what convinces users that it&#8217;s safe to, for example, provide their personal information to your Web site. But actual security is the key. Think of it as the [...]]]></description> <content:encoded><![CDATA[<p>There are two kinds of security that Web sites, applications, and operating systems can provide: <em>perceived</em> security and <em>actual</em> security. Perceived security is still important, because that&#8217;s what convinces users that it&#8217;s safe to, for example, provide their personal information to your Web site. But actual security is the key. Think of it as the difference between having a sign in front of your house saying it&#8217;s protected by a security system and actually having a security system. But if you&#8217;re anything like me, you&#8217;ve never tried to hack someone&#8217;s Web site and aren&#8217;t generally inclined to think like a person who would, so how do you make your sites secure? Here&#8217;s what I do&#8230;<span
id="more-1009"></span></p><p>You really have to start thinking about security from the get-go, which means the database. Secondary column properties make a big difference to the reliability of the stored data. This means identifying columns as <strong>NOT NULL</strong>, <strong>UNSIGNED</strong>, a particular number of decimals, and applying a <strong>UNIQUE</strong> index (all of these as appropriate, of course). These settings will prevent bad data from getting into the database, such as negative quantities or duplicate email addresses (the PHP code will need to handle those MySQL rejections, though).</p><p>In your PHP code, you&#8217;ll want to use regular expressions to validate data when you can. And all strings should be run through an escaping function like <strong>mysqli_real_escape_string()</strong>, prior to using them in a database query. I would do this even if the data already passed a regular expression (you cannot be too careful). You can also consider applying <strong>strip_tags()</strong>, too.</p><p>For numeric values, I strongly recommend type-casting:</p><pre>$something = (int) $_POST['something'];</pre><p>Type-casting to numbers will make the data safe to use in queries. If you type-cast a string as an integer, the result will be zero, so you can type-cast, then check for a valid value (i.e., greater than zero). Valid numeric values will just be formally converted from a string with that value to a number with that value.</p><p>With variables, it&#8217;s also best to assume the values are invalid or not present at all, then prove otherwise.</p><p>When you get to your HTML, there&#8217;s not much you can do to <em>guarantee</em> security, but you can <em>encourage</em> it. For example, you can limit the length of a text input to whatever is the maximum size of the corresponding column in the database. Or you can use drop-down menus with preset values. Client-side validation using JavaScript is nice for the end user, but is not a real security tool as JavaScript can easily be disabled.</p><p>Once you&#8217;ve done all that (and hopefully you already are doing most of these things), you can run some tests to find potential security holes. To start, I think about the three kinds of people that use the site: those that use it perfectly, exactly as intended; those that use it without malicious intent, but that might cause problems; and those that are trying to hack the site. In the first category you have pretty much just me. I&#8217;m developing the site, I know what it&#8217;s supposed to do and how I think it&#8217;s to be used, and I&#8217;m not likely to break it. In the second category is almost everyone. They just want to use the site, they may make mistakes, they may have apostrophes in their names, and they just expect the site to work regardless. For these people, the goal is to provide a proper user interface, point out mistakes when they occur, and insure that clean, proper data is used at every step of the way. For the third category of user, they&#8217;ll do everything they can, include taking extraordinary steps, to try to break your site in order to get some information they deem useful.</p><p>There&#8217;s really no point in testing the site as <em>I&#8217;d </em>use it, so I quickly start imitating the behavior of the second group of users. First, I test my PHP scripts by submitting forms without doing anything at all. The result should be appropriate error messages to the end user, without ANY &#8220;undefined index&#8221; or similar PHP errors. The same goes for scripts that expect to receive values in the URL: test them without sending any values in the URL and see the result. Second, I fill out forms using invalid values: numbers for strings and vice versa. What is the result? Third, I fill out the forms using potentially valid, but complicated values, such as strings with apostrophes and quotation marks, possibly even with HTML.</p><p>As I said, I&#8217;m not maliciously-inclined (or I&#8217;d like to think I&#8217;m not), so it&#8217;s hard for me to think like a hacker. Much of what a hacker might try to do will be caught by the previous set of tests, though. If your site handles invalid data, apostrophes, quotation marks, and HTML tags properly, you&#8217;ve already done a lot to prevent bad things from happening. Hackers might take things further though, like creating their own HTML form that submits data to your PHP scripts (you can POST data without using a form at all, too). What if a hacker were to create a copy of your form, and replace your &#8220;quantity&#8221; or &#8220;states&#8221; drop-down menu with a text input, so they could use their own values? How well would the PHP script handle that contingency?</p><p>Hackers also like to get into places they shouldn&#8217;t, so try directly accessing scripts or directories that should be protected. Also try directly running scripts that are meant to be included, such as a configuration file. If you&#8217;re serving files to only authenticated users, can those files be viewed directly?</p><p>Sometimes the goal of a hacker is to find out information about your server, so you have to be extra careful that the site does not give too much away, specifically, too much about PHP, Apache (or whatever Web server), and MySQL. Towards that end, you have to make sure that MySQL errors are handled properly, without revealing anything to the end user. To do this, you may need to temporarily break your database scripts to see the result. For example, you&#8217;ve got a site working and it&#8217;s not giving away any secrets, whether or not the user behaves themselves. But what if the database server goes down or is to busy or something else happens to prevent your PHP scripts from connecting? What would the user see then? Hopefully nothing but a generic &#8220;system is done/come back later&#8221; apology.</p><p>With practice, developing sites to properly handle all of these situations and types of users becomes second-nature (not that you shouldn&#8217;t continue to test them). But I know that as you&#8217;re just getting going, it&#8217;s natural to feel like you haven&#8217;t done enough or tested enough. I hope that these few paragraphs provide a better feel for the process.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2010/04/17/a-simple-approach-to-site-security/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Protecting Email Addresses Online</title><link>http://www.larryullman.com/2009/06/16/protecting-email-addresses-online/</link> <comments>http://www.larryullman.com/2009/06/16/protecting-email-addresses-online/#comments</comments> <pubDate>Tue, 16 Jun 2009 11:55:46 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[bot]]></category> <category><![CDATA[security]]></category> <category><![CDATA[spam]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=463</guid> <description><![CDATA[If you have an email address posted on a Web site, you&#8217;re almost guaranteed to get spam. Bots scour the Internet, looking through HTML source code to find email address to harvest. Web developers, meanwhile, are constantly trying new techniques to prevent this from happening. In this post, I discuss an interesting study in spam [...]]]></description> <content:encoded><![CDATA[<p>If you have an email address posted on a Web site, you&#8217;re almost guaranteed to get spam. Bots scour the Internet, looking through HTML source code to find email address to harvest. Web developers, meanwhile, are constantly trying new techniques to prevent this from happening. In this post, I discuss an interesting study in spam prevention, some of the available techniques, and the route I choose to go on a recent project.<span
id="more-463"></span>In 2006, a developer created nine email addresses and posted them online, each protected in different ways (or not at all). You can read about this in detail at <a
href="http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/">techblog.tilllate.com</a>. I love this kind of empirical study, because it uses raw data to prove the efficacy of the approaches. Keeping the email in plain text had the worst result, as you might expect, with encoded and slightly obfuscated versions also being hit with spam. These latter techniques are things like replacing the @ symbol with something less obvious: <em>myname [AT] example -DOT- com</em>. And even if you do try this, you still need to put the actual email address in the HTML <strong>mailto</strong> link, so that won&#8217;t really work.</p><p>The most effective results came from using ROT13 encryption, in which the source code has the email address in an encrypted format, with JavaScript then dynamically creating a legible, and clickable, <strong>mailto</strong> link by decryption. Of course, the JavaScript method won&#8217;t work if JavaScript is disabled, but I don&#8217;t personally worry about that too much.</p><p>There are also two very interesting CSS techniques (this code comes from <a
href="http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/">http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/</a>):</p><pre>&lt;style type="text/css"&gt;
span.codedirection { unicode-bidi:bidi-override; direction: rtl; }
&lt;/style&gt;
&lt;p&gt;&lt;span class="codedirection"&gt;moc.elpmaxe@emanym&lt;/span&gt;&lt;/p&gt;</pre><p>and</p><pre>&lt;style type=”text/css"&gt;
p span.displaynone { display:none; }
&lt;/style&gt;
&lt;p&gt;myname@&lt;span class=”displaynone”&gt;null&lt;/span&gt;example.com&lt;/p&gt;&lt;/p&gt;</pre><p>The first example says that the backwords HTML text should be displayed from right to left order. The second adds an invisible <em>null</em> to the example address. Unfortunately these two routes won&#8217;t allow for clickable links and make your site less accessible. Which leads me to a main consideration in this battle: <span
style="text-decoration: underline;">There&#8217;s no perfect solution sometimes</span>!</p><p>One option that I like is to just use a contact form that sends an email upon submission. This only really works if you have just a single email address associated with a site and it does limit what content can be sent (e.g., no attachments without some extra form work). On my own site, I use an image representation of an email address. But like the CSS methods, a link won&#8217;t be clickable and the accessibility is degraded. You can minimize the latter concern by making the <strong>ALT</strong> tag descriptive, like <em>my first name plus my first initial at this domain</em>. But also keep in mind it&#8217;s possible for bots to read images, which is why CAPTCHA text has to be so strange. That being said, I&#8217;ve been using this technique for a couple of years now and I don&#8217;t think I&#8217;ve gotten any spam on that address yet.</p><p>Those are relatively simple routes. If you want a really thorough solution, <a
href="http://www.alistapart.com/articles/gracefulemailobfuscation">A List Apart</a> has a detailed client- and server-side approach you can try.</p><p>As for what I&#8217;ve done lately, on a recent Web site I created, dozens of email addresses are listed for the different people involved with the project, so using a contact form wasn&#8217;t possible. The project itself involves people for whom accessibility is key, so the CSS techniques were out, too. In the end I went with a JavaScript solution, using <a
href="http://www.jquery.com">jQuery</a> and <a
href="http://www.php.net">PHP</a>, which the site is built with. This particular technique—and I have no hard data for how effictive it is—uses a <a
href="http://www.leftrightdesigns.com/library/jquery/nospam/php-integration.php">PHP function</a> to create a somewhat-obsfucated HTML source of an email address, then uses a <a
href="http://plugins.jquery.com/project/nospam">jQuery Plugin</a> to turn that source into a readable, and even clickable, link. For this project right now, it seems to be a reasonable compromise.</p><p>Of course, bots keep learning and they&#8217;ll figure out how to get around these techniques, which is why we all need to stay informed and try new things. That, and get rid of our email addresses every couple of years!</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2009/06/16/protecting-email-addresses-online/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Five JavaScript Tips in Five Days, continued</title><link>http://www.larryullman.com/2009/03/17/five-javascript-tips-in-five-days-continued/</link> <comments>http://www.larryullman.com/2009/03/17/five-javascript-tips-in-five-days-continued/#comments</comments> <pubDate>Tue, 17 Mar 2009 13:12:06 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[security]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=350</guid> <description><![CDATA[The other three posts in my Five JavaScript Tips in Five Days series for Peachpit Press have now been posted. The full set is: Handling JSON Data Securely Debugging XML/JSON Requests Choosing a JavaScript Framework Performing Cross-Domain Ajax Requests Loading JavaScript Faster]]></description> <content:encoded><![CDATA[<p>The other three posts in my <em>Five JavaScript Tips in Five Days</em> series for <a
href="http://www.peachpit.com">Peachpit Press</a> have now been posted. The full set is:</p><ul><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Handling-JSON-Data-Securely1">Handling JSON Data Securely</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Debugging-XMLJSON-Requests">Debugging XML/JSON Requests</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Choosing-a-JavaScript-Framework2">Choosing a JavaScript Framework</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Performing-Cross-Domain-Ajax-Requests">Performing Cross-Domain Ajax Requests</a></li><li><a
href="http://www.peachpit.com/blogs/blog.aspx?uk=Loading-JavaScript-Faster">Loading JavaScript Faster</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2009/03/17/five-javascript-tips-in-five-days-continued/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: www.larryullman.com @ 2012-02-05 14:22:27 by W3 Total Cache -->
