Jump to content

Altering Actual File Contents


icekat83

Recommended Posts

Hi,

 

I have a file which contains settings for a user. Similar to wordpress except simpler like setting a default email for error messages or something. The idea is that it's used as an installation script for web-ware where someone fills in a form with their database details, my script will hard-code them into the settings file and then delete itself. I'll admit I did get the idea from wordpress.

 

Only the way it's coded currently requires a certain combination of characters at the end and seems really messy. The script looks like this (and does work):

    $endpos = strpos ( $contents, '"; //replace with name//', $startpos);

 

The settings file looks like this:

    $hard_name = "Smith"; //replace with name//

 

As you can see I use the comment in the settings file, which follows what I'm actually changing, to find the end of the variable. I am sure there must be a better way of doing things but don't know what. It just seems really inefficient because if the comment is removed the script breaks.

 

Any info and tips would be much appreciated.

 

IceKat

Link to comment
Share on other sites

I've done something like that a long long long time ago, it was to administer the installation settings and maintain them. I took the path that CrayonViolent is suggesting, by storing the variables as a php script to be included, the other option is to store them as serialized data, but i wouldn't recommend saving the serialized data as just a file, a php file ok

 

<?php
$sample=array(
    'name'=>'John Doe',
     'password'=>'JaneDoe'
);

$data='<?php $config=unserialize(\''. serialize($sample) .'\'); ?>';
file_put_contents('config.php',$data);
?>

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.