Oh, I was just so darned proud of myself! I had managed to have a page where a client could add a password to the end of a URL, then edit the contents of a page, then have those altered contents appear so nicely as alerts on the bottom of her homepage.
Problem is that it didn't let the client post a URL. She needs to post a URL.
I'm thinking to use the 'include()' command, instead of what I've got.
Here's what I've got:
<?PHP
if ($_POST['pw']!="") {$pw=$_POST['pw'];}else{$pw=$_GET['pw'];}
$newcontent=$_POST['newcontent'];
$filelocation = "mytext.txt";
if (!file_exists($filelocation)) {
echo "Couldn't find datafile, please contact administrator!";
}
else {
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
}
$content = stripslashes($content);
$content = htmlentities($content);
$pass="password";
if (!$pw || $pw != $pass){
$content = nl2br($content);
echo $content;
}
else {
if ($newcontent){
$newcontent = stripslashes($newcontent);
$newfile = fopen($filelocation,"w");
fwrite($newfile, $newcontent);
fclose($newfile);
echo 'Text was edited.<form><input type="submit" value="see changes" /></form>';
}
else{
echo '<form method="post"> <textarea name="newcontent" cols="80" rows="15" wrap="virtual">';
echo $content;
echo '</textarea><input type="hidden" name="pw" value="'.$pass.'" /> <br /><input type="submit" value="edit" /></form>';
}
}
?>
What I'm not clear on is what to replace with include and how to do it.
I'd still like it to be editable.
Here are the lines I totally don't understand and would like help understanding:
if ($_POST['pw']!="") {$pw=$_POST['pw'];}else{$pw=$_GET['pw'];}
I'm assuming that this means that this has something to do with the method of passing the password via post or get. If the pw variable has a value at all, then let that value be the value of the post value? If not, then let it be the value of the get?
$newcontent=$_POST['newcontent'];
Does this mean that the variable $newcontent is initialized at having the value of the post of the same? (I think I'm not understanding this post thing very well. Is it like this: if something is sent using POST or GET, then its value retrieved is the$_POST['variablename'], for example: $pw=$_POST['pw']; ? )
$content = nl2br($content);
I have no idea what nl2br does. I don't know how to find out. Is there a link to a dictionary where I could find it?
$content = htmlentities($content);
I was thinking that all I'd have to do would be to remove this line, but after thinking for a minute, I didn't even try it. What happens when I put code into this now, like bold tags, is that resulting page shows the code, including the link href code which is what my clients are interested in. (I'd also like to give them the option of bold tags and one of them knows how to do unordered lists and would be put out if she can't do it.) So it looks like 'include' is my answer.
I think.
My problem with thinking about this is that the whole snippet starts with making the content from the page into a variable. I don't think include is that complicated. I think it just includes from the other document, everything that's there, code and all, so you can piece together a document from other pieces.
If this is so, what do I do to get the document and edit it in a form field?
I would be so grateful if someone could help me here. Thank you for your patience in reading through this. I'm really glad I've found you guys. I've been working in a vacuum.
Thanks,
Lee