Combining one banner + website url into one page in php and then display in browser

Discussion in 'PHP' started by globalcashsite, Apr 21, 2011.

  1. #1
    Hi guys

    I want to combine one banner + website url (not local in same folder) into one php page and then display into browser. Here is my code

    gcsurls.php
    <?php
    header("Location: http://www.yahoo.com");
    ?>
    (If I acess this url this works fine and I am redirected to yahoo.com)

    test2.php
    <a rel="nofollow" target="_blank" href=http://goldenwealth.biz/?ref=globalcashsite><img
    src="http://goldenwealth.biz/images/468x60.gif" width="468" height="60"></a>
    <?
    include("/home/gcsite/public_html/urls/gcsurls.php");
    ?>

    When I access http://www.globalcashsite.com/urls/test2.php? it gives error

    Warning: Cannot modify header information - headers already sent by (output started at /home/gcsite/public_html/urls/test2.php:3) in /home/gcsite/public_html/urls/gcsurls.php on line 2

    Previously I was using notepad to edit php file but then I used CuteFTP to edit file and upload. Please help me how to solve this issue.

    Thank you

    GlobalCashSite
     
    globalcashsite, Apr 21, 2011 IP
  2. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    header() function in php must be called before any actual output is sent to the client (read this php.net/manual/en/function.header.php)

    In your code, you output the banner first, then header is called next which caused the error that you described.

    Maybe you can use $ycontent = file_get_contents("www.yahoo.com"); first, then append the banner to the top of "ycontent";

    $ycontent = "your banner".$ycontent;

    Little John
     
    littlejohn199, Apr 21, 2011 IP
  3. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi littlejon,

    Your suggestion worked and that error disappeared. Now my code is as follows:

    <?
    $site = include("/home/gcsite/public_html/urls/gcsurls.php");
    $banner = '<a rel="nofollow" target="_blank" href=http://goldenwealth.biz/?ref=globalcashsite><img
    src="http://goldenwealth.biz/images/468x60.gif" width="468" height="60"></a>';
    $show = $banner.$site;
    echo $show;
    ?>

    But now it does not display banner and browser redirected to yahoo website. I want to show banner at top and yahoo website below banner. How I can do this? I think this redirect will not work that I used in gcsurls.php as follows:

    <?php
    header("Location: http://www.yahoo.com");
    ?>

    Please help me?

    GlobalCashSite
     
    globalcashsite, Apr 21, 2011 IP
  4. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You don't want to use header("Location ....."); because that will redirect users to yahoo.com website.

    So, in gcsurls.php, you want to get the content of yahoo.com. You would do this

    <?php
    $ycontent = file_get_contents("http://www.yahoo.com");
    echo $ycontent;
    ?>

    Little John
     
    littlejohn199, Apr 21, 2011 IP
    globalcashsite likes this.
  5. globalcashsite

    globalcashsite Peon

    Messages:
    806
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi John,

    Thank you very much for your quick help, this solved my problem. I am sure I also can open two sites at same time at same page. :)

    GlobalCashSite
     
    globalcashsite, Apr 24, 2011 IP
  6. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Glad I could help you!
     
    littlejohn199, Apr 25, 2011 IP