Saving and retrieving variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cgroup
Forum Newbie
Posts: 13
Joined: Tue Jun 03, 2003 11:51 pm
Location: PA

Saving and retrieving variables

Post 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
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post 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");
User avatar
discobean
Forum Commoner
Posts: 49
Joined: Sun May 18, 2003 9:06 pm
Location: Sydney, Australia
Contact:

Post by discobean »

Try starting out here before you go nutters:

http://www.php.net/tutorial
cgroup
Forum Newbie
Posts: 13
Joined: Tue Jun 03, 2003 11:51 pm
Location: PA

Post 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:
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post 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
User avatar
r337ard
Forum Commoner
Posts: 29
Joined: Tue Apr 15, 2003 6:14 am
Contact:

Post by r337ard »

readfile() works for me :)
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

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