WYSIWYG PHP issue help!

Discussion in 'PHP' started by Tropica, Nov 25, 2007.

  1. #1
    I building a cms of a site, and its nearly done!

    I have one problem i cant work out:

    I have a WYSIWYG editor that writes to a file:
       
    <form action="main.php" method="post">
    
    <textarea name="main" id="main"><? include ('/home/2345/public_html/11/22/main.txt') ?></textarea>
     <script language="JavaScript">
      generate_wysiwyg('main');
    </script> 
    <br />
    <br />
    
    <input type="submit" value="Confirm Changes">
    </form>
    PHP:
    It then writes to main.php:
    <?php
    
    if (isset( $_POST ))
       $postArray = &$_POST ;			// 4.1.0 or later
    else
       $postArray = &$HTTP_POST_VARS ;	// prior to 4.1.0
    
    $fname="/home/2345/public_html/11/22/main.txt";
    
    if($nfile != false)
    {
    foreach ($postArray as $sForm => $value )
    {
    if (get_magic_quotes_gpc())
    {
    fwrite ($nfile, stripslashes($value));
    }
    else
    {
    fwrite ($nfile, $value);
    }
    
    fclose($nfile);
    }
    
    }	
    
    ?>
    PHP:
    Now that works ok for text, but it has to accept a php include linking to another site, but it outputs the include (<? include ('file.php') ?>) as text, not as php.

    Anyone know what im doing wrong?

    Thanks for your help :)
     
    Tropica, Nov 25, 2007 IP
  2. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you have to use eval when you are reading it so that it reads the string as php and not text... soo something like...

    $file = file_get_contents("file.txt");
    eval($file);

    should work, the thing is with eval is that, you dont use the open and close tags you just type whatever code you want
     
    bobb1589, Nov 25, 2007 IP
  3. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #3
    where would i place that? in the page i want to show the file or in one of the code snippets i posted above?

    thanks :)
     
    Tropica, Nov 25, 2007 IP
  4. ehlokoen

    ehlokoen Peon

    Messages:
    161
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Please note that with user input, it can be dangerous to use eval. Someone can inject harmful code.
     
    ehlokoen, Nov 25, 2007 IP
  5. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #5
    harmful code wouldnt be added, it will be really safe :)
     
    Tropica, Nov 25, 2007 IP
  6. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yes he is right, forgot to mention that
     
    bobb1589, Nov 25, 2007 IP
  7. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #7
    its a really trustworthy organization it is for, so there will be no issues :)

    I still cant get it to display :(
     
    Tropica, Nov 25, 2007 IP
  8. ehlokoen

    ehlokoen Peon

    Messages:
    161
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    That can be, but just note that it could be dangerous ;) I don't say anyone WILL do such things, especially not the administrators of the script (only admins have access to this WYSIWYG, right?).

    Good luck!
     
    ehlokoen, Nov 25, 2007 IP
  9. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #9
    only admins yeah, and its password protected!
     
    Tropica, Nov 25, 2007 IP
  10. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #10
    I cant work out where to add this eval code :(

    Can anyone help me please?
     
    Tropica, Nov 25, 2007 IP