Hi,
here's the deal:
I have a config.php file in which I have set a few var's, to use in the
whole site. E.g.:
$db_host = "localhost";
Then I also have a class, which is supposed to handle all database
functions. In this class I try to recover the var's from my config file,
but this just doesn't seem to work. I tried to put the following
statements in the constructor as well as in a plain function, but the
output of the var is always empty.
include("config.php");
global $db_host;
echo "value of db_host: ".$db_host;
Now, I have a slight suspicion that it might have to do with the fact
that I'm using classes, but I don't know what's wrong. Normally I should
be able to use the values from the config.php file, right?
greetz
<T!M> aka wEEdpEckEr 15 1902
"wEEdpEckEr" <mi**********@pandora.be> wrote in message
news:p2**********************@hestia.telenet-ops.be... Hi,
here's the deal: I have a config.php file in which I have set a few var's, to use in the whole site. E.g.:
$db_host = "localhost";
Then I also have a class, which is supposed to handle all database functions. In this class I try to recover the var's from my config file, but this just doesn't seem to work. I tried to put the following statements in the constructor as well as in a plain function, but the output of the var is always empty.
include("config.php"); global $db_host; echo "value of db_host: ".$db_host;
Now, I have a slight suspicion that it might have to do with the fact that I'm using classes, but I don't know what's wrong. Normally I should be able to use the values from the config.php file, right?
greetz <T!M> aka wEEdpEckEr
Doing that works just fine with a simple example for me. Try
error_reporting(E_ALL) and make sure the config file gets found, etc.
Garp
Garp wrote: "wEEdpEckEr" <mi**********@pandora.be> wrote in message news:p2**********************@hestia.telenet-ops.be...
Hi,
here's the deal: I have a config.php file in which I have set a few var's, to use in the whole site. E.g.:
$db_host = "localhost";
Then I also have a class, which is supposed to handle all database functions. In this class I try to recover the var's from my config file, but this just doesn't seem to work. I tried to put the following statements in the constructor as well as in a plain function, but the output of the var is always empty.
include("config.php"); global $db_host; echo "value of db_host: ".$db_host;
Now, I have a slight suspicion that it might have to do with the fact that I'm using classes, but I don't know what's wrong. Normally I should be able to use the values from the config.php file, right?
greetz <T!M> aka wEEdpEckEr
Doing that works just fine with a simple example for me. Try error_reporting(E_ALL) and make sure the config file gets found, etc.
Garp
I generally use th following to define globals, nfi if it is really a
correct way to do it tho.
define("glb_MY_GLOBAL", "myglobalvalue");
Access is the same as you have by doing:
global glb_MY_GLOBAL;
echo glb_MY_GLOBAL;
-Steve
With total disregard for any kind of safety measures Stephen
Gordon <s4******@student.uq.edu.au> leapt forth and uttered: define("glb_MY_GLOBAL", "myglobalvalue");
Access is the same as you have by doing:
global glb_MY_GLOBAL; echo glb_MY_GLOBAL;
You don't have to globalize constants. They are already accessible
globally.
--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Stephen Gordon <s4******@student.uq.edu.au> wrote in news:c4o1ca$38k$1
@bunyip.cc.uq.edu.au: Doing that works just fine with a simple example for me. Try error_reporting(E_ALL) and make sure the config file gets found, etc.
Here it doesn't... but I must admit, it's in a class (db_administrator)
of wich instances are used in another class (visitor), and there ara
quite a few include statements involved.
I generally use th following to define globals, nfi if it is really a correct way to do it tho.
define("glb_MY_GLOBAL", "myglobalvalue");
Indeed, this seems to work better. Good thing that their values don't
have to change. ;-)
Thanx both for your replies.
Maybe just another question: I used an instance of Visitor to store in a
_SESSION var, so _before_ I call session_start(), I'm obliged to include
the class-definition of Visitor. But when I do this, I get an error
Warning: session_start(): Cannot send session cookie - headers already
sent by (output started at XXX/dbadmin.class.php:80) in XXX/register.php
on line 4
Now, dbadmin.class.php is ofcourse the class definition wich is called
upon by visitor.class.php, but No where in the file I can find anything
that would have 'sent headers', no output at all is used in that class,
only calls to the database. The include to visitor.class.php is on line
3 and start_session() on line 4 in register.php. Beneath is included the
code of dbadmin.class.php, anyone of you know why this file would have
sent headers before any instances of it are used? I have commented the
"or die" statements that maybe could cause any output, but that won't
help.
TIA
Tim
***dbadmin.class.php***
<?
class DatabaseAdministrator {
function DatabaseAdministrator() {
require("config.php");
}
function open_db () {
global $link;
$link = mysql_connect(db_host, db_login, db_passw); //or die ("Can't
connect to host: db_host!\n");
mysql_select_db(db_name); // or die ("Can't select database
db_name: $!\n");
}
function close_db () {
global $link;
mysql_close($link);
}
function add_hit() {
}
function add_visit($v_ip, $v_provider, $v_country, $v_date,
$v_starttime, $v_browser, $v_os, $v_referer) {
}
function get_country($ip_addr) {
$this->open_db();
$table_name = db_table_ipcount;
$query = "SELECT COUNTRY_NAME FROM $table_name WHERE ip_from <=
$ip_addr AND ip_to >= $ip_addr";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$this->close_db();
return $row["COUNTRY_NAME"];
}
}
?>
"wEEdpEckEr" <mi**********@pandora.be> wrote in message
news:df*********************@hebe.telenet-ops.be...
<snip> (output started at XXX/dbadmin.class.php:80)
<snip>
What's on this line? If it's not something you expect output from, stick a @
in front of it, but it's likely it's doing something, possibly a header
output of its own.
Garp
"Garp" <ga***@no7.blueyonder.co.uk> wrote in
news:3w*********************@news-text.cableinet.net: "wEEdpEckEr" <mi**********@pandora.be> wrote in message news:df*********************@hebe.telenet-ops.be... <snip> (output started at XXX/dbadmin.class.php:80) <snip>
What's on this line? If it's not something you expect output from, stick a @ in front of it, but it's likely it's doing something, possibly a header output of its own.
Well, I left out a commented part, but apart from that, everything is in
the previous post. The line refers to the last line of my class, "}". So
it's not doing anything at all. And as you can see (code in previous
message), there's not any output at all. Weird, no?
"Garp" <ga***@no7.blueyonder.co.uk> schreef op zo, 04 apr 2004 11:41:51
GMT in news:3w*********************@news-text.cableinet.net: <snip> (output started at XXX/dbadmin.class.php:80) <snip>
What's on this line? If it's not something you expect output from, stick a @ in front of it, but it's likely it's doing something, possibly a header output of its own.
Ok, looks like I found it: when using an include, the included page,
shouldn't have <?php and ?> tags. The opening php tag will be ignored,
because php is already opened, but the closing one will be used
therefore terminating the php-code, even if it isn't supposed to do so.
Stupid, when you don't know this. I thought all code had to be captured
between these php-tags.
greetz
<T!M> aka wEEdpEckEr
wEEdpEckEr wrote: Ok, looks like I found it: when using an include, the included page, shouldn't have <?php and ?> tags.
It *must* have <?php and ?> tags if it is going to be interpreted
The opening php tag will be ignored, because php is already opened,
PHP "closes" right after the include() and before opening the included
file. If the included file has PHP inside it must be delimited by the
php tags.
but the closing one will be used therefore terminating the php-code, even if it isn't supposed to do so. Stupid, when you don't know this. I thought all code had to be captured between these php-tags.
It has to be. You're doing some other thing wrong.
--
USENET would be a better place if everybody read: : mail address : http://www.catb.org/~esr/faqs/smart-questions.html : is valid for : http://www.netmeister.org/news/learn2quote2.html : "text/plain" : http://www.expita.com/nomime.html : to 10K bytes :
"Pedro Graca" <he****@hotpop.com> wrote in message
news:c5*************@ID-203069.news.uni-berlin.de... wEEdpEckEr wrote: Ok, looks like I found it: when using an include, the included page, shouldn't have <?php and ?> tags.
It *must* have <?php and ?> tags if it is going to be interpreted
The opening php tag will be ignored, because php is already opened,
PHP "closes" right after the include() and before opening the included file. If the included file has PHP inside it must be delimited by the php tags.
but the closing one will be used therefore terminating the php-code, even if it isn't supposed to do so. Stupid, when you don't know this. I thought all code had to be captured between these php-tags.
It has to be. You're doing some other thing wrong.
He's right, wEEdpEckEr. All my code is built this way, something else is
amiss. Try to reproduce the problem in two smaller files, and post them here
if it still fails s so we can try ourselves?
Garp
"Garp" <ga***@no7.blueyonder.co.uk> schreef op do, 08 apr 2004 09:37:01
GMT in news:13*********************@news-text.cableinet.net: It has to be. You're doing some other thing wrong.
He's right, wEEdpEckEr. All my code is built this way, something else is amiss. Try to reproduce the problem in two smaller files, and post them here if it still fails s so we can try ourselves?
Hmmm, ok, so I left out the closing tags, and that seemed to work, now
I've put them back, and again it seems to work fine. So it must've been
something completely different, that I've changed and solved without
knowing... Weird. ;-)
Btw: while I'm buggin you guys: getting the screen resolution is not
possible in php I guess? I've been searching the web, and I only can
seem to find references to javascripts...
greetz
With total disregard for any kind of safety measures wEEdpEckEr
<toch_lekker_nie@geen_email.aub> leapt forth and uttered: Btw: while I'm buggin you guys: getting the screen resolution is not possible in php I guess? I've been searching the web, and I only can seem to find references to javascripts...
greetz
PHP = Server Side
Screen Res = Client side.
So no, it's not possible. Besides, screen resolution is a red herring
as it makes no allowance for /window/ size.
--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Phil Roberts <ph*****@HOLYflatnetSHIT.net> schreef op do, 08 apr 2004
23:48:33 GMT in news:Xn************************@216.196.97.132: PHP = Server Side Screen Res = Client side.
Well, that's your explaination :p Browsername and OS are also client
side and those can be easily checken within php. ;-)
So no, it's not possible. Besides, screen resolution is a red herring as it makes no allowance for /window/ size.
No, but it 's handy to know, weather most of your visitors are still in
800*600 or have advanced to 1024*768. This is pure for stats, not to
change the outcome of the page.
greetz
<T!M> aka wEEdpEckEr
On Fri, 09 Apr 2004 00:00:10 +0000, wEEdpEckEr wrote: PHP = Server Side Screen Res = Client side.
Well, that's your explaination :p Browsername and OS are also client side and those can be easily checken within php. ;-)
[ snip ]
Browser name is sent by the client to the server hence PHP can detect this
value. The OS is often derived from this very same value also.
Check the user agent string in your logs.. normally, they'll contain the
browser and the OS the browser is running on.. neither of which are
actually _detected_ client side =)
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
"Ian.H" <ia*@WINDOZEdigiserv.net> schreef op vr, 09 apr 2004 00:17:02
GMT in news:pa****************************@bubbleboy.digi serv.net: Browser name is sent by the client to the server hence PHP can detect this value. The OS is often derived from this very same value also.
Check the user agent string in your logs.. normally, they'll contain the browser and the OS the browser is running on.. neither of which are actually _detected_ client side =)
Yes, I know, I wrote the regex's myself, but it could be that this is also
being send by the browser. Just like the referer-string, or something. This
is also not "detected", so it could have been possible that the resolution
was available too. Helas, it isn't... Too bad, since I can't use javascript
in my model.
greetz
Tim
On 2004-04-09, wEEdpEckEr <toch_lekker_nie@geen_email.aub> wrote: Yes, I know, I wrote the regex's myself, but it could be that this is also being send by the browser. Just like the referer-string, or something. This is also not "detected", so it could have been possible that the resolution was available too. Helas, it isn't... Too bad, since I can't use javascript in my model.
Meaby you want to read the rfc on http1.1 to know what a browser can
send ;)
-- http://home.mysth.be/~timvw This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
I get the impression that most people who are using objects in their
PHP projects are mixing them with procedural code. The design, I
think, is one where the procedural code is the client code, and...
|
by: John |
last post by:
Hi,
I'm looking for the best way to deal with globals in PHP.
As a 'C' software developer, I would normally avoid all
globals and not have any at all, but use structs and pass
everything in...
|
by: Ron_Adam |
last post by:
Is there a way to hide global names from a function or class?
I want to be sure that a function doesn't use any global variables by
mistake. So hiding them would force a name error in the case...
|
by: Byron |
last post by:
I'm working of several projects that use many of the same constants and I
wanted to put them all into a single file and include them in all the
projects that need them so I can maintain them in one...
|
by: Arpi Jakab |
last post by:
I have a main project that depends on projects A and B. The main project's
additional include directories list is:
...\ProjectA\Dist\Include
...\ProjectB\Dist\Include
Each of the include...
|
by: robert |
last post by:
Using global variables in Python often raises chaos. Other languages use
a clear prefix for globals.
* you forget to declare a global
* or you declare a global too much or in conflict
* you...
|
by: Steven W. Orr |
last post by:
I have two seperate modules doing factory stuff which each have the
similar function2:
In the ds101 module,
def DS101CLASS(mname,data):
cname = mname+'DS101'
msg_class = globals()
msg =...
|
by: SoulIntruder |
last post by:
Hello folks.
I have a beginners question.
I have such script:
<?php
$User = $_POST;
$Password = $_POST;
$Database = $_POST;
|
by: r0g |
last post by:
Hi There,
I'm refactoring some old code that uses global variables and was
originally written in one big flat file with a view to nicening it up
and then extending it. The problem I have though...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |