View Full Version : Edit a php file with a form?

06-22-2006, 04:01 AM
What I want to do is to make a page that will edit these varibles without uploading a file.

// Guildsofwarcraft.net //
// Version 1.0 //

# StyleSheets
$stylesheet = "main.css"; // Main CSS for site
$browserfix = "browserfix.css"; // Broswer fix to keep same look on IE and FireFox

# Site Name / Copyright
$title = "Guilds of WarCraft"; // Website name
$descrip = "Finding Guilds Made Easy"; // Small Description for the Titlebar
$copyright = "Copyright 2005 - Guildsofwarcraft.net";

# Notice
$show = yes; // Show the notice on the main page - (yes/no)
$notice_on = "notice.php"; // Notice Location
$notice_off = "blank.php"; // Blank File


I want to create the form below:

Style Sheet: [ text field for URL/path ]
BrowserFix : [ text field for URL/path ]

Title: [ text field ]
Description: [ text field ]
Copyright: [ text field or URL ]

Notice: Yes () No () <--These are radio button.
Notice File: [ text field for URL/path ]
Notice Blank: [ text field for URL/path ]

Is there a way to do this? Or maybe make the forum apart of the config file and require a password?

06-22-2006, 05:11 AM
You can save your values into a text file that will server as your settings file. This way, you&#180;ll leave your PHP scripts untouched!

Save the following code into a php file, for example settings.php and make sure noone can access it but you.

$file = "my_settings.txt";

// Take care of the form
if (isset($_POST['submit'])) {
$value[] = trim($_POST['stylesheet']);
$value[] = trim($_POST['browserfix']);
$value[] = trim($_POST['title']);
$value[] = trim($_POST['description']);
$value[] = trim($_POST['copyright']);
$value[] = $_POST['show'];
$value[] = trim($_POST['notice_on']);
$value[] = trim($_POST['notice_off']);

// Open the file...
$handle = fopen($file, "w");

// Save the settings...
foreach($value as $key => $op) fwrite($handle, "$op\n");

// Close the file

// Reload the page, just to prevent the form from being re-submited on page refresh
header("Location: sender.php");

$load = file($file);
list($stylesheet, $browserfix, $title, $description, $copyright, $show, $notice_on, $notice_off) = $load;
<form method="post" action="">
<td><input type="text" name="stylesheet" value="<?=$stylesheet;?>" /></td>
<td><input type="text" name="browserfix" value="<?=$browserfix;?>" /></td>
<td><input type="text" name="title" value="<?=$title;?>" /></td>
<td><input type="text" name="description" value="<?=$description;?>" /></td>
<td><input type="text" name="copyright" value="<?=$copyright;?>" /></td>
<td><?php if (trim($show) == "yes") {
echo "Yes<input type=\"radio\" name=\"show\" value=\"yes\" checked=\"checked\" /> / No<input type=\"radio\" name=\"show\" value=\"no\" />";
} else {
echo "Yes<input type=\"radio\" name=\"show\" value=\"yes\" /> / No<input type=\"radio\" name=\"show\" value=\"no\" checked=\"checked\" />";
} ?></td>
<td>Notice On:</td>
<td><input type="text" name="notice_on" value="<?=$notice_on;?>" /></td>
<td>Notice Off:</td>
<td><input type="text" name="notice_off" value="<?=$notice_off;?>" /></td>
<td colspan="2" style="text-align: right"><input type="submit" name="submit" value="Save Settings" /></td>

then where you want to load your settings, do like this:

$load = file("my_settings.txt");

// Remove the \n (linebreaks) from the array
foreach ($load as $key => $value) $load[$key] = trim($value);

// Define the variables
list($stylesheet, $browserfix, $title, $description, $copyright, $show, $notice_on, $notice_off) = $load;

06-22-2006, 05:53 AM
WOW, thanks. When I get home I'll test it out.

So For this:

$load = file("config.txt");

// Remove the \n (linebreaks) from the array
foreach ($load as $key => $value) $load[$key] = trim($value);

// Define the variables
list($stylesheet, $browserfix, $title, $description, $copyright, $show, $notice_on, $notice_off) = $load;

I want to create new .txt file just for the varibles? So nothing is in the config file.

06-22-2006, 07:37 AM

06-22-2006, 07:42 AM
Is there a way to make a php file that get all varibles and allows you to edit/delete/add?

Like I have a config.php, then I have admin.php

With the admin.php it takes the config.php and allows you to add varibles.

So like
note: {} are text fields.

{$valuehere} = {what it equals here} [add]

Then at the top it shows. It grabs all values in the config file.

$value = what is equals here [edit | delete]