PHP Cannot modify header - already sent

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
Jimmi
Mesaje: 5

PHP Cannot modify header - already sent

Am reusit sa rezolv si logarea pe site. Acum citeste parola.
Inca o intrebare totusi. Dupa ce ma loghez nu mai poate sa afiseze header-ul cum ca esti logat direct.
Ma loghez, totul bine, insa nu apare header-ul pana nu dau refresh la pagina.Nu cred ca am gresit ceva la parola din moment ce autentificarea se face.
In error_log imi zice doar ca nu a putut sa modifice informatia din header si atat

Cod: Selectaţi tot

[29-Oct-2018 14:34:09 Europe/Bucharest] PHP Warning:  Cannot modify header information - headers already sent by (output started at /public_html/index.php:69) in /public_html/inc/Config.class.php on line 75

Cod: Selectaţi tot

	public static function setHeader() {
		if(isset($_SESSION['user_web']))
		{
			echo '
			<div class="guestpanel" style="margin-top: 16px">
				<div style = "font-size: 18px;">
				<div class="dropdown">
				  <div class = "user_name_cls">Welcome back '.Config::getData('users','username',$_SESSION['user_web']).'!</div>
				  <i class="fa fa-caret-down" style="font-size:11px"></i>
				  <div class="dropdown-content">
					<li class = "firstLi"><a href ="index.php">Acasa</a></li>
					<li><a href ="../customer/usercp.php">Profile</a></li>
					<li><a href="'.Config::$_PAGE_URL.'adm/logout.php">Log out</a></li>
				  </div>
				</div>
				</div>
			</div>';
		} else {
				if(isset($_POST['submit_login']))
				{
					$password = $_POST['password']; 
					$key_enc = '1234';
					$met_enc = 'aes128'; 
					$iv = '16_characters_ok';
					$pass_enc = openssl_encrypt($password, $met_enc, $key_enc, 0, $iv);
					$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `username` = ? AND `password` = ?');
				    $q->execute(array($_POST['username'],$pass_enc));
					if($q->rowCount())
					{
						while($row = $q->fetch(PDO::FETCH_OBJ))
						{
							$_SESSION['user_web'] = $row->ID;
							header('location: '.Config::$_PAGE_URL.'' );
						}
					} else {
						echo '<strong><font color="red">Incorrect username or password!</font></strong><br><br>';
					}
				}
				else
				{
					echo '<div class="guestpanel">
						<form action="" method="post">
							<input type="text" placeholder = "Username" name="username" value="" class="form_sml" required/>
							<input type="password" placeholder = "Password" name="password" value="" class="form_sml" required/>
                    		<button type="submit" name="submit_login" value="Login" class="button_submit button_sml button_black float_left">Login
                    		</button>
							
							<a href="'.Config::$_PAGE_URL.'adm/register.php" class="button_sml button_blue tip"
                   title="Sign up with to be a part of our quickly growing community">Register</a>
                		</form>
                	
            			</div>';
		        }
		}
}
La login m-am folosit tot de openssl_encrypt ca sa imi citeasca parola direct criptata din baza de date.Functioneaza doar ca nu poate sa modifice header-ul.Logarea pe site se face si nu inteleg de ce...

MarPlo
Pentru problema cu eroare de header vezi raspunsurile de la:
Problema php script logare
Problema Cannot modify header information


Sau poti gasi raspunsuri si pe internet la cautare: PHP Warning: Cannot modify header information - headers already sent.

Jimmi
Rezolvat, am avut cateva spatii dar nu disparea eroarea.Am adaugat ob_start(); la inceput
Multumesc de ajutor

Subiecte similare