ChrisMartino Posted May 8, 2010 Share Posted May 8, 2010 Well i have a function to edit find the value in a file using SSH2 and PHP, Here's what i have: My problem is that it won't edit the values for some reason, I've checked and all the directory's that it is fetching are correct but no file editing takes place?. public function CheckClientConfig($serverid) { if($this->IsValidGameServer($serverid)) { $ClearID = mysql_real_escape_string($serverid); $ObtainDetails = mysql_query("SELECT * FROM gameservers WHERE ServerID = '".$ClearID."'"); $Fetch = mysql_fetch_array($ObtainDetails); $SelectServer = mysql_query("SELECT * FROM servers WHERE ServerName = '".$Fetch[OnServer]."'"); $FetchServer = mysql_fetch_array($SelectServer); $SelectPackage = mysql_query("SELECT * FROM serverpackages WHERE PackageNAME = '".$Fetch[Game]."'"); $PackageRow = mysql_fetch_array($SelectPackage); $ssh = new Net_SSH2($FetchServer['IP']); if (!$ssh->login($FetchServer['RootUsername'], $FetchServer['RootPassword'])) { exit('There was a error Re-Starting the server, Please re-try or contact support.'); } $ReadConfig = $ssh->exec("sudo -u root cat /home{$Fetch['Directory']}/{$PackageRow['ConfigFile']}"); $config_file = explode("\n",trim(str_replace("\r",'',$ReadConfig))); $config_done = array(); $config = ''; foreach($config_file as $key => $line) { $line = trim($line); $ex = explode(' ',$line); if(strlen($ex[0]) != 0) { if(isset($ex[1])) $config_done[strtolower($ex[0])] = (string)$ex[1]; else $config_done[strtolower($ex[0])] = true; if(strcasecmp($ex[0],'maxplayers') == 0) { $slots = (int) $ex[1]; if($slots > $Fetch['Slots'] or $slots == 0) { $config .= 'maxplayers '.$Fetch['Slots']."\n"; } else { $config .= 'maxplayers '.$slots."\n"; } } elseif(strcasecmp($ex[0],'port') == 0) { $config .= 'port '.$Fetch['Port']."\n"; } else { $config .= $line."\n"; } } } if(!isset($config_done['maxplayers'])) $config .= 'maxplayers '.$Fetch['Slots']."\n"; elseif($config_done['maxplayers'] === true) $config .= 'maxplayers '.$Fetch['Slots']."\n"; $ssh->exec("echo '/home{$Fetch[Directory]}/{$PackageRow[ConfigFile]}' > ".$config); } } Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/ Share on other sites More sharing options...
ChrisMartino Posted May 8, 2010 Author Share Posted May 8, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/#findComment-1055164 Share on other sites More sharing options...
ChrisMartino Posted May 9, 2010 Author Share Posted May 9, 2010 Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/#findComment-1055370 Share on other sites More sharing options...
tomfmason Posted May 9, 2010 Share Posted May 9, 2010 you should use echo like this echo 'string' > /path/to/file for example $ssh->exec("echo '$config' > /home{$Fetch[Directory]}/{$PackageRow[ConfigFile]}"); Also, the code posted in your linux thread should work fine Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/#findComment-1055376 Share on other sites More sharing options...
ChrisMartino Posted May 9, 2010 Author Share Posted May 9, 2010 you should use echo like this echo 'string' > /path/to/file for example $ssh->exec("echo '$config' > /home{$Fetch[Directory]}/{$PackageRow[ConfigFile]}"); Also, the code posted in your linux thread should work fine This way still doesn't seem to work though? :[ Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/#findComment-1055392 Share on other sites More sharing options...
tomfmason Posted May 9, 2010 Share Posted May 9, 2010 You might want to read up on debugging. Here is a nice article that I used when I first started - http://www.ibm.com/developerworks/library/os-debug/ . It is a bit old(2005) but the basic concepts still apply. Link to comment https://forums.phpfreaks.com/topic/201108-edit-line-values-problem-in-php/#findComment-1055410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.