Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   More PHP help needed! (http://zelaron.com/forum/showthread.php?t=46189)

Goodlookinguy 2008-06-25 08:11 AM

More PHP help needed!
 
Alright! I've practiced a ton of php and am learning more and more. Now, I've figured out how to make an admin area (secure login/logout) with a page creator, page editor, and IP logger. The page editor is actually what I need help with as of right now.

I'm using a rather strange method to edit things. Really what I want is to edit the raw data. As of right now, I'm editing the data output. I've yet to figure out how to edit any other way. So, please take a look and tell me a better way with this.


index.php
Code:

<?php

// Page asks for user cookie of proof of signed in.  If not, then use is given the login page.

if ($_GET['function']=="newpage" && isset($_COOKIE['HIDDEN'])) {
        include('inc/main.php');
        }
elseif ($_GET['function']=="editpage" && isset($_COOKIE['HIDDEN'])) {
        include('inc/editpage.php');
        }
elseif ($_GET['function']=="editpage" && $_GET['data']=="process" && isset($_COOKIE['HIDDEN'])) {
        include('inc/editpage.php');
        }
elseif ($_GET['function']=="logged" && isset($_COOKIE['HIDDEN'])) {
        include('inc/logging.php');
        }
elseif (isset($_COOKIE['HIDDEN'])) {
        include('inc/main2.php');
        }
else {
        include('login.php');
        }
?>



index.php?function=editpage
Code:

                  <form id="form1" name="form1" method="post" action="index.php?function=editpage&data=process">
            <label>File Name (e.g. file.php - Look below for folder contents)<br />
            <input name="pageopen" type="text" value="" />                 
            <br /></label>
                        <label>[To edit pages from the admin folder type "./" without the quotes.]<br />Folder Location (e.g. ../ or /site/)<br />
                        <input name="pageloc" type="text" value="" />
            </label>
            <input name="Submit" type="submit" value="Submit" />
                  </form>
          <br />
        <form action="fedit.php" method="post">
        <label>Edit File (Once File is Opened)<br />
        <textarea name="edit" cols="60" rows="25">
<?php
if (isset($_REQUEST['pageopen']) && isset($_POST['pageloc'])) {
$thepage = $_POST['pageopen'];
$thedir = $_POST['pageloc'];
chdir("$thedir");
include("$thepage");
}
else {
echo "";
}
?>
</textarea>
        </label>
        <input name="pagename" type="text" value="<?php
                if (isset($_POST['pageloc'])) {
                        $thepage = $_POST['pageopen'];
                        echo "$thepage";
                        }
                else
                        echo "";
                ?>" />
        <input name="pagedir" type="text" value="<?php
                if (isset($_POST['pageloc'])) {
                        $thedir = $_POST['pageloc'];
                        echo "$thedir";
                        }
                else
                        echo "";
                ?>" />
        <input name="submitter" type="submit" value="Save" />
        </form>


fedit.php
Code:

<?php
if (isset($_COOKIE['HIDDEN'])) {
        header("Location: index.php?function=editpage");
        $thepage = stripslashes($_POST['pagename']);
        $thedir = $_POST['pagedir'];
        $edit = stripslashes($_POST['edit']);
        chdir("$thedir");
        unlink("$thepage");
        $fp = fopen("$thepage", "a");
        fwrite($fp, "$edit");
        fclose($fp);
        exit;
        }
else {
        header("Location: index.php?function=editpage");
        }
?>

So, I don't believe there are any more pages that need to be defined to understand this.

WetWired 2008-06-25 11:42 AM

I have no idea what you're showing me.

Goodlookinguy 2008-06-25 01:07 PM

Quote:

Originally Posted by WetWired (Post 642194)
I have no idea what you're showing me.


If you make the pages you will see and understand what I did.

This is a page editor. I am using the second code that I made to call other pages via include within the text box.

I am using the 3rd code to delete then make the pages ("update").

I need to know how I would pull raw data into the box instead of pulling output data.

WetWired 2008-06-25 02:50 PM

htmlspecialchars?
I don't see why you would want to do what you're doing, though.

Goodlookinguy 2008-06-25 05:05 PM

Quote:

Originally Posted by WetWired (Post 642235)
htmlspecialchars?
I don't see why you would want to do what you're doing, though.


I'm creating a website for my neighbors company. Basically he needs me to create a insite page creator and editor. The page creator wasn't an issue, but the page editor was another story. I had to think outside the box when creating it. But I can't pull raw data from the server, only output data.

It is important that I finish it by next week Friday. $50 for me!

WetWired 2008-06-25 06:18 PM

file_get_contents

Still sounds like a bad idea.

Goodlookinguy 2008-06-26 10:07 AM

Quote:

Originally Posted by WetWired (Post 642289)
file_get_contents

Still sounds like a bad idea.


Thank you WW. I had to look up the function since I'd not not heard of it. I figured out that I had to use echo file_get_contents($file);

I know it sounds like a bad idea but I am serving the customer. I have to do what the customer wants. That's just the way things work, for now anyways.

WetWired 2008-06-26 11:32 AM

Don't forget to htmlspecialchars. Otherwise, you won't be able to have a textarea in the file being edited.

I sent you an example of a better way to run a site on ICQ.


All times are GMT -6. The time now is 03:02 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.