php - redirection without reloading the whole page -
i have framework , think i'm following mvc pattern: framework (the model) index page controls input (the controller) , views pages (that included inside main.php/the main html)
i read lot structure , logics, write application. read many comments "why outputting if going try , redirect user page?". answer is, common case: redirect after user logged in. need print something? of course, whole main page login form/post. how i'm supposed redirection??
so i'm bit confused logics , structure of application. how store output , header redirection without printing anything?
i thinking using javascript redirection read comments saying; "if write code (following logic/structre), won't need use hacks javascript redirection". how possible?
because php output_buffering should not enabled.
i have output_buffering enabled, , can use header (after output) without problem. if use javascript redirection whole page reloads, using header loads content (the views content included in main.php).
so how do without output_buffering?
if want redirect success page , pass messages - say, after successful login - easy solution use "flash" sessions, store message in session , then, it's used, discard it. don't need sore in output buffer this.
this basic example, should give gist of it.
login.php
if($login_successful) { // put message in session $_session['message'] = 'login successful'; // redirect success page header('location: success.php'); } success.php
<?php session_start(); // check if $_session['message'] exists if(isset($_session['message'])) { // print message echo $_session['message']; // clear session $_session['message'] = null; }
Comments
Post a Comment