Jump to content

Functions


Arbitus

Recommended Posts

I'm having problems with functions.  This is my first time actualy using functions in a script so bare with me.

 

How would I be able to create a functions.php, and in this file one of the functions created would check to see if the users session is active.

 

Right now I'm trying this

 

functions.php

<?php

//Functions.php!

function session_check()
	 {
	 if(isset($_SESSION['admin_id']))
	 {

?>

 

index2.php

<?php
include("../Sources/functions.php");

session_check();

echo "hello!";

} else {

echo "no hello!";

}

?>

 

I know I'm most likely doing something terrible here. :)

Link to comment
https://forums.phpfreaks.com/topic/132990-functions/
Share on other sites

A function should be a self-contained block of code, optionally accepting parameters from the routine that calls it, and optionally returning a value to the script that calls it.

 

 

function session_check()
    if (isset($_SESSION['admin_id'])) {
        return true;
    } else {
        return false;
    }
}

 

if (session_check()) {
   echo 'hello';
} else {
   echo 'something else';
}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/132990-functions/#findComment-691654
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.