开发者

PHP $_POST not being passed through from textarea

开发者 https://www.devze.com 2023-01-29 20:10 出处:网络
I have the following script to ask for a password and then ask the user if they want to edit a page. Click on a page opens it up in the \'<textarea>\', the save button should then send the conte

I have the following script to ask for a password and then ask the user if they want to edit a page. Click on a page opens it up in the '<textarea>', the save button should then send the content of the text area to the script again for writing. (I am aware that this isn't the safest way of authenticating, if there is any way of doing this without SQL I'd like to hear it.)

The problem is that the content of the text area isn't being passed through to the updateFile() function.

<?
session_start();
$pass = 'generic_password';
$login ='<form action="?page=admin" method="post">
        Password: <input type="password" name="pass" />
        <input type="submit" />
        </form>'; 
function updateFile($file){
    $area=$_POST['area'];
    $fd=fopen($file,"w");
    fwrite($fd,$area);
    fclose($fd);
    echo $file.' has been saved';
    }
if (!isset($_POST['pass']) && $_SESSION['authe开发者_如何学JAVAd'] == false){
    echo $login;  
    $_SESSION['authed'] = false;
    }
elseif ($_POST['pass'] == $pass || $_SESSION['authed'] == true){
    $_SESSION['authed'] = true;

    if(isset($_POST['submit'])){
        updateFile($_POST['file']);
    }

    echo "Select a page to edit<br/>";
    echo "<ul>";
    foreach (glob("{*.html,*.css}",GLOB_BRACE) as $x){
        echo "<li> <a href=\"?page=admin&edit=$x\">$x </a></li>";
    }
    echo "</ul>";
    if (isset($_GET['edit'])){
        echo '<script type="text/javascript" src="nicEdit.js"></script> 
              <script type="text/javascript"> 
                bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
              </script> ';
        echo '<form method="post" action="?page=admin">You are editing: <a name="file">'.$_GET['edit'].'</a> <textarea name="area" style="width:920px;">';
        include $_GET['edit'];
        echo '</textarea>
              <input name="submit" value="Save" type="submit" />
              </form>';
    }
}
else
    echo "something went wrong";

?>


<input name="submit" value="Save" type="submit" />

the above never converted to $_POST['submit']


Nothing is passed in updateFile function. I doubt how you are able to open the file

There is <a> element with the name file Which will not available in $_POST

if(isset($_POST['submit'])){
    updateFile($_POST['file']);
}


Probably You're wrong over here:

if(isset($_POST['submit'])){
  updateFile($_POST['file']);
}

Here you're taking away an input file. where in your form there does not any such field exist, only an anchor tag is there with such name and $_POST can not take away the data inside an anchor tag. So its better to keep there a field for file name seperately like,

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消