Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

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

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43260
Total Topics: 7518
Most Online Today: 297
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 1
Guests: 285
Total: 286

Author Topic: Error in PHP custom code?  (Read 7006 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: 16436
    • 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: 16436
    • 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: 16436
    • 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: 16436
    • 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: 16436
    • 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
4936 Views
Last post June 25, 2008, 08:14:02 pm
by SMFHacks
4 Replies
5856 Views
Last post April 29, 2010, 08:23:00 pm
by cheers101
5 Replies
4399 Views
Last post November 07, 2010, 02:35:36 pm
by Wickedgood
3 Replies
3723 Views
Last post February 23, 2011, 06:06:47 pm
by SMFHacks
4 Replies
4783 Views
Last post March 01, 2011, 01:55:01 am
by kodbg

+- Recent Topics

No thumbnails on new uploads by Tonyvic
Today at 06:26:18 am

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal