SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Assigning an include file to a variable

    Here is the code I have at the top of my page:

    flush();
    ob_start();
    include('preventSpam.php');
    $preventSpam = ob_get_clean();


    Here is the code that I have towards the bottom of my page:

    $pageIntro .= "<p>$formFirstName, thank you for registering. An email has been sent containing a confirmation link. Click on this link to finalize your registration. You will then be able to login and conduct keyword searches and post your own testimonials.</p>

    <h1>Spam Filters</h1>

    <p>Sometimes legitimate email mistakingly gets flagged as spam by internet service providers. Take action now to ensure your confirmation email does not get filtered into your junk or bulk mail folder.</p>";

    echo $preventSpam;


    Here is the error I'm getting when the page is loaded:

    Warning: Cannot modify header information - headers already sent by (output started at /home3/recordau/public_html/newVersion/register.php:876) in/home3/recordau/public_html/newVersion/startSession.php on line 4

    What is the best way to display the contents of an include file since this doesn't seem to work?

    Thanks!

    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Is there a particular reason you need to do all this instead of include'ing the file where you have the echo statement?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I tried that and got an error. You see, I need the contents of that external file to be added to the $pageIntro variable so later the whole thing can be displayed, like this:

    $pageIntro .= " contents of the include file ";

    What is the best way to do this?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    does preventSpam.php actually include PHP code? Or is it just HTML?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's just HTML.
    Convert your dollars into silver coins. www.convert2silver.com

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    file_get_contents it instead of including it.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Also check to make sure there are no contents outputted before the header() is called.

  8. #8
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    844
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that did the trick brother!
    Convert your dollars into silver coins. www.convert2silver.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •