Results 1 to 3 of 3
Thread: PHP: Install Script
-
04-12-2005, 03:09 PM #1Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
PHP: Install Script
Hi all!
Im trying to do this install script for my script configuration, so the user does not need to open the config.php in a text editor and enter in their variables.
Like.. you know those install scripts forums like vBulletin and Invision uses, where you type your info in some form field, and click finish and it will enter those in for you. How would I do this? I have tried with fwrite and stuff.. cant get it to work
Any ideas?
-
04-12-2005, 03:32 PM #2Web Hosting Master
- Join Date
- Oct 2003
- Location
- Georgetown, Ontario
- Posts
- 1,771
They use the file handling functions to write the data to a file. Whats not working with fwrite? If you do it correctly, it should work no problem.
·· Repeat after me... ProSupport is the best... Prosupport is... ··
ProSupport Host Support System - OUT NOW! Grab a copy yourself and see what the hype is about!
VertiHost Inc. - We run a quality business. Do you?
-
04-14-2005, 01:02 AM #3Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
Oke.. now I found out this far..
Although.. I still have some problems with getting the text to be filled in my config between the " and ";
like $sendip=""; I would want my users to either specify yes/no in the install script, but using above method would give this output in the configfile:
$sendip="";yes
and not place it inside the " and ";
Heres my config:
<?php
$cool1="thisis";
$cool2="atest";
?>
Heres part of my index:
<html>
<TITLE><? $title; ?></TITLE>
<form method="POST" action="install.php">
<table class=mtable>
<tr>
<td class=mtext>
cool1:
</td>
<td><input type="text" name="cool1">
</td>
</tr>
<tr>
<td class=mtext>
cool2:
</td>
<td><input type="text" name="cool2">
</td>
</tr>
</td>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input type="submit" value="Create"></td>
</tr>
</table>
</form>
</table>
</body>
</html>
And here's my install.php:
<?php
function writeFile($file, $data)
{
if (!is_writable($file))
{
die("File does not exist or is not writable");
}
else
{
if (!$fp = fopen($file, "a"))
{
die("Cannot open file ($file)");
}
else
{
if (fwrite($fp, $data) === false)
{
die("Cannot write to file ($file)");
}
fclose($fp);
}
}
}
// Call the function with the correct data
writeFile("config.php", "cool1\r\ncool2");
?>
When using the form on index file, it POST to the install.php which are supposed to edit config.php, but when I do it and look at my config.php afterwards it looks like this:
<?php
$cool1="thisis";
$cool2="atest";
?>cool1
cool2
Is there any way I could get it to insert it inside the " and ";
Thanks in advance for all answeres I may get..
~UrlGuy