Page 1 of 1

not linking correctly (fread etc..)

Posted: Thu Nov 13, 2003 10:11 pm
by d3ad1ysp0rk
Edit.php:

Code: Select all

<?php
if($pass!="***"){
    echo "
    Please Enter The Password to Continute:
    <form action='$PHP_SELF' name="passform" method="post">
    <input type="text" name="pass" value="Enter Password" size="20">
    <input type="hidden" name="s1d" value="yes">
    <input type="submit" value="Submit" name="submit">
    </form>
    ";
}
else if($pass=="****"){
    if($page!=""){
        if($save == "Save"){
            $filename = "$page.html";
            $file = fopen( $filename, "w");
            fwrite($file, $textarea);
            fclose( $file );
            header('location: index.php');
        }
        else{
            $filename = "$page.html";
            $file = fopen( $filename, "r" );
            $filesize = filesize( $filename );
            $text = fread( $file, $filesize );
            fclose  ( $file );

            echo ("<form name="form" method="post" action="">\n");
            echo ("<textarea name="textarea" cols="100" rows="20">\n");
            echo $text;
            echo ("</textarea>\n");
            echo ("<br>\n<input type="submit" name="save" value="Save">\n");
            echo ("<input type="hidden" name="page" value="$page"\n>");
            echo ("<input type="hidden" name="pass" value="$pass"\n>");
            echo ("</form>\n");
        }
    }
    else{
        echo "
        <form action='$PHP_SELF' name="pageform" method="post">
        <table width="400" cellspacing="0" cellpadding="0">
        <tr>
        <td valign="top" width="100">Page Name:</td>
        <td valign="top" width="100"><input type="text" name="page" size="20"></td>
        </tr>
        <tr>
        <td></td>
        <td valign="top" width="100"><input type="hidden" name="pass" value="$pass"><input type="submit" value="Log-In"></td>
        </tr>
        </table>
        </form>
        Page Key:<br>
        Home Page = homepage<br>
        Method = method<br>
        Links = links<br>
        Stats = stats<br>
        ";
    }
}
else
{
    echo "Error In Processing. Please press back and try again";
}
?>
I made this for my friend.
I host his site (because he needed a guestbook and freewebs doesnt allow php), but i dont want to give him ftp access, since he doesnt know what he's doing, so i made a page that allows him to select which page to edit and then edit it inside of a textarea.

Only problem is when you use <a href="http://www.site.com"></a> the quotes get escaped.. and even trying to escape them (typing <a href=\"site.com\"> just makes it worse..

any ideas on how to save the text file with the quotes intact?

-thanks
btw, here's links.html (a page that is editable), so you can see what happens:

Code: Select all

Links:&lt;br&gt;
- &lt;a href=&quote;http://www.404-design.net/pbk/index.php&quote;&gt;Home Page&lt;/a&gt;&lt;br&gt;
- &lt;a href=&quote;http://www.404-design.net/pbk/method.php&quote;&gt;Trophy Method&lt;/a&gt;&lt;br&gt;
- &lt;a href=&quote;http://www.404-design.net/pbk/guestbook.php&quote;&gt;Guestbook&lt;/a&gt;&lt;br&gt;
- &lt;a href=&quote;http://www.xxxx/page.php?x=996468&quote; target=&quote;_blank&quote;&gt;Support the Site&lt;/a&gt;&lt;br&gt;
- &lt;a href=&quote;http://www.stock-wars.com/&quote; target=&quote;_blank&quote;&gt;Stock-Wars&lt;/a&gt;&lt;br&gt;
(it adds more \s everytime i load and save it)

Posted: Fri Nov 14, 2003 3:20 am
by twigletmac
It's because the slashes are being added when the page is submitted - you can remove them before writing the changes to the file, by using [php_man]stripslashes[/php_man]() on the text, e.g.:

Code: Select all

if($save == "Save"){
    $textarea = stripslashes($textarea);
    $filename = "$page.html";
    $file = fopen( $filename, "w");
    fwrite($file, $textarea);
    fclose( $file );
    header('location: index.php');
}
Mac