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.

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.