Checking another file if X variable = on

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
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Checking another file if X variable = on

Post by Drachlen »

Okay.. I'm very new to PHP but i understand some of it.. I want to know how i would have 1 PHP file with variables on it, and an option to make the variable "X" = "ON" or "OFF" .. I got this page made. Now i want to make another page that if i open will check the other page to see what the variable is, and act upon it. I Dont want to use a 'get' funtion or a button to goto the other page.. I want it to be completly seperate. Please, if this isnt too much trouble, link me to a tutorial that does this or a brief explanation.. Thanks in advance.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

If i understead you correctly,

You want to have 1 page for the visitor, where you set something.

And a other page for you where you readout this setting?
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Post by leebo »

cant you just use sessions ? register session in page one then you have it on page 2 ?

Hey what do i know ?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I know what you mean. I do it all the time for my online web game and in most sites for db variables.

I have one page called vars.php, it contains most of the variables.

Simply use the require() or include() function to add thoses variables to that page. Then i believe you should be able to easily verify variables on that page.

eg.

Code: Select all

<?php
// this is vars.php
$pagetitle = "This is my page"; // goes in big letters on main page
$showtitle = "on";                   // on or off
?>

Code: Select all

<?php
// this is any php page you want to show the title

     include("vars.php"); // including the variable page

if ($showtitle == "on"){ // important to use double = sign

     echo "<h1>$pagetitle</h1>";

} else {

      echo "<br>";

}
?>
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

If you are using this to let users on your website personalize the site (like change the background color) then you could use a MySQL database a and store your users settings in that?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

That's possible too.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

To get vars or constants defined in file a.php into another file:

include('folder_path_to/a.php');

Constants are a little more secure - less open to substitution.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

thank you Oromian, this worked.. But im curious how i would goto vars.php and change the variable using a drop down menu, then save the changes from online?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You could save all the variables to a database. And then vars.php would have to query the database and pull out the variables.

Here is how the table could be setup:

Code: Select all

$sql = 'CREATE TABLE `test` ( 
`id` INT(3) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
`variable` TINYTEXT NOT NULL, 
`value` TINYTEXT NOT NULL 
);';
Now create a secure page, possibly by cookies or sessions then create a form that displays the current results of a db, and when updated, will process whatever the contents of the text field is into the db.

Hope it makes enough sence,

/me is pretty sleepy :)
Post Reply