PDA

View Full Version : Call to underfined function that is there


thesavior
07-11-2006, 05:42 AM
Here is my php class
class site_stats
{
function displayip() // Returns the IP of the user
{
return $_SERVER['REMOTE_ADDR'];
}
function site_loggedinas() // Creates the "Logged in as TheSavior line
{
global $forum_user;
if($forum_user['displayname'] != "")
{
$displaynamewithparens = '('.$forum_user['displayname'].')';
}
echo 'Logged in as <a href="'.FORUM_ROOT.'profile.php?id='.$forum_user['id'].'"><strong>'.convert_htmlspecialchars($forum_user['username']).'</strong></a>&nbsp'.$displaynamewithparens;
}
function site_hits()
{
$yourhits = 'SELECT COUNT(*) from `admin_stats` where `ip` = \''.$_SERVER['REMOTE_ADDR'].'\'';
$yourhits = mysql_query($yourhits);
@$yourhits = mysql_result($yourhits , 0);
echo $yourhits;
}
function site_mostvisitedpage()
{
$mostpage = "SELECT page, COUNT(*) AS c FROM admin_stats where page !='' and ip = '".$_SERVER['REMOTE_ADDR']."' GROUP BY page ORDER BY c DESC LIMIT 1";
$mostpage = mysql_query($mostpage);
$mostpage = mysql_result($mostpage , 0);
echo $mostpage;
}
function site_lastvisit()
{
global $forum_user;
echo format_time($forum_user['last_visit']);
}
function site_referer()
{
$referer = $_SERVER['HTTP_REFERER'];
$referer = str_replace("http://", "", $referer);
echo $referer;
}
}


and the relevant part of my php page:

<li><?php $site->site_loggedinas()?></li>
<li>Your page hits: <?php $site->site_hits()?></li>
<li>Most Visited Page: <?php $site->site_mostvisitedpage()?></li>
<li>Uploaded Images: 3</li>
</ul>
<ul class="brdwelcomeright">
<li>Current IP: <?php echo $site->displayip()?></li>
<li>Last Visit: <?php echo $site->site_lastvisit()?></li>
<li>Referer: <?php echo $site->site_referer()?></li>

What is wierd, is that i get a fatal error, call to undefined function in this:<?php echo $site->site_referer()?>

What is wierd, is that <?php echo $site->site_lastvisit()?> works, and is in the same place in my function file, so I have no idea why im getting the php error on that.

dswimboy
07-11-2006, 05:48 AM
what happens when you change the name of the function in both places to something like site_foo()?

what happens if you comment out all the code that site_referer() has, and just return true;?

also, your signature like doesn't work.

GJay
07-11-2006, 07:56 AM
I assume $site is instantiated somewhere?

(as an aside, why are you echoing the function calls when they all echo internally?)