Page 1 of 1

Checking another file if X variable = on

Posted: Fri Apr 25, 2003 1:16 am
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.

Posted: Fri Apr 25, 2003 2:05 am
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?

Posted: Fri Apr 25, 2003 12:10 pm
by leebo
cant you just use sessions ? register session in page one then you have it on page 2 ?

Hey what do i know ?

Posted: Fri Apr 25, 2003 12:32 pm
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>";

}
?>

Posted: Fri Apr 25, 2003 1:49 pm
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?

Posted: Fri Apr 25, 2003 5:46 pm
by m3mn0n
That's possible too.

Posted: Fri Apr 25, 2003 9:57 pm
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.

Posted: Fri Apr 25, 2003 10:04 pm
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?

Posted: Fri Apr 25, 2003 10:34 pm
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 :)