« first day (43 days earlier)      last day (5 days later) » 

5:58 PM
@TheUnhandledException - There?
 
6:37 PM
@TheUnhandledException I'm here.
 
Hey. I just got back from lunch, won't be able to help much for at least 30 minutes, have an email transfer to cpmplete and a hosting account to set up
 
@TheUnhandledException - ok, that's perfect.
I have to finish lunch here too.
@TheUnhandledException - what's JPA?
 
Somebody called for PHP?
 
@spoulson - that would be me
We were discussing sessions yesterday.
 
ahh, well I'm not really a PHP expert, but thought I'd see if I could help
Spent most of my PHP time in Drupal or CakePHP
 
6:51 PM
@spoulson - Ok, Well I'm trying to roll a CMS.
Yesterday we were dealing with a typo in a variable name. (Kudos to Tim for the find).
Once that was clear, I'm back to the project.
 
Hmm, I know it sounds like a big hammer, but Drupal might help in that department
You'd config a content type (audio), which uploads save to a certain directory, you attach meta data to it (title, body, access URL, etc.)
And customize a theme to view the content type to include an mp3 player or something like that.
 
@Moshe Sorry, "JPA"?
 
@TheUnhandledException - you mentioned that in The Tavern.
Forget it then.
@spoulson - I have a database set up for my metadata.
i need to get stuff into it and out of it.
 
@Moshe Ok, then my other big hammer is CakePHP. I'd rather use it than plain PHP.
 
@spuolson - What's that?
 
6:58 PM
@Moshe I did? maybe a typo. Do you have context?
 
I've seen that it exists (in O'Reilly's "PHP and MYSQL").
@TheUnhandledException hang on
 
cakephp.org It's an MVC framework that feels like RoR
 
@TheUnhandledException My mistake...
Tim said it.
in The Tavern (General), 13 mins ago, by Tim
I'm busy trying to figure out this JPA nonsense at the moment, but maybe later.
@spoulson - ok. I really want to do this one from scratch.
 
@Moshe Gotcha. No harm on that.
 
7:01 PM
If it tries to mimic RoR so hard, why not just use RoR?
 
Dunno
PHP hosting is a commodity.
 
@ThomasMcDonald - Not that this is the case, but perhaps one is working in an environment where PHP is available, not RoR.
 
RoR is still kinda specialized.
 
Anyhoo.
I'm also working on this: stackoverflow.com/questions/3936506/…
So, let's talk PHP.
 
7:04 PM
So, I'm trying to roll this CMS.
I kinda like the logic behind Wordpress - separate files for parts of the page.
header.php footer.php etc.(php?)
(rolls eyes at self for attempting humor)
And someone (@TheUnhandledException?) mentioned a separate auth.php file yesterday.
 
Can anyone help me with what that auth.php should look like?
 
@Moshe I did, yes
@Moshe Kinda ,like this:
21 hours ago, by John the Seagull
So, assuming one follows good security practices and trusts the PHP session security, one should do, starting each request (usually on its own file) something like
     if (!$_SESSION['valid']) {
          if(validate_user($_SESSION['user'],$_SESSION['pwd'])) {
               $_SESSION['valid'] = true; //Don't forget to SQL sanitize me if validation's against a DB
          } else {
               die("You are not authorized"); //Saner to redirect to login page or whatever
          }
 }
 
So how do I do the initial auth?
This only checks for subsequent auths, no?
 
What part are you unclear on?
The implementation of validate_user()?
 
7:14 PM
@spoulson - yes, that. And, what if $_SESSION['valid'] is true? What is $_SESSION['valid'] supposed to hold?
 
well, whatever you want, I suppose.
A fresh session will be void of any values, so by default 'valid' will be falsey.
 
@spoulson - But if I don't know what to put in there, it will always be invalid. hehe.
 
It's only ever set to 'true' if validate_user() returns true
 
@spoulson - so what does validate_user() look like?
 
Well, I would take the password, hash it and compare it against the hashed password in the database.
 
7:18 PM
@spoulson - ok.
and if it matches the username and password, return true, otherwise, return false?
 
You can add a little security on top of that, but that's the basic idea
 
where are the new login peices coming from?
 
Yes. The hashing part is so that you never store plaintext passwords in the database.
 
right, but where do I present the user with a login form?
 
Write up a login.php. It will have your HTML and form that submits to auth.php
 
7:21 PM
@spoulson - makes sense.
 
And in auth.php, I would use $_FORM[x] to access the submitted form, not $_SESSION
e.g. validate_user($_FORM['username'], $_FORM['pwd'])
 
And then the login.php needs to point to another file that sets the session variables in the first place. Correct?
 
yes, auth.php
But what I'm saying is, there's no reason to store the username/password in the session. That doesn't even sound safe.
 
@spoulson But why would I keep passing around my username and password around to the auth.php?
I apologize, but you've confused me.
 
Ok, I'll step through the initial login
User hits a page on your site.
That page checks $_SESSION['valid'] to see if the user is logged in
That's false, so the page redirects to login.php
User is presented with login form. He fills it out and clicks the submit button.
 
7:27 PM
ok.
 
The form is POSTed to auth.php
 
Can I pair this with AJAX (for better UX)?
 
auth.php checks $_SESSION['valid']. If false, it passes the POSTed name/password to validate_user()
if validate_user() returns true, $_SESSION['valid'] is set to true. From that point on, the user is logged into the site.
The name/password are not ever stored anywhere. It's just a one-way submit and then tossed after calling validate_user().
The end
:)
 
@Moshe sorry, things are really crazy here for me
@spoulson is giving you sound advice
 
@spoulson - then how do I check for authorization every time we do something like a file upload or database insert?
@TheUnhandledException - I'm okay as long someone is helping me. Thanks. How is your (hopefully gone) headache?
 
7:32 PM
@Moshe You might want to set $_SESSION['logged_in_user'] instead of $_SESSION['valid']
Since you have different users with different permissions
 
$_SESSION['valid'] will contain 'true' to indicate the user has been logged in
 
@Moshe Gone, yes, thank you.
 
yeah, what @TheUnhandledException said. There's nothing wrong with populating the session with some user metadata. Just don't put the password in there.
 
@spoulson He needs 3 levels of access, users, admins and superuser
 
@TheUnhandledException - But can't someone manually escalate their permissions level?
 
7:33 PM
@Moshe Nope
Unlike cookies, only your code can set $_SESSION
 
@TheUnhandledException So i just put a number in $_SESSION['logged_in_user']?
 
The easy way is to have a database field in the Users table "role", containing one of admin, user, superuser.
 
So unless your code has a bug :-)
 
1-5, for example, 5 being me and 0 being a guest - so as long as $_SESSION['logged_in_user'] is not 0.
 
@Moshe Either a number, and you can look up the user each time (this is what I would do) or, the actual user data
@Moshe I'd say an ID number.
so each user has an ID
in the database
 
7:34 PM
@TheUnhandledException Ah, you mean check permissions level based on the corresponding id from the database?
Where does that go? A separate file?
 
You know the id of row in the Users table, because you know the username at login.
 
@Moshe Where does which go?
 
@spoulson - that makes sense.
 
And if the passwords patch, the user is authenticated. You can pull all the fields associated with that user into the session. (except password)
 
@TheUnhandledException where do I lookup the ID for permissions?
Seperate file, called on every action to check for permissions?
 
7:36 PM
@Moshe what database are you using?
 
MySQL
MyISAM, I think.
Why?
 
@Moshe In a database
 
@TheUnhandledException - I know I look up from the database, but my question is where to put the actual PHP to create the lookup.
 
  $q="SELECT * FROM users WHERE id=".intval($_SESSION['logged_in_user']
@Moshe Here's what I'd do. I'd have a function to fetch the user from the database and store it in a global somewhere, and a function to check permissions
So for example:
function loadUser()
{
    global $system;
    if(!is_set($system['user']))
        // load the user from the database and store into $system['user']
}
 
$system?
 
7:41 PM
function checkUserHasPermissionLevel($level)
{
    global $system;
    loadUser();
    return ($system['user']['permissions'] <= $level);
}
 
ah
 
@Moshe I'm giving away my style :-)
I don't like a lot of globals floating around
I normally only have two: $config and $system
then I put things under those globals
but you can do it how you like
under $system I usually have things like the MySQL database link, open file handles, logged in user, information about the request, etc. Anything the entire system will need.
$config is where I put db username, password, etc
 
Well, I but curly braces on the same line as my function delcarations, if that helps preserve your style. ;-)
 
so when I connect to the database I say $system['database_link'] = mysql_connect($config['database']['name'], $config['database']['user'], ...
@Moshe I'm alone in my style there :-)
I almost never see people put curly braces on the next line like I do
 
@TheUnhandledException Except for the fact that the people behind C - Ritchie and Kernighan put them on the next line.
So, I gotta piece this together and get coding.
Should I work on a page template first and work in my PHP later?
 
7:50 PM
@Moshe Yeah when I learned C, I put them on the next line. habiot has stuck
 
@TheUnhandledException - ok
 
@Moshe Page template file?
sorry, trying to do work, have to run to an event in 8 minutes
haven't finsihed the days work, eeek
 
@TheUnhandledException ok good luck ttyl then.
 
When you say page template do you mean the look of all pages?
I'd do that in PHP as well
 
@TheUnhandledException - that's what I mean.
How so?
(sorry) ;-)
 
7:57 PM
OK. More secrets of mine coming :-)
sec, lemme get this navbar implemented, boss reloading page every few minutes, want him to see progress :-)
 
ok sure
 
OK, so what I do is create a single PHP file which contains the entire design. As if it were one big HTML page
 
Ok.
 
so it's easily editable in dreamweaver, frontpage etc
but at the beginning I have PHP that says, <?php if (!$template_opened) { ?>
and in the middle, where the content goes, I put <?php $template_opened = true; } else { ?>
So on every other page I just do:
include('template.php');
//some content
include('template.php');
That way the template looks to editors like a full page. It's easy to edit, and easy to include
 
I edit by hand though.
 
8:03 PM
but, this is just my style :-)
 
Interesting.
what goes into your "else"?
 
8:17 PM
@TheUnhandledException any particular reason you are not using Smarty or friends?
 
@JohntheSeagull No particluar reason. I just ended up building my own templating engine before learning about Smarty
@Moshe After the else goes the closing portion of the design
footer, etc
 
@TheUnhandledException - And how do I end up dealing with die() calls in the middle?
 
@Moshe You shouldn't actually die() in production code, you should either redirect to an error page or have an error handler that would log the errors and display a fancy page to the user
 
I actually prefer to use AJAX in a template, quicker UX, no?
@TheUnhandledException I'm also confused as to how your template works with more than two <?php $template_opened = "true" ?> calls
Whatever.
 
8:50 PM
Sorry guys
I'm like an hour late now :-(
gotta leave my ofice
@Moshe I'll be available a little bit tomorrow. Going on vacation next week
Catch you guys later!
 
@TheUnhandledException Thanks!
I am not around tomorrow.
@TheUnhandledException - Speak in two weeks then.
 

« first day (43 days earlier)      last day (5 days later) »