Re: Question about functions

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

 



On Jan 24, 2008 3:00 PM, Jason Pruim <japruim@xxxxxxxxxx> wrote:
> Hi everyone!
>
> So, I'm trying to learn about functions, and I think I understand what
> to use them for... And one of the ideas I had was to write a function
> to logout of an application. The question I have though, is how do I
> call it?
>
> Right now I just have a link like this: <A href="logout.php">Click
> here to logout</A>  Can I do the same thing with a function? And if
> so, then maybe I don't really understand functions like I thought I
> did... Because to me, that would look like it would be just the same
> as calling a single script to logout vs. a function?
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> japruim@xxxxxxxxxx
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Keep your link as is.  Create a page called logout.php.

Make it look like something like this:

<?php
require_once 'functions.php';
logout();
require_once 'index.php';
?>

Then functions.php:
<?php
function logout() {
    session_destroy(); or whatever
}
?>

See the function is an idea of code to be run.  You still have to
access a function at some point and run it.  The point though is that
you call the function instead of having tons of code just littering up
your page.  It makes the logic flow of your scripts easier to
understand.

Another example would be a form processing page.  You could do something like

if (my_uber_form_processor() !== true) {
    require_once 'form.php';
    exit();
}

require_once 'success.php';

This way you keep the logic of how your pages work separate from the
gritty details of what form processing is or how you log out.  This is
a oversimplification, but hopefully it might make something in your
head click.

-- 
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