Jump to content

PHP Setting Script


01hanstu

Recommended Posts

Hi, Hope you can help. I want to know how i can make my own installation script so that once all of the details are filled in they are saved into a config file and then opened when requested i.e. the hostname, username, password for the sql database ...

 

Help will be appreciated

Stuart

Link to comment
Share on other sites

As far as I know, it is not impossible to create a file and then fill it with PHP code, so I think this may help

<?php
$fileHandle=fopen("config.php", "w");
$stringToWrite="<?php  \$param1=$value1;
\$param2=$value2;
\$param3=$value3;
?>";
fwrite($fileHandle, $stringToWrite);
fclose($fileHandle);            /*Assuming that your data is - $value1, $value2 and $value3
Of course you may have any variable you want. The slash ("\") states as escaping character
*/
?>

 

Then when you have to use this file just include it

<?php include "config.php";?>

and use the variables you have already set (but here you are using $param not $value)

 

Hope this helps

----------------

Now playing: Timbaland - Way I Are (Feat. Keri Hilson & D.O.E.)

via FoxyTunes

Link to comment
Share on other sites

You could use JSON or XML or YAML for this.  That would probably be simpler than a PHP file.

 

<?php
// write
$config['hostname'] = 'pterodactyl.com';
$config['username'] = 'iheartdinosaurs';
$config['password'] = 'rawr';

$fp = fopen('config.json', 'w');
fwrite($fp, json_encode($config));
fclose($fp);

// read
$config = json_decode(file_get_contents('config.json'));
print_r($config);
?>

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.