Raised This Month: $ Target: $400
 0% 

trend_graph.php error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Julius95
Senior Member
Join Date: Jul 2013
Location: Sweden
Old 08-14-2013 , 08:53   trend_graph.php error
Reply With Quote #1

This is the error I get:
Notice: Undefined variable: player in C:\Abyss Web Server\htdocs\stats\trend_graph.php on line 69

How can I fix that? I'm new to PHP.

here is the line

if (!$player) exit();

Last edited by Julius95; 08-14-2013 at 08:54.
Julius95 is offline
Send a message via ICQ to Julius95 Send a message via AIM to Julius95 Send a message via MSN to Julius95 Send a message via Yahoo to Julius95 Send a message via Skype™ to Julius95
Adjo
Member
Join Date: Dec 2009
Location: UK
Old 08-14-2013 , 09:43   Re: trend_graph.php error
Reply With Quote #2

That notice only happens because the variable $player is only ever set on the above line, assuming the condition in the if statement is met ($_GET['player'] containing a value)

You could fix it by changing line 69, so you have this:

PHP Code:
    if (isset($_GET['player'])) $player = (int)$_GET['player'];
    if (empty(
$player)) exit(); 
The change above should account for any characters stripped from $player when casting it to an integer (so further down the code there won't be a possible broken query), and if $_GET['player'] isn't set, it'll just exit() without any errors/notices.
Adjo is offline
Rytis
Veteran Member
Join Date: Feb 2012
Location: Germany
Old 08-14-2013 , 11:30   Re: trend_graph.php error
Reply With Quote #3

The trend graph can't be used without a player ID...
There must be a player ID, example: http://stats.rts-server.net/trend_graph.php?player=65
Rytis is offline
Adjo
Member
Join Date: Dec 2009
Location: UK
Old 08-14-2013 , 13:10   Re: trend_graph.php error
Reply With Quote #4

Quote:
Originally Posted by Rytis View Post
The trend graph can't be used without a player ID...
There must be a player ID ...

While that is true, if someone were to visit the script manually - without passing a playerId, or not passing the player variable in the GET request, it would give a notice in the error logs... which is probably what he or someone else did.

I don't really think it matters if it, 'can't be used without a player ID', it didn't have the checking necessary to prevent a notice in the logs.

If the player variable wasn't set in the GET request, then line 69 gives an undefined variable because it isn't defined at any part above it (and the part it could be defined in returns false, so it isn't defined there), if it is set, but doesn't have a value (or the value it contained was removed when casting it to an int, because it was a string), there wouldn't be a notice -- because that if statement checks for that.

The if(empty()) check does what it would do before, but also accounts for that it may be someone visiting the script manually, in which case there probably isn't a value - and from the php docs, the empty function won't give any notices when it is passed an undeclared variable, instead it'll return true.
Adjo is offline
Rytis
Veteran Member
Join Date: Feb 2012
Location: Germany
Old 08-14-2013 , 13:24   Re: trend_graph.php error
Reply With Quote #5

I know, I'm just saying that it need to be used with the playerID.
Also errors should only be seen on a developement server, not on a production server.
Rytis is offline
Julius95
Senior Member
Join Date: Jul 2013
Location: Sweden
Old 08-15-2013 , 04:31   Re: trend_graph.php error
Reply With Quote #6

I changed it to what you said Adjo but if you see here
http://julius95.zapto.org/stats/hlst...rinfo&player=8

the player trend still NOT appears
Julius95 is offline
Send a message via ICQ to Julius95 Send a message via AIM to Julius95 Send a message via MSN to Julius95 Send a message via Yahoo to Julius95 Send a message via Skype™ to Julius95
Rytis
Veteran Member
Join Date: Feb 2012
Location: Germany
Old 08-15-2013 , 04:38   Re: trend_graph.php error
Reply With Quote #7

IS PHP-GD installed?
Rytis is offline
Julius95
Senior Member
Join Date: Jul 2013
Location: Sweden
Old 08-15-2013 , 05:13   Re: trend_graph.php error
Reply With Quote #8

Quote:
Originally Posted by Rytis View Post
IS PHP-GD installed?
No what's that?
Julius95 is offline
Send a message via ICQ to Julius95 Send a message via AIM to Julius95 Send a message via MSN to Julius95 Send a message via Yahoo to Julius95 Send a message via Skype™ to Julius95
Julius95
Senior Member
Join Date: Jul 2013
Location: Sweden
Old 08-15-2013 , 05:43   Re: trend_graph.php error
Reply With Quote #9

I would really need a good tutorioal for how to install PHP-GD
Julius95 is offline
Send a message via ICQ to Julius95 Send a message via AIM to Julius95 Send a message via MSN to Julius95 Send a message via Yahoo to Julius95 Send a message via Skype™ to Julius95
Rytis
Veteran Member
Join Date: Feb 2012
Location: Germany
Old 08-15-2013 , 05:43   Re: trend_graph.php error
Reply With Quote #10

https://www.google.com/search?q=php+gd

Last edited by Rytis; 08-15-2013 at 05:43.
Rytis is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode