Jump to content

Recommended Posts

Whats going on PHPfreaks? So this is what I've been trying to do for the whole weekend and just can't figure it out.

 

I want to let users create new pages on my site like wiki style but dont want a wiki or drupal or joomla or any of that. I know its possible with:

 

$text = $_POST['text'];

$file = fopen($text . ".php","x");

fwrite($file,"Welcome to your new page!");

 

but I'm not sure how to integrate it.

 

For further clarification here's an example: You come to the site and there is a list of previously made user pages all with their own user generated name. What I want to have is a create new page button that opens a new page allows the user to upload images then submit it to the database and upon refresh of the page their page is now in the list. The create new page resets and is available for another user and on and on.

 

Any help will be appreciated. I need to get this done it's driving me crazy.

Link to comment
https://forums.phpfreaks.com/topic/235404-create-new-page-option-for-user/
Share on other sites

You spent an entire weekend working on this, and you came up with 3 lines of PHP?

 

As a cracker, i will sure love coming to your site knowing that you'll let me make a php file and stuff it full of whatever code I want and then you'll go and run that code for me.  Sure will save me time trying to actually exploit your server as I'll have my root kit installed in record time.

 

You need to step back for a minute and look for a basic "database driven website" tutorial or book, and learn some of the basics.

 

FWIW, a wiki has 3 basic properties:

- a minimal markup language that people can use to add page content, so they don't need to know a scripting language or html

- the ability of people to add/edit (within the confines of the wiki markup supported) pages, where the most frequent implementation is that the data for the pages is kept in some form of database.

- when changes are made to a page, those pages are tracked so that there is a complete history and ability to see or revert to prior versions of the page.

 

I don't see that you're looking for the key features that differentiate a wiki -- it just sounds like you want a CMS.  Since you brought up Joomla and Drupal, someone else must have suggested those to you because they match what you're looking for. 

 

I'm not trying to pick on you, but after 10 years of answering questions here, myself and the other vets have seen every variation of this type of question.  It's just not interesting to us -- you have to bring more to the table than your desire for something that you have absolutely no chance of creating yourself. 

 

 

 

 

 

Do me a favor. Next time don't answer.

 

You think three days was spent coming up with three pieces of code you can grab off php.net? How would that even be possible? What I was actually doing was trying to build the custom page application. This is new to me but PHP isn't. Granted I'm no professional but I don't need to use Drupal or Joomla. And no no one told me about those. Jesus do you guys think everyone who asks a question is a complete idiot?

 

If you're going to help ,help if not move on. I showed the three pieces of code because that will make the new page for me. Should I post every bit of security for the page since it has nothing to do with the question? I don't think so.

 

Try this answer next time: Can you give us more code to look at? But even that is irrelevant. I showed someone how to make a user/login script very simple not much security a little salt on the password and thats about it. I told him he could find better ways to make it more secure it was up to him. All he wanted was the skeleton and that's what I gave and I was hoping for something like that here. But I'm sorry for straining your precious eyes and brilliant mind on my silly question that you and other moderators has seen for ten years.

 

If thats the case just answer the question in a basic manner. Lead someone in the right direction. Do not tell them they can not do it on a first reply. And what I hate the most is when people always try to push these bullshit CMS systems on people who ask questions about PHP.

 

I'll take my three lines of code and figure it out myself figured this might speed up the process and give me some deeper insight into something I've never done.

 

Do me a favor and ban me so I dont accidentally come back here.

While I certainly don't owe you an additional reply, I'd suggest you go back and carefully re-read my reply to you.  You reacted emotionally and took personal insult.  I'm great at insulting people and if I wanted to insult you I would have written an entirely different reply.  It's like you only read the first part, where I lightheartedly pointed out that the code you provided was a horrible idea, and you lost your mind.

 

I could care less if you ever come back to this site, and really don't feel any need to ban you.  This site has some ridiculous amount of users, and gets thousands of questions every day.  This is simply the best PHP help community there is, and most certainly the most patient, so you're only hurting yourself. 

 

Nobody is pushing "bullshit CMS" systems on people.  What they are doing is seeing people who don't know the most basic things about the language come in and ask for all the features of a CMS.  Considering that these CMS's typically have man years of code in them.  I wrote a CMS with another guy at a company that was used to host 50 websites, had it's own ad serving module, user system, cluster management, and modular forum system, and served up a quarter million page views a day, so I know something about the topic.  It's non trivial and nothing I can sketch out for you or anyone else in skeleton form. 

 

I have no problem with people wanting to reinvent the wheel, so long as they approach it in pieces, and bring something to the table.  You didn't, I called you on it, and where we go from here is entirely up to you. 

First off. Apologies all around. It was late, I was frustrated. So again sorry. So unprofessional and immature of me. Let me ask again.

 

If I don't want to use drupal or joomla or something like than can you point me in a direction of reference or study that can start me on the path to learning how to do this. Many of the books I have don't cover this. Its usually the user login,registration,databases,email that sort of thing but I feel like this isn't that hard and that is what's frustrating. I can't put the pieces together.

 

By the way thanks for not banning me.

I think we need to go back to what you're looking for.  What I got right now is that you want users to be able to add pages to the site.  There is some wiki - like features you are envisioning. We need clarity on what that means.  Blogs, CMS's etc. all for the most part handle this by having a database structure that supports it.  For example, there is a "Content creation Kit" addon to Joomla named K2 that is used by a lot of Joomla users these days as a drop in replacement for the article system that comes with Joomla.  I reverse engineered the database structure they use and I think it might help you think about this some more to see how someone else accomplished this.  K2 adds tags and nested categories that in Joomla 1.5 were not part of the base system. 

 

Here's the database schema diagram:

 

k2_schema.png

 

If you look at the core columns for the table jos_k2_items you get an idea of how you could approach something like this.  There is a parent category foreign key, a title, alias (which is a version of the title that can be used as the url to the content) and then you have introtext and fulltext for the actual content stored as text columns.  There are a set of meta columns so that individual meta keywords and descriptions can be stored for the page.  There is a seperate table jos_k2_attachments that stores information about external assets needed by the page, like videos, images, pdf's etc.  The 1-M relationship between the table allows the system to track any number of these assets which can then be referenced in the article.

 

This should give you an idea of how to structure a database, although there is a lot of extra columns you wouldn't necessarily need if you wanted to keep things simple.  You want some sort of status column in the table to indicate whether the page is visible to the public, inactive, or deleted.

 

Let's assume you now need an index of all the available pages generated -- pretty easy to SELECT from the jos_k2_items and get a list of all the active articles, with an order by created or by category or however you would like.

 

You'd want a page controller that given a url like: /page/article_title.html will find the item, assemble an html version from the various database columns and present it.

 

In terms of markup supported you would need to decide what you want to support.  You could look at the various wiki markups, or use bbcode, or even a subset of html.  In almost all cases the parsing is based on using regular expressions to convert this markup into the html you will allow.  You don't want to allow any javascript or meta refresh or anything else that facilitates XSS.

 

You need forms that allow people to enter or edit new pages that then call mysql routines to store rows in the database, etc.  You indicated you had some experience with this, so I'm going to leave that to you.

 

You also need a form, which typically would be embedded to allow you to upload the images you referred to.  Just about everything you need to know about how to do that in PHP is well documented on the php manual here:  http://us3.php.net/manual/en/features.file-upload.php.  If you read that you'll be able to handle uploads and store them.  The markup system will need to intelligently understand how to convert an embedded image into an img tag that points to the location of the asset in webspace.

 

That's all I can think of at the moment, and this is already getting to be a novel. 

 

 

While gizmola laid everything out perfectly (just like a winning superbowl gameplan) for you I have a feeling that it looks a bit more intimidating than your OP had in mind.  If you re-read his first reply you'll get every bit of the answer you're looking for out of it.  Btw, bashing gizmola's help is like bitch slappin' your momma when you pop out into the new world... or taking a big dump on Socrates' gravesite... or throwing a brand new custom computer through the maker's window in spite of a missing wireless card.

 

I hate to iterate what you've already been told, but seeing as I have absolutely no clue where to begin on gizmo's last explanation (with the screenshot).. I figured you didn't either.  So in spite of that, I'll throw in my two cents.

I know its possible with:

$text = $_POST['text'];
$file = fopen($text . ".php","x");
fwrite($file,"Welcome to your new page!"); 

Pretty much.  That is absolutely what is going on.  You request some input and you put it somewhere..

 

When you throw the word "wiki" around though, you're implying that you want rich-text with images and such.  You could easily create a new html file for every user, but that would add up to a lot of files... it's really your decision.  What you don't want is for people to be able to put in malicious code, so it all boils down to what you DON'T want them to do.  You already know your goal which is to mimic a wiki system, but to mimic it you must know what not to allow and this is where this community's expertise comes in very handy.

 

Just for an example.  You don't want a user to be able to enter:

- PHP code

- Javascript

- Redirection links

- and pretty much anything that would take them away from the server... or better yet, destroy/vandalize it.

 

If you think you need to allow Javascript, then you'll need to come up with a secure way to allow it and the same goes for PHP, HTML, links, etcetera.. and in doing this you will have created a framework... which is regrettably synonymous with Joomla nowadays.  Hopefully I made some sense, otherwise I just wasted a lot of time.

Ok.First off. thanks to both of you for not shunning me.Second you're right Zanus, though super informative, gizmola's post was slightly confusing. I understand what he's doing in showing me what it takes to make this project so. But I feel what I'm doing is alot simpler but again I could be wrong. But back to what you said about the fwrite method.

 

This is going to be an image oriented site so can't I just put "if" validations in the code to make sure nothing comes through except say .jpg .gif .png and so on or am I still on the wrong path and is this out of my scope?  I think I'll just try out my method and see what happens then come back here and show you guys.

 

One issue that I'm interested in is after the form is submitted will the create new page function refresh and be ready for someone else.

 

If you're getting tired of my ramblings tell me and I'll give in to drupal or joomla for the time being until I figure this out. I just don't want all the extras they have to offer. No user profiles just user/login and create a page and maybe I'll do a comment system. Very basic.

 

Again thank to both. I understand why you responded the way you did gizmola.

If you're really focused on image uploading, then be sure to read the link I provided to the upload page of the php manual.  The code snippet you have won't work for images for reasons that are thoroughly explained in that part of the manual.  Just focusing on having a form that allows you to upload an image to a directory on the server, and then allowing users to see a table of those images, is a good starter project that is not too big.

Yes Exactly! Thanks gizmola. Thats where I'll start. Actually its what I want to do just upload images into a table, submit, then have someone do another page. I just felt that a create new page was the way to go. Maybe not. Maybe I should've said that in the first place. Anyway lets be best friends from now on. Thanks again to both. I'll be back to bother you guys again.

The only way to learn is to try it out... 

 

you can indeed use IF statements to determine the image type and you can indeed use IF statements to validate an infinite number of other things.  Your project can only get as diverse and functional as YOU make it.  Though Joomla and Drupal and Wordpress are great ways to end the insanity of reinventing the wheel, a lot of benefit comes from customizing, controlling and manipulating your users' input yourself... from scratch.

 

The moral of the idea... start small.. 

Do what you can already do, fix it... get it working perfectly.. delete it... remake it again.. get fed up with your whitespace and indenting, delete it all again... redo redo redo... until you know everything there is to know about what you're doing.  Then you'll be able to adequately bring something to the table for us to answer.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.