ShaolinF Posted February 3, 2008 Share Posted February 3, 2008 Hi Guys, I have an awful lot of sessions and I want to create a function to check them. Below is an example of a typical session check: if(isset($_SESSION['LOGINFAILED'])) { echo $_SESSION['LOGINFAILED']; } else { echo "none"; } Most of my session checks go along those lines. I have tried to make a function out of it but I keep having problems. See my current attempt below: function checkSession($sessionName) { if(isset($_SESSION["$sessionName"])) { echo $_SESSION["$sessionName"]; } else { echo "none"; } } Quote Link to comment https://forums.phpfreaks.com/topic/89174-solved-creating-functions/ Share on other sites More sharing options...
ratcateme Posted February 3, 2008 Share Posted February 3, 2008 you need to change your echo's to return's function checkSession($sessionName) { if(isset($_SESSION["$sessionName"])) { return $_SESSION["$sessionName"]; } else { return "none"; } } Scott. Quote Link to comment https://forums.phpfreaks.com/topic/89174-solved-creating-functions/#findComment-456632 Share on other sites More sharing options...
ShaolinF Posted February 3, 2008 Author Share Posted February 3, 2008 Ah ha. Thanks. What if I wanted to write a function for SELECT/UPDATE/DELETE/INSERT statements ? They all have the potential to accept many arguments. Quote Link to comment https://forums.phpfreaks.com/topic/89174-solved-creating-functions/#findComment-456642 Share on other sites More sharing options...
ratcateme Posted February 3, 2008 Share Posted February 3, 2008 you could create a function and use [ur=http://nz2.php.net/manual/en/function.func-get-arg.phpl]func-get-arg[/url] to get the args but i write all my query's inline with out functions Scott. Quote Link to comment https://forums.phpfreaks.com/topic/89174-solved-creating-functions/#findComment-456643 Share on other sites More sharing options...
haku Posted February 3, 2008 Share Posted February 3, 2008 You can write a function that will do all those things, but to write the function versatile enough to be able to handle all the different types of queries it ends up becoming so bulky that you might as well just write the queries inline each time. Quote Link to comment https://forums.phpfreaks.com/topic/89174-solved-creating-functions/#findComment-456674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.