Link to home
Start Free TrialLog in
Avatar of badwolfff
badwolfffFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Could anyone please explain why I am seeing this php error and how I could fix it?

On my development site I am getting a php error towards the base of the page:
http://demo.missionfamily.org/index.php?route=common/home

I am attaching the php file that is mentioned in the error. Pro-Ads-Main.php

please help!

thanks in advance
Avatar of Heather Ritchey
Heather Ritchey
Flag of United States of America image

The error reads more like there is a problem with the feed being used. Try rechecking the settings of that plugin and see if you can test a different feed/ad - whatever it is that it's fetching, parsing, displaying.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I believe the trouble is near line 201.
<?php
class Pro_Ads_Main {	


	public $IP = '127.0.0.1';
	
	
	
	public function __construct() 
	{
		$this->get_visitor_ip();
		
		add_action( 'wp_loaded', array( $this, 'wpproads_rss' ) );	
	}
	
	
	
	
	
	
	/*
	 * Get Visitor IP
	 *
	 * @access public
	 * @return IP
	*/
	public function get_visitor_ip()
	{
		// Get the visitor IP    
        if(isset($_SERVER['HTTP_X_FORWARD_FOR']))
        {
            $this->IP = $_SERVER['HTTP_X_FORWARD_FOR'];
        } 
		else 
		{
            $this->IP = $_SERVER['REMOTE_ADDR'];
		}	
	}
	
	
	
	
	
	
	/*
	 * Get Visitor Device
	 *
	 * @since v4.2.9
	 * @access public
	 * @return string
	*/
	public function get_visitor_device()
	{
		global $pro_ads_browser;
		
		$device = 'desktop';
		
		if( $pro_ads_browser->isMobile() )
		{
			$device = 'mobile';
		}
		elseif( $pro_ads_browser->isTablet() )
		{
			$device = 'tablet';
		}
		
		return $device;
	}
	
	
	
	
	
	/*
	 * daily update function
	 *
	 * @access public
	 * @return array
	*/
	public function daily_updates( $force = 0) 
	{	
		global $pro_ads_campaigns, $pro_ads_banners;
		
		$last_update = get_option( 'wpproads_daily_update', 0 );
		$today = date('Y').date('m').date('d');
		
		if( $last_update < $today || $force )
		{
			$pro_ads_campaigns->update_campaign_status();
			
			$banners = $pro_ads_banners->get_banners( 
				array(
					'meta_key'       => '_banner_contract',
					'meta_value'     => 3
				)
			);
			
			foreach( $banners as $banner )
			{
				$pro_ads_banners->update_banner_status( $banner->ID );
			}
				
			update_option( 'wpproads_daily_update', $today );
		}
	}
	
	
	
	
	
	
	/*
	 * Check if ADD_ON Buy and Sell ads is active
	 *
	 * @access public
	 * @return array
	*/
	public function buyandsell_is_active() 
	{
		global $pro_ads_bs_templates;
		
		if( method_exists( $pro_ads_bs_templates, 'buyandsell_placeholder' ) )
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	
	
	/*
	 * Check if ADD_ON Buy and Sell Woocommerce ads is active
	 *
	 * @access public
	 * @return array
	*/
	public function buyandsell_woo_is_active() 
	{
		global $pro_ads_bs_woo_templates;
		
		if( method_exists( $pro_ads_bs_woo_templates, 'buyandsell_placeholder' ) )
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	
	
	
	/*
	 * Check if ADD_ON Geo Targetting
	 *
	 * @access public
	 * @return bool
	*/
	public function pro_geo_targeting_is_active() 
	{
		global $pro_geo_targeting;
		
		if( method_exists( $pro_geo_targeting, 'get_user_geo_data' ) )
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	
	
	
	
	
	
	
	/*
	 * Geo Info - get city and country
	 *
	 * @access public
	 * @return array
	*/
	public function get_geo_info() 
	{	
		$ip = $_SERVER['REMOTE_ADDR'];
		$url = "http://www.geoplugin.net/xml.gp?ip=".$ip;
		//$url = "http://www.geoplugin.net/php.gp?ip=".$ip;
		
		$ch = curl_init();
		$timeout = 5; // set to zero for no timeout
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$content = curl_exec($ch);
		curl_close($ch);
		
		// since V4.1.4 till V4.1.6 and used again since V4.1.8
		$xml = simplexml_load_string($content);
		// since V4.1.7
		//$data = unserialize($content);
		
		/*if( $data !== false )
		{
			$geo = array(
				'city'         => !empty($data['geoplugin_city']) ? $data['geoplugin_city'] : '',
				'country'      => !empty($data['geoplugin_countryName']) ? $data['geoplugin_countryName'] : '',
				'country_cd'   => !empty($data['geoplugin_countryCode']) ? $data['geoplugin_countryCode'] : '',
				'continent_cd' => !empty($data['geoplugin_continentCode']) ? $data['geoplugin_continentCode'] : ''
			);
		}*/
		
		if ($xml !== false) 
		{
			$geo = array(
				'city'         => !empty($xml->geoplugin_city) ? $xml->geoplugin_city : '',
				'country'      => !empty($xml->geoplugin_countryName) ? $xml->geoplugin_countryName : '',
				'country_cd'   => !empty($xml->geoplugin_countryCode) ? $xml->geoplugin_countryCode : '',
				'continent_cd' => !empty($xml->geoplugin_continentCode) ? $xml->geoplugin_continentCode : '',
			);
		}
		else
		{
			$geo = array('city' => '', 'country' => '', 'country_cd' => '', 'continent_cd' => '');
		}
		
		return $geo;
	}
	
	
	
	
	
	
	/*
	 * Detect search engine bots
	 *
	 * @access public
	 * @return int $isbot
	*/
	public function detect_bots()
	{
		$isbot = 0;
		$bots = array(
			'Arachnoidea',
			'FAST-WebCrawler',
			'Fluffy the spider',
			'Googlebot',
			'Gigabot',
			'Gulper',
			'ia_archiver',
			'MantraAgent',
			'MSN',
			'Scooter',
			'Scrubby',
			'Teoma_agent1',
			'Winona',
			'ZyBorg',
			'WebCrawler',
			'W3C_Validator',
			'WDG_Validator',
			'Zealbot',
			'Robozilla',
			'Almaden'
		);
		
		foreach( $bots as $i => $bot )
		{
			if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), $bot))
			{
				$isbot = 1;
				return $isbot;
			}
		}
		
		return $isbot;
	}
	
	
	
	
	
	
	/*
	 * Adzone RSS feed
	 *
	 * @access public
	 * @return rss
	*/
	public function wpproads_rss( $adzone_id = 0 )
	{
		global $pro_ads_adzones;
		
		if( !empty( $adzone_id ) || isset( $_GET['wpproads-rss'] ) && !empty( $_GET['wpproads-rss'] ) )
		{
			$html = '';
			$adzoneID = !empty( $adzone_id ) ? $adzone_id : $_GET['wpproads-rss'];
			
			// http://kb.mailchimp.com/merge-tags/rss-blog/rss-item-tags
			// Mailchimp RSS code
			// *|RSSITEMS:|* *|RSSITEM:CONTENT_FULL|* *|END:RSSITEMS|*
			
			header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
			
			$html.= '<?xml version="1.0" encoding="UTF-8"?>';
			$html.= '<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">';	
				$html.= '<channel>';
					$html.= '<title>'.get_bloginfo('name').'</title>';
					$html.= '<atom:link href="'.get_bloginfo('url').'/?wpproads-rss='.$adzoneID.'" rel="self" type="application/rss+xml" />';
					$html.= '<link>'.get_bloginfo('url').'</link>';
					$html.= '<description><![CDATA['.get_bloginfo('description').']]></description>';
					$html.= '<lastBuildDate>'.date('r', time()).'</lastBuildDate>';
					$html.= '<language>'.get_bloginfo('language').'</language>';
					$html.= '<generator>http://wordpress-advertising.com/?v='.WP_ADS_VERSION.'</generator>';
					
					$html.= '<item>';
						$html.= '<title>Adzone</title>';
						$html.= '<link>'.get_bloginfo('url').'</link>';
						$html.= '<guid isPermaLink="false">'.get_bloginfo('url').'/?wpproads-rss='.$adzoneID.'</guid>';
						$html.= '<description><![CDATA[ '.get_the_title( $adzoneID ).' ]]></description>';
						$html.= '<content:encoded><![CDATA['.$pro_ads_adzones->display_adzone( $adzoneID ).']]></content:encoded>';
						$html.= '<pubDate>'.date('r', time()).'</pubDate>';
					$html.= '</item>';
	
				$html.= '</channel>';
			$html.= '</rss>';
			
			echo $html;
			
			exit();
		}
	}
	
	
	
}

Open in new window

Avatar of badwolfff

ASKER

Hi

thanks. I see that and I have contacted the plugin developers but there is a weekend in the middle and I need a solution as the client and others can see the error. Is there a way that I can temporarily hide that error from showing while I get a solution worked out? Apart from the error the plugin's output iself is still correct and consistent.

thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks I will try. By the way. Why does it work despite the error?
There are a cascade of things that happen in this PHP script, and it's built on house-of-cards assumptions.  First of all, the error does not always occur, so that would explain some of why it might work.  Second, nobody with a computer science background would write code with that kind of assumptions; basically PHP is a "loosely typed" language and many different things can mean "I screwed up."  Notably, there are a variety of ways to interpret a false, zero, empty, null, etc.  The script does not check for these conditions properly.  In other words, if everything works right, the web page looks OK.  If some things fail and not others, the web page might look OK.  Certain kinds of failures will be hidden and certain kinds will be noticed.

If you hide the errors with something like error_reporting(0) you really, really want to remember that you've set a time bomb in your code, and you want to get the developers to remediate the issue ASAP.  This is the kind of approach that can mask a multitude of problems, some with consequences for data loss, etc.  So while that may be an expedient today, it cannot be left in place.

This appears to be a WordPress question.  At E-E we have a WordPress zone.  You might consider posting a question there about best-practices to get the kind of information you need from this PHP programming.  I'll bet there are popular and thoroughly debugged scripts that can do this without error.
If the error_reporting(0); works to hide that for the weekend while you wait for the author's support, be sure to let them know you have added that and either remove when they go to trouble shoot, or allow them access so they can.

When I saw the list of errors, I was seeing html tags throwing the errors. Which usually means that what it's parsing isn't properly formatted xml.
Probably want to check the validity of the document, too.  The W3C validator is fairly strict, but even so, hundreds of markup errors can't be what you want.
http://validator.w3.org/check?uri=http%3A%2F%2Fdemo.missionfamily.org%2Findex.php%3Froute%3Dcommon%2Fhome&charset=%28detect+automatically%29&doctype=Inline&group=0
Ray, yeah - that's exactly what I was trying to get at. The plugin is pulling a feed from somewhere and something in it isn't formatted/validated right. That's usually out of the site owners control where the plugin is when it's a feed elsewhere. But hopefully the plugin author will answer his support ticket and see that some additional checks etc need to be added in the plugin to prevent the errors.

I maintain the feedcommander rss feed reader tool and I have checks in it so that if the feed is badly formatted, it will stop and show one single message that the feed is not a valid format.
^^ @Dzynit:  +1 for doing it the right way!!