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
badwolfffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DzynitCommented:
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.
0
Ray PaseurCommented:
Probably the issue occurs in the get_geo_info() method.  It uses cURL but does not do appropriate error checking, using the $content variable without knowing what it contains.  If you paid for this script, go back and ask the authors to add cURL error handling.  This will be a transient error, difficult to reproduce because the script as written cannot be unit tested.  The error will crop up any time the GeoPlugin API is down, or even slow to respond.
0
Ray PaseurCommented:
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

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

badwolfffAuthor Commented:
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
0
DzynitCommented:
You can try putting error_reporting(0); at the beginning of your theme's functions.php file - but this doesn't always work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badwolfffAuthor Commented:
Thanks I will try. By the way. Why does it work despite the error?
0
Ray PaseurCommented:
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.
0
DzynitCommented:
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.
0
Ray PaseurCommented:
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
0
DzynitCommented:
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.
0
Ray PaseurCommented:
^^ @Dzynit:  +1 for doing it the right way!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.