Results 1 to 2 of 2

Thread: Single editable page script won't work

  1. #1
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Single editable page script won't work

    Code:
    <?php
    
    /***************************************************\
    * Easy-edit page script by anger2headshot           *
    * Version 0.1                                       *
    * http://a2h.uni.cc                                 *
    * an a2h project                                    *
    * licensed under CC-BY-NC-ND-2.5-AU                 *
    \***************************************************/
    
    ////////////////////////////////////////////////////////
    // configure here                                     //
    ////////////////////////////////////////////////////////
    // username
    $user1name="username";
    // password
    $pass1word="password";
    // page name
    $pagename="gmcrnews";
    
    ////////////////////////////////////////////////////////
    // dont edit further unless you know what youre doing //
    ////////////////////////////////////////////////////////
    
    // page location
    $pageloc = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER["SCRIPT_NAME"];
    
    // check whether data exists
    if (file_exists($pagename.".dat")) {
    	$pagemade=1; $pagecontents = file_get_contents($pagename.".dat");
    }
    else {
    	$pagemade=0; $pagecontents=""; $file=fopen($pagename.".dat","x"); fclose($file);
    }
    
    // check whether logged in
    if ($_POST["username"]==$user1name) {
    if ($_POST["password"]==$pass1word) { $logged=true; } else { $logged=false; }
    } else { $logged=false; }
    
    // editing the page?
    if ($_POST["submitting"]=="lolz") {
    	$file=fopen($pagename.".dat","w");
    	fwrite($file,$_POST["newcontent"]);
    	fclose($file);
    	$edited=1;
    } else { $edited=0; }
    
    // check whether user wants raw data, if so, give the data and exit
    if ($_GET["raw"]==1) { if ($pagemade==1) { echo $pagecontents; exit(); } }
    ?>
    <html>
    <head>
    <title>Easy-edit page script by anger2headshot</title>
    </head>
    <body>
    <?php
    // not logged in? time to login...
    if ($logged==false) {
    echo 'Please login to edit this page.<br />
    <form action="' . $pageloc .'" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
    <input type="submit" value="Login" /></form>';
    } else {
    ?>
    Logged in.<br />
    <?php if ($edited==1) { echo '<b>Your edit has been saved!</b><br />';} ?>
    <form action="<?php echo $pageloc; ?>" method="post">
    <input type="hidden" name="submitting" value="lolz" />
    <textarea rows="5" cols="30" name="newcontent">
    <?php echo $pagecontents; ?>
    </textarea><br />
    <input type="submit" value="Edit page" /></form>
    <?php
    }
    ?>
    </body>
    </html>
    I've just written this, but for some reason, logging in won't work, and even if I remove the login part, editing the page doesn't work either. What's wrong with my coding? The folder has CHMOD 777 and the data file was created by the script...
    Last edited by rctxtreme; 07-24-2007 at 11:41 AM. Reason: removed username/password

  2. #2
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmm, firstly, shouldn't posted variables be incased in single quotes not double?

    Also wherever $pagename is mentioned, do the quotes have to be around .dat?

    E.g. instead of:
    PHP Code:
    file_get_contents($pagename.".dat"); 
    Use:
    PHP Code:
    file_get_contents($pagename.dat); 
    Also, to set text to a variable incase it with quotes? (note the single quotes around the posted info)
    PHP Code:
    // check whether logged in
    if ($_POST['username']==$user1name) {
    if (
    $_POST['password']==$pass1word) { $logged="true"; } else { $logged="false"; }
    } else { 
    $logged="false"; } 
    And finally, use single quotes around false maybe?
    PHP Code:
    if ($logged=='false') {
    echo 
    'Please login to edit this page.<br />
    ... 

Bookmarks

Posting Permissions

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