Help: PHP/MySQL errors when script runs

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
DLashley
-


Joined: 18 Dec 2002
Posts: 207
Location: New York, NY

PostPosted: Fri Dec 27, 2002 7:16 am    Post subject: Help: PHP/MySQL errors when script runs Reply with quote

I tried to run a script written in PHP (uses MySQL database), and got these 3 error messages:

Code:

Notice: Undefined variable: REMOTE_ADDR in C:\SERVER ROOT PATH\htdocs\SCRIPT.php on line 21

Notice: Undefined variable: PHP_SELF in C:\SERVER ROOT PATH\htdocs\SCRIPT.php on line 21

Notice: Undefined variable: PHP_SELF in C:\SERVER ROOT PATH\htdocs\SCRIPT.php on line 33


Now here's the script: :roll:

Code:

<?php
//Put your basic server info here
$server = " "; //normally localhost
$db_user = " "; //your MySQL database username
$db_pass = " "; //your MySQL database password
$database = " ";
$timeoutseconds = 300;

//this is where PHP gets the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

//connect to database
//$server = localhost probably
//$db_user = your MySQL database username
//$db_pass = //your MySQL database password
mysql_connect($server, $db_user, $db_pass);

//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}

//delete values when they leave
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}

//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}

//number of rows = the number of people online
$user = mysql_num_rows($result);


//spit out the results
mysql_close();
if($user == 1) {
print("$user user online\n");
} else {
print("$user users online\n");
}
?>


How, where do I fix the problem? Please help. Thanks in advance!
_________________
DLashley
Back to top View user's profile Send private message Visit poster's website
!Keys
-


Joined: 23 Nov 2002
Posts: 156
Location: Holland, Enschede

PostPosted: Fri Dec 27, 2002 11:48 pm    Post subject: Reply with quote

In the new php variables are adjusted

$REMOTE_ADDR » $_SERVER[REMOTE_ADDR]
$variable » $_POST[some-variable-you-sent-by-form]
_________________
!Keys || MwM^computerware
Back to top View user's profile Send private message MSN Messenger
DLashley
-


Joined: 18 Dec 2002
Posts: 207
Location: New York, NY

PostPosted: Sat Dec 28, 2002 4:07 am    Post subject: Reply with quote

Thanks for helping me, !Keys, but I don't speak PHP yet. :wink:

I got that script from a website, so I don't know how to alter it so that it works. I don't know the syntax yet, you know what I mean?

Can you or someone else please help me with that, and insert the modified code into the script for me? I'd really appreciate that!
_________________
DLashley
Back to top View user's profile Send private message Visit poster's website
!Keys
-


Joined: 23 Nov 2002
Posts: 156
Location: Holland, Enschede

PostPosted: Sat Dec 28, 2002 12:18 pm    Post subject: Reply with quote

i know what you mean, if you downloaded this script from somewhere else it´s better t:

ór download an older version of php and intall that one.
ór go to php.net and read the changed added to php 4.2.3
_________________
!Keys || MwM^computerware
Back to top View user's profile Send private message MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Mon Dec 30, 2002 2:04 am    Post subject: Reply with quote

DLashley wrote:
Thanks for helping me, !Keys, but I don't speak PHP yet. :wink:

I got that script from a website, so I don't know how to alter it so that it works. I don't know the syntax yet, you know what I mean?

Can you or someone else please help me with that, and insert the modified code into the script for me? I'd really appreciate that!

An easier way to render PHP compatible with older scripts that use the old variable access manner is to open php.ini and to serach for the line:
Code:
register_globals = off

and to change it to
Code:
register_globals = on

_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
DLashley
-


Joined: 18 Dec 2002
Posts: 207
Location: New York, NY

PostPosted: Tue Dec 31, 2002 5:43 pm    Post subject: Reply with quote

I read on the page below that turning register globals to "on" is a security issue. I'd really rather not get hacked. :roll:


http://www.zend.com/manual/security.registerglobals.php
_________________
DLashley
Back to top View user's profile Send private message Visit poster's website
Jack
Guest





PostPosted: Tue Dec 31, 2002 5:55 pm    Post subject: PHP Variables... Reply with quote

Hi,

I think all you need to do is change the following lines like someone already mentioned...

Code:
//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$_SERVER["REMOTE_ADDR"]','$_SERVER["PHP_SELF"]')");

//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$_SERVER["PHP_SELF"]'");


Check to make sure everything is correct (quotes, dollar signs, etc.), and compare with the above post...

Quote:
$REMOTE_ADDR changes to $_SERVER["REMOTE_ADDR"]
$PHP_SELF changes to $_SERVER["PHP_SELF"]


If the script is just this one page, then it's okay to edit it. However, if this is part of something bigger, then it is simpler to:

Code:
register_globals = on


I wouldn't worry about the security, cause if there is sufficient error checking then it's not a problem. And server variables are kinda hard to change anyway, so they are not (?!) a security threat.

Cheers,

Jack
Back to top
DLashley
-


Joined: 18 Dec 2002
Posts: 207
Location: New York, NY

PostPosted: Tue Dec 31, 2002 7:26 pm    Post subject: Reply with quote

Hi again, Jack. :-)

1. Thank you for taking the time to write it out like that for me. That clarified it for me. I'm not a PHP programmer (yet), so as I said before - I'm not too familiar with the PHP syntax. I've only installed pre-made scripts (so far) on another server where I rent space. The same scripts run error free on that server, so I've never run into this problem before.

2. Yes, this is a one-page script which is supposed to give a "readout" of how many people are currently on my site at any given time.

3. I notice that you omitted certain parts from the script. It looks like the parts you omitted are supposed to give error messages if incorrect values are given. May I ask why these parts of the script were omitted? Is the coding incompatible with the current version of PHP? Tryin' to learn here. Just curious... :wink:

Code:
if(!($result)) {
print "Useronline Select Error > ";
}
 


and

Code:
if(!($delete)) {
print "Useronline Delete Failed > ";
}

_________________
DLashley
Back to top View user's profile Send private message Visit poster's website
Jack
Guest





PostPosted: Wed Jan 01, 2003 4:02 pm    Post subject: php... Reply with quote

:D
Heh heh, ooops...

I did not mean for them to be omitted, I merely edited the lines that need changing, all the others should be preserved as they are... I just didn't feel like copying the whole script over again...

So to reiterate, I only changed two lines and the comments (//) are there just to show you where the lines belong.

Again, I'm not sure if it'll work, didn't check... but that should be the idea anyway...

Cheers,

Jack
Back to top
Guest






PostPosted: Wed Jan 01, 2003 5:18 pm    Post subject: Reply with quote

Ok, no problem. lol. :wink:

I'll give it a shot. Thanks a lot for your help!
Back to top
drage
Guest





PostPosted: Sun Feb 02, 2003 2:28 am    Post subject: Reply with quote

register_globals = on

where would i put this in my php?

Im having various problems at the moment, which file should i put this command in?
if you could post me a reply to
drageo5@hotmail.com, that'd be ace!
cheers!

Pau!
Back to top
Bluedog
-


Joined: 05 Jan 2003
Posts: 179

PostPosted: Sun Feb 02, 2003 2:44 pm    Post subject: Reply with quote

you must change it in your php.ini file, it is towards the bottom. Simply change off to on.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group