Jump to content

PHP Code + fopen + Writing PHP Code


jj20051

Recommended Posts

Alright so I'm attempting to save config data via php. Bellow is the code I currently have, however I'm afraid that when I "flip the switch" and use it that it will error out because of the <?php and ?> tags inside of it... Ideas, suggestions?

 

$config = '../includes/config.php';
$fh = fopen($config, 'w');
$data = '
<?php

$dbhost = "'.$database_host.'";
$dbuser = "'.$database_username.'";
$dbpass = "'.$database_password.'";
$dbname = "'.$database_name.'";

$key = "'.$site_key.'";
$cron_key = "'.$database_cron_key.'";
?>
';
fwrite($fh, $data);
fclose($fh);

Link to comment
https://forums.phpfreaks.com/topic/213264-php-code-fopen-writing-php-code/
Share on other sites

The major problem being: I only want to try it once... I suppose I could create a separate test page with just that piece of code + the variables.

 

Edit Update: Well apparently PHP has some form of a prevention mechanism to ensure that this works :P -- So apparently I'm already right... Sorry to have bugged anyone.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.