craygo Posted February 28, 2006 Share Posted February 28, 2006 I have 2 files. function.php and servstatus.phphere is snips from both filesfunctions.php[code]// Check if TE CSS Private 1 server is runningfunction tecsspriv1(){$serv1 = win32_scheduler_get_task_info("start_TE_CSS_Priv1");foreach ($serv1 as $k1[] => $v1[]){//echo "$key: $value<br />\n";}if($v1[12] == '267009'){$priv1status = 'Online';} else {$priv1status = 'Offline';}echo $priv1status;}[/code]servstatus.php[code]<?include('includes/functions.php');?><table width=600 align=center><form name=servmanager method=POST action="<?=$_SERVER['PHP_SELF']?>"> <tr> <td width=400>The Elders CS:S Private 1 IP:66.29.112.102</td> <td colspan=2 align=center><strong><?=tecsspriv1()?></td> </tr> <tr> <td> </td> <td width=100><input type=submit name=shutdown value="Shutdown Priv1"></td> <td width=100><input type=submit name=start value="Start Priv1" <?if($priv1status == 'Online'){print 'disabled'; }?>></td> <---- Line 29 </tr></form></table>[/code]When I go to the page is saysNotice: Undefined variable: priv1status in c:\Inetpub\wwwroot\gamestatus\servstatus.php on line 29How come the variable is not being carried over from the functions file.thanksRay Quote Link to comment https://forums.phpfreaks.com/topic/3755-functions-variables-not-working/ Share on other sites More sharing options...
kenrbnsn Posted February 28, 2006 Share Posted February 28, 2006 Varibles declared in a function are available only to the function.Change your function to return the status instead of echoing it.[code]<?phpfunction tecsspriv1(){ $serv1 = win32_scheduler_get_task_info("start_TE_CSS_Priv1"); foreach ($serv1 as $k1[] => $v1[]){ //echo "$key: $value<br />\n"; } $priv1status = 'Offline'; if($v1[12] == '267009') $priv1status = 'Online'; return ($priv1status); // return status}?>[/code]then where you want to use it:[code]<?phpinclude('includes/functions.php');$priv1status = tecsspriv1(); // get the status?><table width=600 align=center><form name=servmanager method=POST action="<?=$_SERVER['PHP_SELF']?>"> <tr> <td width=400>The Elders CS:S Private 1 IP:66.29.112.102</td> <td colspan=2 align=center><strong><? echo $priv1status ?></td> </tr> <tr> <td> </td> <td width=100><input type=submit name=shutdown value="Shutdown Priv1"></td> <td width=100><input type=submit name=start value="Start Priv1" <?if($priv1status == 'Online') echo 'disabled'; ?>></td> </tr></form></table>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/3755-functions-variables-not-working/#findComment-13031 Share on other sites More sharing options...
craygo Posted February 28, 2006 Author Share Posted February 28, 2006 Exactly what I needed to know!!Thanks KenRay Quote Link to comment https://forums.phpfreaks.com/topic/3755-functions-variables-not-working/#findComment-13039 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.