The Gamer Corner
This isn't the brand of crazy koolaid that I usually pour
chaoscat
Lost your password?

PHP Tutorial

PHP Tutorial – July 9, 2008 7:40 PM (edited 7/9/08 3:40 PM)
Cuzzdog (1522 posts) Head of Gamer Corner R&D
Rating: Not Rated
Not that anyone here is likely to need this, but in terms of learning php from a beginner standpoint, I found the following tutorial to be excellent. It answered every question I had thought of before hand, including things I was thinking were advanced issues like handling server-side data files and connecting to a DB.

http://devzone.zend.com/node/view/id/627

Re: PHP Tutorial – July 9, 2008 7:43 PM (edited 7/9/08 3:43 PM)
Talraen (2373 posts) Doesn't Play with Others
Rating: Not Rated
Oh god, PHP embedded inside HTML, my eyes, they burn!!!

Seriously, the whole <?php and ?> thing? Just mark the beginning and end of files. Wink

Re: PHP Tutorial – July 9, 2008 7:44 PM (edited 7/9/08 3:44 PM)
Cuzzdog (1522 posts) Head of Gamer Corner R&D
Rating: Not Rated
Really? But then don't you have to do echo commands to get regular HTML on the output? I would think that would be far uglier...

Re: PHP Tutorial – July 9, 2008 7:47 PM (edited 7/9/08 3:48 PM)
Talraen (2373 posts) Doesn't Play with Others
Rating: Not Rated
Oh god no, you use smarty. Sure, I don't exactly use PHP the way it was originally designed, but whatever.

EDIT: Smarty is a template engine. In case you were wondering.

Re: PHP Tutorial – July 9, 2008 7:53 PM (edited 7/9/08 3:53 PM)
Cuzzdog (1522 posts) Head of Gamer Corner R&D
Rating: Not Rated
LOL my work blocks smarty! What are they? Porn templates?! Big Smile

Anyway, as I'm programing on someone else's box (the school's) I'm not sure I'll be able to such a thing. Also, it's not like I can check right now since it's blocked.

But, fancy pants apps aside, I don't have a problem with embedded tag code mixed with HTML code. At work, we do the same with JSP tags. In fact, I'm pretty sure you need to mix HTML and JSP tags together, so the concept didn't really strike me as ugly when I saw the same with the PHP. As I said, I would think mixing is cleaner than having a ton of echo commands as the alternative.

Re: PHP Tutorial – July 9, 2008 8:01 PM (edited 7/9/08 4:01 PM)
Talraen (2373 posts) Doesn't Play with Others
Rating: Not Rated
Oh, you never have to do anything. For example, here's the source code of the base index.php file for this site (specifically the splash page):
<?php

require_once ("../src/Splash.php");

$page= new Splash ();
$page->get_content ();
$page->run ();
?>
Yep, that's it. This site (and most of the advanced PHP sites I'm familiar with) has little placeholder files which call the real source code, which is object-oriented, and relies on Smarty for output. This prevents the possibilty of exposing your database password to a file visible to people on the web, as chaoscat unfairly accused PHP of doing.

Basically, the main object the site runs on either has a smarty object, or extends it (I don't remember), and both the source code and the templates are outside of the web-visible directory tree. The source gathers up all the variables and spits them into a template.

What's interesting about Smarty is that it doesn't just replace things on the template with text and output it, but rather turns the template into an old-school PHP/HTML script which is hideously ugly to read. It's pretty cool, really.

Re: PHP Tutorial – July 10, 2008 12:36 PM (edited 7/10/08 8:36 AM)
chaoscat (452 posts) Ambassador of Good Will
Rating: Not Rated
It's not that I'm saying you can't write secure PHP, or insecure anything else. I'm just saying that PHP SQL Injection Attack is it's own domain of exploit. And yes, I realize that's not quite the same as splashing the db password on every page. 98% of my objections to PHP could be fixed if they would include namespaces and something roughly equivilant to perl's taint mode

_________________________________________________
Talraen (11:16 AM): That, and I've learned to parse through Tozzi's contempt
Active Users: (guests only)
1 user viewing | Refresh