Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Edit a php file with a form?

    What I want to do is to make a page that will edit these varibles without uploading a file.

    PHP Code:
    <?php
    //////////////////////////
    // 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?

  • #2
    New Coder
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    49
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.

    PHP Code:
    <?php
    $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 => $opfwrite($handle"$op\n");

    // Close the file
    fclose($handle);

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

    $load file($file);
    list(
    $stylesheet$browserfix$title$description$copyright$show$notice_on$notice_off) = $load;
    ?>
    <form method="post" action="">
    <table>
    <tr>
        <td>StyleSheet:</td>
        <td><input type="text" name="stylesheet" value="<?=$stylesheet;?>" /></td>
    </tr>
    <tr>
        <td>Browserfix:</td>
        <td><input type="text" name="browserfix" value="<?=$browserfix;?>" /></td>
    </tr>
    <tr>
        <td>Title:</td>
        <td><input type="text" name="title" value="<?=$title;?>" /></td>
    </tr>
    <tr>
        <td>Description:</td>
        <td><input type="text" name="description" value="<?=$description;?>" /></td>
    </tr>
    <tr>
        <td>Copyright:</td>
        <td><input type="text" name="copyright" value="<?=$copyright;?>" /></td>
    </tr>
    <tr>
        <td>Show:</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>
    </tr>
    <tr>
        <td>Notice On:</td>
        <td><input type="text" name="notice_on" value="<?=$notice_on;?>" /></td>
    </tr>
    <tr>
        <td>Notice Off:</td>
        <td><input type="text" name="notice_off" value="<?=$notice_off;?>" /></td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: right"><input type="submit" name="submit" value="Save Settings" /></td>
    </tr>
    </table>
    then where you want to load your settings, do like this:
    PHP Code:
    $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
    Last edited by Nicklas; 06-22-2006 at 05:21 AM.

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WOW, thanks. When I get home I'll test it out.


    So For this:
    PHP Code:
    $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.

  • #4
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    fixed.
    Last edited by Donnerschlag; 06-22-2006 at 12:42 PM.

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •