Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2010, 08:58 PM   PM User | #1
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
Page help please

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.
wincode is offline   Reply With Quote
Old 01-27-2010, 09:17 PM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Yes you can do this, and if you need to edit a file that is back a folder you use ../
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Users who have thanked masterofollies for this post:
wincode (01-30-2010)
Old 01-27-2010, 09:58 PM   PM User | #3
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
ohh I see
so how would I make it so that a page is created?
wincode is offline   Reply With Quote
Old 01-28-2010, 02:07 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
wincode (01-30-2010)
Old 01-28-2010, 09:34 PM   PM User | #5
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
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.

Code:
<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.
wincode is offline   Reply With Quote
Old 01-28-2010, 10:00 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.


.

Last edited by mlseim; 01-28-2010 at 10:03 PM..
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
wincode (01-30-2010)
Old 01-28-2010, 11:33 PM   PM User | #7
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
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.
wincode is offline   Reply With Quote
Old 01-29-2010, 01:43 AM   PM User | #8
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Database is way more simple than using text files.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 01-29-2010, 02:44 AM   PM User | #9
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
wincode (01-30-2010)
Old 01-30-2010, 12:46 AM   PM User | #10
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
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...
wincode is offline   Reply With Quote
Old 01-30-2010, 04:14 AM   PM User | #11
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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 Code:
<?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);
}

?>

.
mlseim is offline   Reply With Quote
Old 01-30-2010, 11:26 PM   PM User | #12
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
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 ):
wincode is offline   Reply With Quote
Old 01-31-2010, 12:18 AM   PM User | #13
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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...=f&aqi=g10&oq=

The first hit will most likely be the PHP Manual.
mlseim is offline   Reply With Quote
Old 01-31-2010, 12:28 AM   PM User | #14
wincode
Regular Coder

 
Join Date: Jan 2010
Posts: 153
Thanks: 53
Thanked 0 Times in 0 Posts
wincode is an unknown quantity at this point
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! (:
wincode is offline   Reply With Quote
Old 01-31-2010, 01:25 AM   PM User | #15
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:38 PM.


Advertisement
Log in to turn off these ads.