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
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.

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.