Jump to content


Photo

Making a TryIt Editor


  • This topic is locked This topic is locked
4 replies to this topic

#1 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 12 March 2008 - 04:32 AM

I've been trying to make a script like the TryIt Editor for my site, but I'm kind of stuck. I want a script that enables HTML, CSS and JavaScript, but not PHP or MySQL.

First I thought about using a HTML-flatfile for storing the code, but that might cause some problems if several users use the editor at the same time (I want a lot of people to be able to use it). An option could be to make flatfiles with the users IP as filename, but that would make a lot of files at my server, which I don't want.
Then I thought about storing the code in a cookie and then load it, but I'm no good with cookies, and how do I disable PHP and MySQL through that?
I'm not sure if databases or sessions could/should be used for this.

Any suggestions on how to make a TryIt Editor?

#2 dotbart

dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 12 March 2008 - 06:26 AM

Hi,

unless you want to store all those code snippets for further use, there is no need to use a database/file/...
You can just display what was entered in the form, this will also allow your HTML to be parsed!

if(isset($_POST['myText'])){
print $_POST['myText'];
}
//Seems pretty straightforward :-)

I'm not too sure about restricting your users from using PHP, I don't think it's really nessescary but it's never bad to use the: http://php.net/htmlentities function ...


B

#3 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 March 2008 - 04:35 PM

You don't need to worry about enabling or disabling php to do that, or even about server clutter.

When the form is submited, write the contents to a file (i.e. their ip would work for the name, extension doesn't make any difference with this method). Then for the iFrame on the right, just use readfile() to read the contents into the frame, and then unlink() the file after it has been read.

Edited by rc69, 12 March 2008 - 04:36 PM.


#4 Piemaster

Piemaster

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 27 June 2008 - 11:09 PM

Here :) I was bored..
Makesure you save it as 'tryit.php'! And if you dont mind, give me credit?
<?php
$ht = $_GET['html'];
echo '<title>HTML:'.$ht.'</title>';
echo 'Tryit editor';
echo '<form action=/tryit><div>When you are done, click <input type=submit value="me">';
echo '<div>HTML:<textarea rows=20 cols=30 name="html">'.$ht.'</textarea>';
echo '<div>___HTML BELOW___<div>'.$ht;
?>

Edited by Piemaster, 27 June 2008 - 11:12 PM.


#5 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 June 2008 - 11:45 AM

This topic is outdatted. No further replies are necessary. Future questions may be posted in a new topic.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users