Kent Posted December 24, 2006 Share Posted December 24, 2006 I am new to this language (well all, except english). I would like to create a simple function (if thats right) for a security feature on a page. I give you the code first and then what I want to implementThe code i am struggling with (level.php):[code]$level = create_function($a,'0'){ if ($a => $_SESSION['levelID'];){ // level check OK // continue }elseif{ header("Location: /login.php"); exit(); // cut script here and send to login }}[/code]What I want it to do:[code]<? session_start();include ("level.php");level(2,$_SESSION[levelID]); ?>[/code]I hope you can figure out my mess. Basically if the $_SESION[levelID] does not match the variable set (ie. '2' in this example) then direct the user to the login page.My Code editor (Rapid PHP) is complaining about a Syntax error '{' on the $level, line. I dont understand function creation as well.Thankyou Link to comment https://forums.phpfreaks.com/topic/31773-function-syntax-please-help-noobie/ Share on other sites More sharing options...
.josh Posted December 24, 2006 Share Posted December 24, 2006 [code]<?php //example of a function where you don't need anything returned function echoIt ($value) { echo "$value"; } // example of a function that returns something function makeBold($value) { $value = "<b>$value</b>"; return $value; } /* example for using these functions */ // will call the echoIt function and the echoIt function will // echo out 'hello how are you?' echoIt("hello how are you?"); // this will make a variable called $message will contain // '<b>hello how are you?</b>' $message = makeBold("hello how are you?"); // calling echoIt with the $message will now echo a bold version of the string. echoIt($message);?>[/code] Link to comment https://forums.phpfreaks.com/topic/31773-function-syntax-please-help-noobie/#findComment-147357 Share on other sites More sharing options...
Kent Posted December 24, 2006 Author Share Posted December 24, 2006 Thankyou for that,I found out what was wrong and now have a working script.Here:[code]// check for Access Level via Session Variable// 0=Guest, 1=Member, 2=Moderator, 3=Administrator etc..function level($a){ $b = $_SESSION[leveID];// this is set when logged in if ($a <= $b) { // do nothing and allow the script to continue }else{ // send the script to the login page header("Location: /login.php"); exit();// kill the process here }}//Set access level of page at top of pagelevel(2)[/code]Thanks again/////////////////////////////To the post below....You are right, I changed it. (new u c) Thanks Link to comment https://forums.phpfreaks.com/topic/31773-function-syntax-please-help-noobie/#findComment-147371 Share on other sites More sharing options...
kenrbnsn Posted December 24, 2006 Share Posted December 24, 2006 Why have the null action? Check for what you want, not what you don't want.[code]<?php// check for Access Level via Session Variable// 0=Guest, 1=Member, 2=Moderator, 3=Administrator etc..function level($a){ $b = $_SESSION[leveID];// this is set when logged in if ($a > $b){ // send the script to the login page header("Location: /login.php"); exit();// kill the process here }}//Set access level of page at top of pagelevel(2);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31773-function-syntax-please-help-noobie/#findComment-147379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.