installer file creater help needed

From: Date: Fri, 15 Oct 2004 13:23:30 +0000
Subject: installer file creater help needed
Groups: php.general 
Request: Send a blank email to php-general+get-199591@lists.php.net to get a copy of this message
Does anyone know how i can get this following code (#1) in the adminconfig.php script (#2). At the moment script #2 creates a file---config.php which has the php open/close tags plus the variables for hostname etc but i need the code #1 to be embedded below all of this but before the closing php tag, but as is with all the indents etc. I tried to get it to work but failed miserabley ! (is that a word) I hope you all understand what i mean! //////////////////////////////////////////////////////////////////////////// (#1) /////////////////////////////////////////////////////////////////////////// $link = mysql_connect($host, $username, $password); if(! @$link) die("<br><br>Could not connect to MySQL"); $database = "mytipinstaller"; mysql_select_db($database) or die ("<br><br>Could not open " . $database .mysql_error() ); //////////////////////////////////////////////////////////////////////////// / (#2) //////////////////////////////////////////////////////////////////////////// // $filename="config/config.php" ; $itemsarray = array("hostname", "user", "password") ; if ($btnsubmit) { foreach ($itemsarray as $value) { ${$value} = stripslashes(${$value}) ; writeconfig($value, ${$value}) ; } } else { foreach($itemsarray as $value) { ${$value} = readconfig($value) ; } } function readconfig($item) { global $filename ; $fcontents=@file($filename) ; if (!empty($fcontents)) { while (list($linenum, $line) = each($fcontents)) { if (leftside($line) == $item) { return rightside($line) ; break ; } } } return "" ; } function writeconfig($item, $value) { global $filename ; if (!file_exists($filename)) { $fp = fopen($filename, "w") ; fputs($fp, "<?php\n"); fclose($fp) ; } $fcontents=file($filename) ; $fp = fopen($filename, "w") ; $found = false ; while (list($linenum, $line) = each($fcontents)) { if ($line != "?>\n") { if (leftside($line) == $item) { fputs($fp, "\$".$item."=\"".$value."\";\n") ; $found = true ; } else { fputs($fp, $line) ; } } } if (!$found) { fputs($fp, "\$".$item."=\"".$value."\";\n") ; } fputs($fp, "?>\n") ; fclose($fp) ; } function leftside($line) { $pos = strpos($line, "=") ; if ($pos === false) { return "" ; } else { return substr($line, 1, $pos-1) ; } } function rightside($line) { $pos = strpos($line, "=") ; if ($pos === false) { return "" ; } else { return substr($line, ($pos+2), strlen($line)-5-strlen(leftside($line))) ; } } echo "<html><body><form method=post action=\"".$PHP_SELF."\">" ; foreach ($itemsarray as $value) { echo "$".$value." <input type=text name=".$value." size=20 value=\"".${$value}."\"><br>" ; } ?> <input type=submit name=btnsubmit value=Save> </form> </body> </html> //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////

« previous php.general (#199591) next »