Page 1 of 1

Saving and retrieving variables

Posted: Tue Jun 03, 2003 11:51 pm
by cgroup
I am switching from HTML to PHP so I'm still fairly new to the programming.

I saved some variables that I want to use on all pages in a file called variables.php so I can use them all over the site and change them easily. The problem is that I don't know how to load them.

I tried the include('variables.php') tag first but it takes the file literally and doesn't parse it.

I've searched all over the net and can't find anything about loading variables from another file. :(

Can anyone help me :?: THANX

Posted: Wed Jun 04, 2003 1:34 am
by detrox
you may need add tags <?php and ?> at the begin and end of variables.php

for example.

if variables.php likes this

$username ="username"
$password = "password";

when you include this file the content of the variables.php will be show in the explorer, If you want to execute the php file, you need this,
<?
$username ="username"
$password = "password";
?>

then include("variables.php");

Posted: Wed Jun 04, 2003 3:12 am
by discobean
Try starting out here before you go nutters:

http://www.php.net/tutorial

Posted: Wed Jun 04, 2003 10:42 pm
by cgroup
Thanks for the help - I've been able to get it to work somewhat through the include() tag like this.

<?php
include ('variables.php')
?>

but when I try to do an absolute URL it doesn't work. This was the problem I was having.

<?php
include ('http://www.sitename.com/directory/variables.php')
?>

...doesn't work - do you have a solution that would allow me to get variables from a file in another directory.

Thanks a bunch :oops:

Posted: Thu Jun 05, 2003 1:30 am
by delorian
Try something like this:

Code: Select all

<?php
include("./directory/variables.php");
?>
I don't know where do you include the file, so I can't tell if that's path is correct :D , but I think you understatnd what I mean :P

Posted: Thu Jun 05, 2003 3:03 am
by r337ard
readfile() works for me :)

Posted: Thu Jun 05, 2003 6:55 am
by detrox
"include ('http://www.sitename.com/directory/variables.php') "

I think that If the site is not your own one, it won't work unless you set sth in the php.ini, details can be find in the manual.