Facebook  Twitter 

SMFHacks.com

+- +-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 12356
Latest: how to logo design
New This Month: 7
New This Week: 1
New Today: 1
Stats
Total Posts: 40076
Total Topics: 7055
Most Online Today: 30
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 19
Total: 19

Author Topic: Error in PHP custom code?  (Read 5028 times)

0 Members and 1 Guest are viewing this topic.

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Error in PHP custom code?
« 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 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?
« Last Edit: February 23, 2013, 04:26:48 am by amwebby »

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15040
    • View Profile
Re: Error in PHP custom code?
« Reply #1 on: February 23, 2013, 09:35:44 am »
Don't include the <?php and ?> in your code
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #2 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"

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15040
    • View Profile
Re: Error in PHP custom code?
« Reply #3 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.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #4 on: February 23, 2013, 09:45:09 am »
Tried that. Same error

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #5 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.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15040
    • View Profile
Re: Error in PHP custom code?
« Reply #6 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.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #7 on: February 23, 2013, 09:54:37 am »
I already have it stand alone. How to include?

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #8 on: February 23, 2013, 09:56:19 am »
Removed the die statement and it now works but is not centered, despite my choosing center.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15040
    • View Profile
Re: Error in PHP custom code?
« Reply #9 on: February 23, 2013, 09:57:14 am »
add center html tags around the code

echo '<center>';


echo '</center>';
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #10 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

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #11 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?

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #12 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.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 15040
    • View Profile
Re: Error in PHP custom code?
« Reply #13 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>
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline amwebby

  • Community Suite Customer
  • Sr. Member
  • ******
  • Posts: 306
    • View Profile
Re: Error in PHP custom code?
« Reply #14 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.

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
3927 Views
Last post June 25, 2008, 08:14:02 pm
by SMFHacks
4 Replies
3382 Views
Last post April 29, 2010, 08:23:00 pm
by cheers101
5 Replies
3114 Views
Last post November 07, 2010, 02:35:36 pm
by Wickedgood
3 Replies
2345 Views
Last post February 23, 2011, 06:06:47 pm
by SMFHacks
4 Replies
3031 Views
Last post March 01, 2011, 01:55:01 am
by kodbg

+- Recent Topics

Cannot install Gallery Pro on SMF 2.1 RC2 by Hatshepsut
March 19, 2020, 12:55:00 am

Newbie questions by SMFHacks
March 08, 2020, 09:28:17 am

Update detect mobile mode PHP5 to PHP7 by Plus
March 05, 2020, 11:19:05 am

Just a hello by Plus
March 05, 2020, 11:05:56 am

Enotify Copyright Problem by SMFHacks
March 04, 2020, 09:21:09 pm

Cannot import by shawnb
March 02, 2020, 12:17:00 pm

Error message with latest SMF 2.1 Github build by Hatshepsut
March 01, 2020, 10:06:10 am

[Mod]Avatars Display Integration by SMFHacks
February 15, 2020, 07:30:47 pm

[Mod]BBC Message Boxes 1.0 by SMFHacks
February 15, 2020, 07:26:46 pm

[Mod]Stack Trace by live627 by SMFHacks
February 15, 2020, 07:21:33 pm

Powered by EzPortal