Re: Is this the best way?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Just to warn you... I've been up for about 30 minutes and I'm still on  
> my first shot of caffeine... Sorry if things don't make 100% sense :)

Same here.


> > start from scratch again?
> 
> By the time I'm ready to release this, I'll have 50 versions :)


Measure twice, cut once.   Not that I don't go through many versions when 
creating things, but it's nice to do as much design and theory before the 
coding so you don't have to end up with 50 versions.  But that's all part 
of learning, so it's all good.

> Would it make sense to set up a function to see if they are  
> authenticated, and if they aren't, have it call the authentication  
> function?

If that's how you want it designed. Yes.    A typical setup would be 
something like this:

if (!$authenticated) {
   // show login form or redirect to login page or show error
   exit();   // I like die() better myself, but it's your personal preference
}


// all the rest of your code here


> I've seen these kinds of things in other scripts that I've looked at,  
> but don't totally understand what the : does between 2 options...

That's a "ternary operation".  It's used as shorthand for a simple  
if...then.. else...

$val = ($condition) ? "condition is true" : "condition is false";

is the same as...


if ($condition) {
  $val = "condition is true";
} else {
  $val = "condition is false";
}


It just takes whatever the value before the ":" and assigns it to the 
variable if true, takes the value after the ":" and assigns it if false.

The values can be from functions or anything that returns a value, it doesn't 
have to be a straight variable type value.


-TG

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux