Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    I'm working on a large website project which uses a Model, View, Controller organization system.

    Controller = determines which page will be loaded (loads view and models)
    View = what the user actually sees
    Model = runs the back end logic (database queries, filtering, validation, etc.)

    I have hit a road block and I'm not quite sure how to proceed.

    In this application, I'm using the PHP header() function numerous times throughout the application. At some point, I hit this error:

    Code:
    Warning: Cannot modify header information - headers already sent by....
    I know what causes this error, and how to fix it, but the why my code runs, I have to redirect after HTML has already been displayed.

    I have tried creating a class (called "Redirect") to call the header() function before any HTML is used, but that method isn't working. I know I could fix the issue by using JavaScript or <meta> redirects, but I would prefer to avoid using unconventional methods.

    Does anyone know how to fix this?
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]

  2.  

  3. #2
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    Ok, after doing some more research and a little code modification, I fixed this issue.

    I added the following before using any HTML:

    PHP Code:
    ob_start(); 
    I then added

    PHP Code:
    ob_end_flush();
    ob_end_clean(); 
    after my page loading function.
    mlseim likes this.
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]


Remove Ads

Posting Permissions

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

Search tags for this page

php mvc redirect after post

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:12 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com