Jump to content

[SOLVED] write external variables?


adamh91

Recommended Posts

Hey, I was wondering if its possible to edit the variables in another file. e.g.

 

config.php

$db_user = "admin";
$db_pass = 'password';
$db_host = 'localhost';
$db_name = 'mail';

 

somename.php

<? 
include 'config.php';
//Some code to edit the variable stored in config.php
?>

 

Sorry for the bad explanation  ;D

Is there a way to do this? =s

thanks

Link to comment
https://forums.phpfreaks.com/topic/40711-solved-write-external-variables/
Share on other sites

If I'm understanding you correctly, Yes you can do that. When you include a file, that file then becomes part of the file it is being included in. So any variables/functions that is in the included file these can be used in the file main file too, variables can also be modified too.

 

Think of include/require as copy 'n' paste. As that is what PHP basically does.

 

Includes are very handy when including frequent bits of code, for example when connecting to a database. Every time you need to connect to a database just simply include the file, rather than having to retype the same bit of code each time.

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.