Jason Pruim 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
[EMAIL PROTECTED]

Functions basically save you repeating code; for example, let's say we have these lines of code in 10 scripts on our website:

if(isset($_GET['pageid']) && trim($_GET['pageid'])) {
 $pageid = trim($_GET['pageid']);
} else {
 $pageid = '1';
}

you could wrap this code up in a function as such:

function get_pageid() {
 if(isset($_GET['pageid']) && trim($_GET['pageid'])) {
  $pageid = trim($_GET['pageid']);
 } else {
  $pageid = '1';
 }
 return $pageid;
}

save that function (along with other functions you've made) in an php file (example: myfunctions.php)

then in every script we simply include our functions file and call our function(s) as and when we need them:

scripta.php:
<?php
include 'myfunctions.php';
$pageid = get_pageid();
//more code
?>

I'm no technical writer but I think that about sums it up.

Nathan

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

Reply via email to