开发者

how to redirect with session_start on top of page php

开发者 https://www.devze.com 2023-03-25 23:09 出处:网络
i am checking the user login and password on a separate page on top of which i have 开发者_开发百科session_start();

i am checking the user login and password on a separate page on top of which i have

开发者_开发百科session_start();

Now if the user gives wrong credentials then i want him to go back but redirect is not working it gives error headers already sent and that is because of session_start() . what could be the best way of doing it. thanks.


First check if there is not any space before session_start

or you can also do this

on start before session_start write "ob_start();" and on the page end write "ob_flush();"

This will help


Use ob_start to buffer the output. This prevents session_start from sending headers right away, and makes it wait untill the end of the request.


A simple alternative is to use the following piece of HTML code, placed in the head element of your HTML output.

<meta http-equiv="refresh" content="0; URL=http://google.com">


check if there aren't white spaces or new line before php start tag or some echo... you can try to use ob_start

<?php 
    ob_start(); 

    session_start();
    // code  

    //Flush the buffer to screen
    ob_end_flush(); 
?>

http://php.net/manual/en/function.ob-start.php

0

精彩评论

暂无评论...
验证码 换一张
取 消