Activity Stream
48,167 MEMBERS
63365 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 10 of 10
  1.     
    #1
    Member

    Default Use php include for certain div of the page

    Hello,

    I have this syntax:

    Code: 
    if ( $CountryCode == RS || $CountryCode == ME ) {
    	require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html ";  
    
    }
    I would like to access certain div o the above page for example


    Code: 
    if ( $CountryCode == RS || $CountryCode == ME ) {
    	require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html#nameovDiv1";  
    
    }
    than

    Code: 
    if ( $CountryCode == RS || $CountryCode == ME ) {
    	require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html#nameovDiv2";  
    
    }
    Code: 
    if ( $CountryCode == RS || $CountryCode == ME ) {
    	require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html#nameovDiv3";  
    
    }
    And make just that div visible... On page ads/et300x250rsTEST.html i would add all my advertisment in divs, and return right one when user from specific country visits the site.

    Qusetion is - How to use php include to include just part of the page which is on mine server, so i have full control of it, i can add whatever code there too [et300x250rsTEST.html] ?

    Thanks
    igordr Reviewed by igordr on . Use php include for certain div of the page Hello, I have this syntax: if ( $CountryCode == RS || $CountryCode == ME ) { require $_SERVER."/ads/et300x250rsTEST.html "; } Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Respected Member
    Without seeing the rest of the code it would be hard to say.

    You will have to use javascript to turn the div back to display from none.

    Are you writing the entire html from the php program? If not just add the javascript in html to display the div you want. How are you determining the country code?

  4.     
    #3
    Member
    Hi mate, thanks for reply.

    This is the full code:

    Code: 
    <?php
    //connect to db
    $con = mysql_connect('localhost', 'xxxxxxx_user', 'passss') or die(mysql_error());
    
    mysql_select_db('xxxxxxx_base', $con);
    
    //Get the parameters
    if ($_GET["ip"]){
      $ip = mysql_real_escape_string(trim($_GET["ip"]), $con);
    } else {
      $ip = getenv('REMOTE_ADDR');
    }
    
    //Run the IP location query
    $ipQuery = mysql_query("SELECT * FROM `ip_group_city` where `ip_start` <= INET_ATON('$ip') order by ip_start desc limit 1;", $con);
    $ipData = mysql_fetch_array($ipQuery);
    $nbResults = (bool)mysql_num_rows($ipQuery);
    
    $CountryCode = $ipData['country_code'];
    
    if ( $CountryCode == RS || $CountryCode == ME ) {
    	require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html";  
    
    } 
    
    else if ( $CountryCode == HR || $CountryCode == BA ) {
    	include $_SERVER['DOCUMENT_ROOT']."/ads/et300x250hr.html"; 
    
    }
    
    else if ( $CountryCode == DE || $CountryCode == AU || $CountryCode == CH ) {
    	include $_SERVER['DOCUMENT_ROOT']."/ads/sp300x250deAUch.html"; 
    }
    
    else {  
    	include $_SERVER['DOCUMENT_ROOT']."/ads/300x250else.html"; 
    
    }
    
    
    ?>
    This is code for showing desired advertisement based on user location... This is just one part of ads on my site, as you see 300x250 banner. Am i going to copy and paste this code for every ad unit, and how to avoid that? Also, i want to connect to database just once...
    May you help me with that?

    Thanks

  5.     
    #4
    Member
    Or you could shorten it to

    PHP Code: 
    if (file_exists($_SERVER['DOCUMENT_ROOT']."/ads/et300x250".$CountryCode.".html")) {
    include(
    $_SERVER['DOCUMENT_ROOT']."/ads/et300x250".$CountryCode.".html");
    } else {
    include 
    $_SERVER['DOCUMENT_ROOT']."/ads/300x250else.html"

    Or even better just wrap it into a function and call it wherever you need to call an ad

  6.     
    #5
    Member
    Thanks for reply bluefrogx!

    May you help me with wrap all this into the function and call it, how code should look like?

    Thanks a lot.
    Igor

  7.     
    #6
    Member
    This site is using a hacked database of W junction
    Last edited by Gavo; 4th Jan 2015 at 02:03 PM.

  8.     
    #7
    Member
    Gavo, your post is very interested, but where i may find and download GeoIP.dat and geoip.inc ?
    Also, how i can use statements as

    if ( $CountryCode == RS || $CountryCode == ME ) {
    require $_SERVER['DOCUMENT_ROOT']."/ads/et300x250rsTEST.html";

    }

    else if ( $CountryCode == HR || $CountryCode == BA ) {
    include $_SERVER['DOCUMENT_ROOT']."/ads/et300x250hr.html";

    }

    else if ( $CountryCode == DE || $CountryCode == AU || $CountryCode == CH ) {
    include $_SERVER['DOCUMENT_ROOT']."/ads/sp300x250deAUch.html";
    }

    else {
    include $_SERVER['DOCUMENT_ROOT']."/ads/300x250else.html";

    }
    May you write me code please, or help me with that?

    Thanks

  9.     
    #8
    Member
    This site is using a hacked database of W junction
    Last edited by Gavo; 4th Jan 2015 at 02:03 PM.

  10.     
    #9
    Member
    Hi,
    I would say, change the page you are including to a php file too (as you probably already know, php can contain html or you can use php to echo it).
    That way you don't even need an if statement in your main page, you just move those if statements to the page containing the ads, echo'ing the right div based on your "CountryCode" variable.
    Good luck.

  11.     
    #10
    Member
    Website's:
    WarezRocker.info Share4U.org Imdb.WarezRocker.info DownTurko.org Host-Palace.com HeroTurko.pro
    make functions for each ads,and call those ads function(country based);
    like:

    if ( $CountryCode == RS || $CountryCode == ME ) {
    functionnameRSorME;

    }

    else if ( $CountryCode == HR || $CountryCode == BA ) {
    functionnameHR;

    }

    else if ( $CountryCode == DE || $CountryCode == AU || $CountryCode == CH ) {
    functionnameRSorME;
    }

    else {
    functionname;

    }

    and add those ads in functions.if its not cleared to you,then maybe i can help but later.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Selling] Post Button (Include PSD)
    By Samar in forum Services
    Replies: 0
    Last Post: 26th Aug 2012, 06:08 PM
  2. [Selling] 4 Website for Sale (include 2 PR2 + 1 PR1)
    By freehealthylife.com in forum Completed Transactions
    Replies: 5
    Last Post: 28th Sep 2011, 11:05 AM
  3. vbulletin 4 php include
    By Klinzter in forum Webmaster Discussion
    Replies: 0
    Last Post: 31st Aug 2011, 09:13 PM
  4. [PHP]Include functions scope
    By Robin H in forum Web Development Area
    Replies: 6
    Last Post: 10th Jan 2011, 06:01 PM
  5. Replies: 0
    Last Post: 13th Jan 2008, 01:32 AM

Tags for this Thread

BE SOCIAL