Parse error in one php archive

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
struch23
Forum Newbie
Posts: 4
Joined: Tue Aug 01, 2006 5:42 pm

Parse error in one php archive

Post by struch23 »

I need some help with some php code.

I get this when I try to get one archive.php:


Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in /home/xxxxxx/public_html/extreme/search/includes/ip.php on line 11



Archive ip.php

Code: Select all

<?php

define('SMALL', 0);
define('BIG',   1);

class ClientInfo {

	var $flag_dirs = array(SMALL => 'assets/flags/small', BIG => 'assets/flags/big');
	var $flag_ext  = 'png';

	cfunction getctrybycode($code) {
		$countryArray = array();
		$input = "includes/countries.dat";
		$fd = fopen($input,"r") or die("Error: cannot open $input!");
		while ($buffer = fgets($fd,4096))
		{
			$buffer = preg_replace("/\n/","",$buffer);   //chomp()
			$pieces = explode(",",$buffer);
			$countryCode = $pieces[0]; $countryName = $pieces[1];
			$countryArray[$countryCode] = $countryName;
		}
		fclose($fd);
		return $countryArray[$code];
	}
Can anybody help me?

Thanks.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Parse error in one php archive

Post by Luke »

struch23 wrote:I need some help with some php code.

I get this when I try to get one archive.php:


Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in /home/xxxxxx/public_html/extreme/search/includes/ip.php on line 11



Archive ip.php

Code: Select all

<?php

define('SMALL', 0);
define('BIG',   1);

class ClientInfo {

	var $flag_dirs = array(SMALL => 'assets/flags/small', BIG => 'assets/flags/big');
	var $flag_ext  = 'png';

	function getctrybycode($code) {
		$countryArray = array();
		$input = "includes/countries.dat";
		$fd = fopen($input,"r") or die("Error: cannot open $input!");
		while ($buffer = fgets($fd,4096))
		{
			$buffer = preg_replace("/\n/","",$buffer);   //chomp()
			$pieces = explode(",",$buffer);
			$countryCode = $pieces[0]; $countryName = $pieces[1];
			$countryArray[$countryCode] = $countryName;
		}
		fclose($fd);
		return $countryArray[$code];
	}
Can anybody help me?

Thanks.
Try it now
struch23
Forum Newbie
Posts: 4
Joined: Tue Aug 01, 2006 5:42 pm

Post by struch23 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


now i get this:

Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in /home/xxxx/public_html/extreme/search/includes/ip.php on line 27


this is the full archive ip.php

Code: Select all

<?php

define('SMALL', 0);
define('BIG',   1);

class ClientInfo {

   var $flag_dirs = array(SMALL => 'assets/flags/small', BIG => 'assets/flags/big');
   var $flag_ext  = 'png';

   function getctrybycode($code) {
      $countryArray = array();
      $input = "includes/countries.dat";
      $fd = fopen($input,"r") or die("Error: cannot open $input!");
      while ($buffer = fgets($fd,4096))
      {
         $buffer = preg_replace("/\n/","",$buffer);   //chomp()
         $pieces = explode(",",$buffer);
         $countryCode = $pieces[0]; $countryName = $pieces[1];
         $countryArray[$countryCode] = $countryName;
      }
      fclose($fd);
      return $countryArray[$code];
   } 


	cfunction getctrybyhost($hostname) {

		return($this->getctrybycode($this->getctrycodebyhost($hostname)));
	}

	cfunction getctrycodebyhost($hostname) {
		return(substr(strrchr($hostname,'.'),1));
	}

	cfunction MaskOtherIP($IP) {

		if($IP==getenv("REMOTE_ADDR"))
			    return($IP);

				 $IP=strtr($IP,"0123456789","##########");
				 return($IP);
	}

	cfunction getClientIP() {
		$IP = getenv('REMOTE_ADDR');
		return $IP;
	}

	cfunction getClientHostname()
	{
		$error = 0;
		$IP = $this->getClientIP();
		$hostname = gethostbyaddr($IP);

	   if(!strcmp($hostname,$IP)) $error = 1;		// if failure, gethostbyaddr() returns the IP
		if (!$error) //if no error
		{
			return $hostname;
		}			
		//else
		return "";
	}

	cfunction getClientCountry()
	{
		$error = 0;
		$hostname = $this->getClientHostname();
		if (!strcmp($hostname,"")) $error = 1;
		if (!$error)
		{
			$country = $this->getctrybyhost($hostname);
			return $country;
		}
		//else
      return "";
	}

	cfunction getClientFlag($size)
	{
		$error = 0;
		$hostname = $this->getClientHostname();
		if (!strcmp($hostname,"")) $error = 1;
		if (!$error)
		{
			$country_code = strtolower($this->getctrycodebyhost($hostname));
			$file_name = $this->flag_dirs[$size] . '/' . $country_code . '.' . $this->flag_ext;
			if (is_readable($file_name))
			{
				return $file_name;
			}
		}
		//else
      return "";
	}

	cfunction getClientFlagHTML($size)
	{
		$error = 0;
		$flag = $this->getClientFlag($size);
		if (!strcmp($flag,"")) $error = 1;
		if (!$error)
		{
			return '<img src="' . $flag . '">';
		}
		//else
      return "";
	}
};

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

struch23 wrote:now i get this:

Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in /home/xxxx/public_html/extreme/search/includes/ip.php on line 27


this is the full archive ip.php

Code: Select all

<?php

define('SMALL', 0);
define('BIG',   1);

class ClientInfo {

   var $flag_dirs = array(SMALL => 'assets/flags/small', BIG => 'assets/flags/big');
   var $flag_ext  = 'png';

   function getctrybycode($code) {
      $countryArray = array();
      $input = "includes/countries.dat";
      $fd = fopen($input,"r") or die("Error: cannot open $input!");
      while ($buffer = fgets($fd,4096))
      {
         $buffer = preg_replace("/\n/","",$buffer);   //chomp()
         $pieces = explode(",",$buffer);
         $countryCode = $pieces[0]; $countryName = $pieces[1];
         $countryArray[$countryCode] = $countryName;
      }
      fclose($fd);
      return $countryArray[$code];
   } 


	function getctrybyhost($hostname) {

		return($this->getctrybycode($this->getctrycodebyhost($hostname)));
	}

	function getctrycodebyhost($hostname) {
		return(substr(strrchr($hostname,'.'),1));
	}

	function MaskOtherIP($IP) {

		if($IP==getenv("REMOTE_ADDR"))
			    return($IP);

				 $IP=strtr($IP,"0123456789","##########");
				 return($IP);
	}

	function getClientIP() {
		$IP = getenv('REMOTE_ADDR');
		return $IP;
	}

	function getClientHostname()
	{
		$error = 0;
		$IP = $this->getClientIP();
		$hostname = gethostbyaddr($IP);

	   if(!strcmp($hostname,$IP)) $error = 1;		// if failure, gethostbyaddr() returns the IP
		if (!$error) //if no error
		{
			return $hostname;
		}			
		//else
		return "";
	}

	function getClientCountry()
	{
		$error = 0;
		$hostname = $this->getClientHostname();
		if (!strcmp($hostname,"")) $error = 1;
		if (!$error)
		{
			$country = $this->getctrybyhost($hostname);
			return $country;
		}
		//else
      return "";
	}

	function getClientFlag($size)
	{
		$error = 0;
		$hostname = $this->getClientHostname();
		if (!strcmp($hostname,"")) $error = 1;
		if (!$error)
		{
			$country_code = strtolower($this->getctrycodebyhost($hostname));
			$file_name = $this->flag_dirs[$size] . '/' . $country_code . '.' . $this->flag_ext;
			if (is_readable($file_name))
			{
				return $file_name;
			}
		}
		//else
      return "";
	}

	function getClientFlagHTML($size)
	{
		$error = 0;
		$flag = $this->getClientFlag($size);
		if (!strcmp($flag,"")) $error = 1;
		if (!$error)
		{
			return '<img src="' . $flag . '">';
		}
		//else
      return "";
	}
};
For some reason your functions were declared cfunction... this should fix it.
struch23
Forum Newbie
Posts: 4
Joined: Tue Aug 01, 2006 5:42 pm

Post by struch23 »

Thank you very much.

Now works fine!



Thanks again...
Post Reply