...

View Full Version : Page help please



wincode
01-27-2010, 08:58 PM
Hey guys. I was wondering if it's possible to have a page say /admin.php, where I can create new pages from?
I want to be able to create new pages from another page on my site, like /admin.php
On that page, I'd have a form for the page's properties, like file name. Could anyone assist me in doing this?
I'm really new to php and want to get better.

masterofollies
01-27-2010, 09:17 PM
Yes you can do this, and if you need to edit a file that is back a folder you use ../

wincode
01-27-2010, 09:58 PM
ohh I see
so how would I make it so that a page is created?

mlseim
01-28-2010, 02:07 PM
What do you consider a "page" ... not sure what you mean by that.

Are you talking about creating a text file (for content)?
Usually, you don't create a "page", as in an HTML or PHP web page ...
you create the text or content for another script to use ... which generates
the HTML "page". Typically using a database, like MySQL.

wincode
01-28-2010, 09:34 PM
Yes. Here I'll explain.
I'm trying to make a site so that I don't have to edit it by uploading files to ftp to make small changes like adding news or links. I'd also like to be able to create a new page.
Here below is what it would look like.


<html>
<body bgcolor=FFFFFF>

<a href="http://www.MYSITE.com/home.php">HOME</a> - <a href="http://www.MYSITE.com/news.php">NEWS</a> - <a href="http://www.MYSITE.com/coollinks.php">COOL LINKS</a> -
</br>

This is the homepage.
</body>
</html>

I want to have a page, where I can edit what it says in home.php in the part where it says "This is the homepage". The same thing goes for news.php and coollinks.php.

But I'd also want to be able to add a new page, but I'll do that later when I'm able to do this.

Thanks a lot for your help.

mlseim
01-28-2010, 10:00 PM
That is called a CMS (content management system).
Somehow, you either need to use a database (like MySQL),
or a simpler text (flat-file) database, or at a minimum, some plain text files.

Let's go with the most basic, plain text files ...

The first step is to create the text you want and save it in files.
You might want to do them in sections, like:
n1.txt, n2.txt, n3.txt for paragraphs of news,
and l1.txt,l2.txt,l3.txt for paragraphs (or content) for links.

Create those text files and put text in them (you can also put HTML in them).
Upload them all into a directory called "content".

Then, wherever you want them to appear, you do this:
<?php include("./content/n1.txt")?>

The PHP script will take the contents of "n1.txt" and display it at that spot.

Do that for all of your content.

The next step is to find a simple PHP editor to edit those text files,
or edit them using notepad and upload them. The PHP editor is something
you can do later, when you learn more about PHP.

But the PHP "includes" is the most basic, first step, to putting content on your page,
without using a database (like MySQL). Eventually, you'll be wanting to get more
elaborate and learn MySQL.


.

wincode
01-28-2010, 11:33 PM
Ahh perfect. I can do the text files easily. But I would really like to have the editor so that I don't have to edit in notepad and upload.

masterofollies
01-29-2010, 01:43 AM
Database is way more simple than using text files.

mlseim
01-29-2010, 02:44 AM
Database is more simple and more powerful for experienced people,
but in his case, he'll need to know MySQL and set-up
variables, and the coding to read and write the database.

The "point" is ... MySQL is simpler for an experienced programmer.

Wincode ...
How far are you planning on going with your site?
Adding dozens or hundreds of "content" paragraphs?
Searching, sorting, dating them, etc?

We can't teach you a whole programming class on this forum,
so I would say ... you have a start on it, where do you want
to go from here?

wincode
01-30-2010, 12:46 AM
No I want it very simple.
I just want 4-5 pages, in which I can update regularly.. I want maybe one master paragraph for each page, where I can change and add to the paragraph (but possibly be able to add links (without coding), images, and file uploading, so in other words a veryy simple editor). But I guess those are complex, so at the moment I just want to be able to add/change text to the pages.

Thank you so much for your help!

I think I have an idea of how it would work..
What I would have is connect to the database and set up a 5 variables (each for a page paragraph). Then on the page where I edit my pages, I would have the editors. And what the editors would do is display what each variable has. Say one of the vairables is $page1, then I can view what's in it and change it/add to it.
Then on www.mysite.com/page1.php , I'd have an include statement to include the variable $page1.
But my problem is I don't know how to do it...

mlseim
01-30-2010, 04:14 AM
Below is the simplest online text editor ever ... no security, no frills ...

Make sure all of your text files have CHMOD permissions set to 0777 (or 777),
using your FTP program ... you can set those permissions, so you can write to them.




<?php
// Give this script a name like, "edit.php"
// Very simple text editor.
// To edit one of your files, call it like this:
// <a href="edit.php?p=n1.txt">Edit n1.txt</a>

// There is no error checking, no security,
// just a plain text editor.

if(isset($_POST['action'])){
$action=$_POST['action'];
}
if(isset($_POST['textarea'])){
$textarea=$_POST['textarea'];
}

if(isset($_GET['p'])){
$p=$_GET['p'];
}

$url = $p;

// Get page
$data = implode("", file($url));

if($action=="save"){
$newtext=stripslashes($textarea);
$newtext = str_replace("<?", "", $newtext);
$newtext = str_replace("?>", "", $newtext);
$newtext = nl2br($newtext);
$fh = fopen($url, 'w') or die("can't open file");
fwrite($fh, $newtext);
fclose($fh);
// where to go after they click "update"
header ("location: page.php?p=$url");
}
else{
echo"
<html>
<head><title>Simple Text Editor</title>
<style>
body,html{
margin:0px auto;
width:700px;
text-align:center;
}
#content{
margin:0px auto;
width:700px;
}
#middle h1 {
color: transparent;
font-family:georgia;
font-size:12pt;
margin:0;
color: #dF9100;
padding:10px 0px 15px 0px;
text-align:left;
}
</style>
<body>
<div id='content'>
";

$ta=br2nl($data);
// where to return to, if they click "return" ...
$return="index.php";

echo"
<a href='$return'><-- Return to Page</a><br /><br />
Make Changes and click \"Save Changes\" at the very bottom ...<br />
<form action='edit.php' method='post'>
<input type='hidden' name='action' value='save'>
<input type='hidden' name='p' value='$page'>
<input type='hidden' name='n' value='$n'>
<textarea name='textarea' rows='25' cols='80'>$ta</textarea>
<br />
<input type='submit' name='submit' value='Save Changes'>
</form>

<div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'>

</div>
</div>
</body>
</html>
";
}

function br2nl($str) {
return preg_replace('=<br */?>=i', "", $str);
}

?>



.

wincode
01-30-2010, 11:26 PM
Ahh great! Thanks a lot (:
So this isn't database based?

Also, what does "implode("", file($url))" do?
I'm getting an error after I click "Save Changes":

Warning: implode() [function.implode]: Invalid arguments passed in /home/USERNAME/public_html/php/edit.php on line 26
can't open file


So I made a txt file and then I chmod it to 777. Then I called it with edit.php?p=
and then clicked Save Changes, which is when I got the error.

Hmm, I wish I knew php ):

mlseim
01-31-2010, 12:18 AM
my bad ... I see the error ...

Change this line:
<input type='hidden' name='p' value='$page'>

To this:
<input type='hidden' name='p' value='$url'>

===================

For all of your PHP questions, there is an online PHP manual for everything:
http://php.net/manual/en/function.implode.php

Use Google and search for PHP things using the word "PHP" and then the command:
Like this: PHP date
http://www.google.com/search?hl=en&q=php+date&aq=f&aqi=g10&oq=

The first hit will most likely be the PHP Manual.

wincode
01-31-2010, 12:28 AM
Hmm, I'm still getting the same error.

Also, on the edit.php?p=blahblah, there are two "Save Changes" buttons. In between them is this text ""; } function br2nl($str) { return preg_replace('=
=i', "", $str); } ?>"

Thank you so, so much! I really appreciate it! (:

masterofollies
01-31-2010, 01:25 AM
Can you post your coding 5 lines above and 5 lines below that error? or just the whole function? I would like to help tackle this problem.

wincode
01-31-2010, 03:33 AM
Okay, thanks!!


<html>
<body bgcolor=FFFFFF>
<?php
// Give this script a name like, "edit.php"
// Very simple text editor.
// To edit one of your files, call it like this:
// <a href="edit.php?p=n1.txt">Edit n1.txt</a>

// There is no error checking, no security,
// just a plain text editor.

if(isset($_POST['action'])){
$action=$_POST['action'];
}
if(isset($_POST['textarea'])){
$textarea=$_POST['textarea'];
}

if(isset($_GET['p'])){
$p=$_GET['p'];
}

$url = $p;

// Get page
$data = implode("", file($url));

if($action=="save"){
$newtext=stripslashes($textarea);
$newtext = str_replace("<?", "", $newtext);
$newtext = str_replace("?>", "", $newtext);
$newtext = nl2br($newtext);
$fh = fopen($url, 'w') or die("can't open file");
fwrite($fh, $newtext);
fclose($fh);
// where to go after they click "update"
header ("location: page.php?p=$url");
}
else{
echo"
<html>
<head><title>Simple Text Editor</title>
<style>
body,html{
margin:0px auto;
width:700px;
text-align:center;
}
#content{
margin:0px auto;
width:700px;
}
#middle h1 {
color: transparent;
font-family:georgia;
font-size:12pt;
margin:0;
color: #dF9100;
padding:10px 0px 15px 0px;
text-align:left;
}
</style>
<body>
<div id='content'>
";

$ta=br2nl($data);
// where to return to, if they click "return" ...
$return="index.php";

echo"
<a href='$return'><-- Return to Page</a><br /><br />
Make Changes and click \"Save Changes\" at the very bottom ...<br />
<form action='edit.php' method='post'>
<input type='hidden' name='action' value='save'>
<input type='hidden' name='p' value='$url'>
<input type='hidden' name='n' value='$n'>
<textarea name='textarea' rows='25' cols='80'>$ta</textarea>
<br />
<input type='submit' name='submit' value='Save Changes'>
</form>

<div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'>

</div>
</div>
</body>
</html>
";
}

function br2nl($str) {
return preg_replace('=<br */?>=i', "", $str);
}

?>
</body>
</html>

mlseim
01-31-2010, 03:22 PM
What did you call your script ... "edit.php"?

It makes a difference what you've called.

wincode
01-31-2010, 05:20 PM
Oh sorry. My last post's code is edit.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum