Jump to content

Writing PHP constants to config file, it wont work...


Hall of Famer

Recommended Posts

Well hello there, I want to create a script that writes a few PHP constants to a file called config.php. It does not work however, with the way I wrote it as below:

 

$configdata = "<?php
//Configuration File

\define("DBHOST", $dbhost);             //DB Hostname
\define("DBUSER", $dbuser);             //DB Username
\define("DBPASS", $dbpass);             //DB Password
\define("DBNAME", $dbname);             //Your database name
\define("DOMAIN", $domain);             //Your domain name (No http, www or . )
\define("SCRIPTPATH", $scriptpath);     //The folder you installed this script in
\define("PREFIX", $prefix);
?>";

$file = fopen('../inc/config.php', 'w');
fwrite($file, $configdata);
fclose($file);		

 

I am getting this error 'syntax error, unexpected T_STRING in ...', and I have no idea how to fix it. Strangely the below codes using PHP variables work flawlessly:

 

$configdata = "<?php
//Configuration File

\$dbhost = '{$dbhost}';      		//DB Hostname
\$dbuser = '{$dbuser}';			//DB User
\$dbpass = '{$dbpass}';			//DB Password
\$dbname = '{$dbname}';    			//Your database name
\$domain = '{$domain}';    			//Your domain name (No http, www or . )
\$scriptpath = '{$scriptpath}';		//The folder you installed this script in
\$prefix = '{$prefix}';    			

?>";

//Write the config.php file...

$file = fopen('../inc/config.php', 'w');
fwrite($file, $configdata);
fclose($file);	

 

 

This confuses me, all I did was to change the string to output from a list of variables to a list of constants, and it gives weird errors that I have absolutely no idea how to fix. Can anyone please lemme know what I did wrong? Thanks.

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.