SMFHacks.com

Ad Seller Pro => Support => Topic started by: amwebby on February 23, 2013, 03:00:02 am

Title: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 03:00:02 am
I've just started using eBay Partner Network and they have a nice custom banner that performs a search within a specified country for a particular item and shows the results within that ad.

It works well but, as my board is global, I wanted the ad to search the country based on the users ip address. eBay can't do this for some reason so I thought I'd follow their guidance to generate a separate page for each county and serve up the country-specific search via that.

I found this php script (code below) at http://www.phptutorial.info/iptocountry/identification_of_specific_countries.html and adapted it with US.html and UK.html containing the relevant ad banner javascript.

You then place a series of php files for the US ip addresses in a folder called ip_files and the script uses them to determine if the browsers ip address is in that range.

It works fine as a standalone script as you can see here http://www.amoc.org/sandbox/us_or_them.php but, when I put it in AdSeller as Custom Code with "Is PHP Code?" checked it returns the error, "We have detected an error in your syntax for your php ad code"

I placed the html files and the ip_files in the root directory of my forum. Is that correct? If not where should they be and, if so, what is the error?

Code: [Select]
<?php
$IPaddress
=$_SERVER['REMOTE_ADDR']; 
$two_letter_country_code=iptocountry($IPaddress); 

if (
$two_letter_country_code=="US"){ 
     include(
"US.html"); 
      die(); 
    }else{ 
     include(
"UK.html"); 
      die(); 
    } 

function 
iptocountry($ip) {    
    
$numbers preg_split"/\./"$ip);    
    include(
"ip_files/".$numbers[0].".php"); 
    
$code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);    
    foreach(
$ranges as $key => $value){ 
        if(
$key<=$code){ 
            if(
$ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} 
            } 
    } 
    if (
$two_letter_country_code==""){$two_letter_country_code="unkown";} 
    return 
$two_letter_country_code

?>

Edit: I found this http://www.smfhacks.com/index.php/topic,5626.0.html (http://www.smfhacks.com/index.php/topic,5626.0.html) and tried disabling the error checking. It then accepted the ad but nothing shows at the chosen locations, leading me to suspect either there IS an error in the code or I've got the locations of the ip_files folder and html files wrong?
Title: Re: Error in PHP custom code?
Post by: SMFHacks on February 23, 2013, 09:35:44 am
Don't include the <?php and ?> in your code
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 09:39:34 am
I already tried that. I still get the error "We have detected an error in your syntax for your php ad code"
Title: Re: Error in PHP custom code?
Post by: SMFHacks on February 23, 2013, 09:41:49 am
I would try putting in the full path to any of the file you use in the include statement.
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 09:45:09 am
Tried that. Same error
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 09:52:05 am
I removed the error checking and the ad now shows but nothing shows below it, a sure sign that the php script isn't resolved.
Title: Re: Error in PHP custom code?
Post by: SMFHacks on February 23, 2013, 09:53:39 am
Well I would move all the code to it's own file and just include.
And also remove the die statement.
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 09:54:37 am
I already have it stand alone. How to include?
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 09:56:19 am
Removed the die statement and it now works but is not centered, despite my choosing center.
Title: Re: Error in PHP custom code?
Post by: SMFHacks on February 23, 2013, 09:57:14 am
add center html tags around the code

echo '<center>';


echo '</center>';
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 10:00:04 am
That did it. I wonder if the die statement was what was triggering the error code? I'll have to try re-enabling the error checking in adseller.php
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 10:09:31 am
Aargh! Just tried it in message index and the formatting is awry!

I think best to include the standalone file. How do I do that please?
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 10:27:31 am
I just tried

Code: [Select]
echo '<center>';
include("http://www.amoc.org/sandbox/us_or_them.php");
echo '</center>';

It worked fine in the board index but had the same effect on the formatting as above.
Title: Re: Error in PHP custom code?
Post by: SMFHacks on February 23, 2013, 12:26:24 pm
Well your include file needs the center tags after <body> and before </body>
Code: [Select]
<html>
<body>
<script type="text/javascript" src='http://adn.ebay.com/files/js/min/jquery-1.6.2-min.js'></script>
<script type="text/javascript" src='http://adn.ebay.com/files/js/min/ebay_activeContent-min.js'></script>
<script charset="utf-8" type="text/javascript">
document.write('\x3Cscript type="text/javascript" charset="utf-8" src="http://adn.ebay.com/cb?programId=1&campId=5337255373&toolId=10026&customId=EB3&keyword=Aston+Martin&width=468&height=60&font=1&textColor=000000&linkColor=0000AA&arrowColor=8BBC01&color1=709AEE&color2=[COLORTWO]&format=SimpleText&contentType=TEXT_ONLY&enableSearch=n&usePopularSearches=n&freeShipping=n&topRatedSeller=n&itemsWithPayPal=n&descriptionSearch=n&showKwCatLink=n&excludeCatId=&excludeKeyword=&catId=&disWithin=200&ctx=n&autoscroll=n&title=an+Aston+Martin&flashEnabled=' + isFlashEnabled + '&pageTitle=' + _epn__pageTitle + '&cachebuster=' + (Math.floor(Math.random() * 10000000 )) + '">\x3C/script>' );
</script>
</body>
</html>
Title: Re: Error in PHP custom code?
Post by: amwebby on February 23, 2013, 12:34:50 pm
I tried that. Even put it in a div constraining the height and width and it still seems to escape the boundaries. Only in message index and after 1st post. Board index and the one I call from my Joomla site via SSI work fine. No idea why.