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

Link to comment
Share on other sites

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.