FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Functions...





Diablosblizz
Hey, this is sort of hard to explain but I'll try my best. I am trying to make a offline script for my site, so a function will check if the offline variable is set to 0 or 1. If it's set to 1, then it shows an offline page. I had it working, but that way made every page have the offline code on it. So, I have a functions.php script, and I have tried this:

Code:

<?php
function check_offline() {
if($offline == "0") {
return false;
} else if($offline != "0" || $offline != "1") {
?>
<link rel="StyleSheet" type="text/css" href="template/template.css" />
<center><img src='images/header.jpg'></center><BR><BR>
<fieldset>
<legend>Site Offline</legend>
<b><font color='yellow'>WARNING</font></b>: The site configuration variables seem to have been edited by hand. The ONLINE variable in the config.ini is set to something other than 0 or 1. Please check that the variable is set to either 0 or 1. The number 0 makes the site online while the number 1 makes the site offline to normal members. Administrators will have the priviledge to login to the administrator panel and change the site from online or offline.
</fieldset>
<?php
} else if($offline == "1") {
?>
<link rel="StyleSheet" type="text/css" href="template/template.css" />
<center><img src="images/header.jpg"></center><BR><BR>
<fieldset>
<legend>Site Offline</legend>
<b><font color="yellow">WARNING</font></b>: This website, <?php echo $webname; ?>, is currently offline. This could be caused by site maintance or site closure.
</fieldset>
<?php
}
}
?>


I apologize for it being a long code, but it's the only way I could show you. So, as you can see it checks if $offline (defined above that code) is either 0, 1 or neither. If it's 0 it will return false, and the rest just sorta shows the code. When I put check_offline() on my pages, and set the variable to 0 (site online) it just shows the configuration issue error (see here).

Does anybody know what I should and can do? Thanks![/url]
Star Wars Fanatic
Most likely what you've done is set the variable wrong.
You check for some reason the string "0" or "1" and if you are setting offline as
$offline = 0 ;
The that is an int, not a string, and it may be confusing the two. Make sure you are sticking with either ints or strings, or you are converting it to one or the other.

Also make sure that the function check_offlline can see the variable. The best way to do this is to set it global at the top of the function:

Code:

<?php
function check_offline() {
global $offline ;


Try those two things and let us know if anything changed.
rvec
huh Confused
Code:
} else if($offline != "0" || $offline != "1") {

that is not always true?
not 1 or not 0 is always true Wink

I think you mean
Code:
} else if($offline != "0" && $offline != "1") {


or even easier, just at the end after you tried if it was 1 or 0 use else.

Also, the main problem, global variables aren't readable from the function scope by default.

Instead of $offline try to use $GLOBALS['offline'] and instead of $webname use $GLOBALS['webname']

More info about scopes: http://nl2.php.net/global
Diablosblizz
Okay, Star Wars you were correct. The global wasn't set and changed it properly. The only problem is that:

1. It shows the error twice, so the same error twice. **
2. It still shows the content.

I have learned, from rvec, that the die() stops the page from continuing to load. I, unfortunately, do not know how to make that happen with the coding that I have done (HTML). To see what I mean, click here. As you can see, it shows two of them, and continues to show the site content.

EDIT: I fixed the error showing twice, now just a problem of killing the rest of my content. (**)
Star Wars Fanatic
That page you linked to is Forbidden for me.

And I'm not sure about the problem you are having with the die. No matter where you put it it should work...
Whether there is html outputting after or not, it will still stop it from outputting.
Now the thing you might be having trouble with is if you have your html before it. That would cause it to output the html, and then when it reaches the die it would stop.
But that can be solved if you put your code at the top.

Also using exit() seems like a better function, though die() works just as well.


*Note: There are virtually no differences between die and exit, I hope I didn't confuse you.
Diablosblizz
EDIT: I have fixed this by putting my code in single (') quotes and using exit. Thank you very much for the support!
Related topics
req: PHP to list files in directory, and link to them
Great php editor
Tutorial: PHP Installed Modules Dynamic Reference Tool
PHP Tutorials
Enabled PHP Methods
A very good PHP MySQL Tutorial
Need a forum signature script, (php functions req)
PHP.ini
php / javascript script works in FireFox browser, but not IE
Using Javascript to Encrypt Data then POST to PHP
some usefull PHP functions
2 php functions disabled on Server 2
php functions
Need a PHP expert or Wordpress wizard
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.