PHP Include error

Discussion in 'PHP' started by ASM Design, Sep 16, 2008.

  1. #1
    Hi guys,

    I'm trying to implement some code in an include and it seems to be writing out the actual code instead of just showing the adsense. I'm wondering if perhaps the code in the include file is missing something to stop the rest from showing? I've attached it below:

    <?php
    $rand = rand(1,2);
    if ($rand == 1) //Alex's Code
    print '<script type="text/javascript"><!--
    google_ad_client = "pub-3397443514176608";
    /* 468x60, Vitality Post created 16/09/08 */
    google_ad_slot = "6505292334";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    elseif ($rand == 2) //Quail's code
    print '<script type="text/javascript"><!--
    google_ad_client = "pub-8340578488567063";
    /* Vitality Post */
    google_ad_slot = "1305793207";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    ?>
    Code (markup):
    You can see the error on this page: http://tinyurl.com/6xsn2m

    Thanks for any help on this!
     
    ASM Design, Sep 16, 2008 IP
  2. eugen

    eugen Active Member

    Messages:
    154
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Try changing the code to this:

    
    <?php
    $rand = rand(1,2);
    if ($rand == 1)
    {
    //Alex's Code
    ?>
    <script type="text/javascript"><!--
    google_ad_client = "pub-3397443514176608";
    /* 468x60, Vitality Post created 16/09/08 */
    google_ad_slot = "6505292334";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php
    } elseif ($rand == 2) 
    {
    //Quail's code
    ?>
    <script type="text/javascript"><!--
    google_ad_client = "pub-8340578488567063";
    /* Vitality Post */
    google_ad_slot = "1305793207";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <?php
    }
    ?>
    
    Code (markup):
     
    eugen, Sep 16, 2008 IP
  3. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #3
    The included file contains no error.
     
    nabil_kadimi, Sep 16, 2008 IP
  4. ASM Design

    ASM Design Peon

    Messages:
    502
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #4
    any guesses as to why its showing up wrong Nabil?
     
    ASM Design, Sep 18, 2008 IP
  5. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try -

    
    <?php
    
    
    $rand = rand(1,2);
    if ($rand == "1") 
    echo '
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-3397443514176608";
    /* 468x60, Vitality Post created 16/09/08 */
    google_ad_slot = "6505292334";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    elseif ($rand == 2) //Quail's code
    print '<script type="text/javascript"><!--
    google_ad_client = "pub-8340578488567063";
    /* Vitality Post */
    google_ad_slot = "1305793207";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    ';
    ?>
    
    PHP:
     
    Funk-woo10, Sep 18, 2008 IP
  6. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hold ignor that just notice you have php in the middle..wait .....1 sec...
     
    Funk-woo10, Sep 18, 2008 IP
  7. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?php
    $rand = rand(1,2); ///
    if ($rand == "1")
    {
    echo '
    <script type="text/javascript"><!--
    google_ad_client = "pub-3397443514176608";
    /* 468x60, Vitality Post created 16/09/08 */
    google_ad_slot = "6505292334";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    ';
    }
    
    elseif ($rand == 2)
    {
    echo '<script type="text/javascript"><!--
    google_ad_client = "pub-8340578488567063";
    /* Vitality Post */
    google_ad_slot = "1305793207";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    ';
    }
    ?>
    
    PHP:
     
    Funk-woo10, Sep 18, 2008 IP
  8. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #8
    hold on...3rd version coming..
     
    Funk-woo10, Sep 18, 2008 IP
  9. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #9
    this works fine for me -

    
    <?php
    $rand = rand(1,2); ///
    if ($rand == "1")
    {
    echo '
    <script type="text/javascript"><!--
    google_ad_client = "pub-3397443514176608";
    /* 468x60, Vitality Post created 16/09/08 */
    google_ad_slot = "6505292334";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    }
    
    elseif ($rand == "2")
    {
    echo '
    <script type="text/javascript"><!--
    google_ad_client = "pub-8340578488567063";
    /* Vitality Post */
    google_ad_slot = "1305793207";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    }
    ?>
    
    PHP:
     
    Funk-woo10, Sep 18, 2008 IP
  10. ASM Design

    ASM Design Peon

    Messages:
    502
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks Funk, worked perfectly :D
     
    ASM Design, Sep 18, 2008 IP