Jump to content
php.lv forumi

"Headers already sent"


bubu

Recommended Posts

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

Joprojām nesaprotu, kas vainas header(Location'am. Tas ļoti labi vienmēr strādā, kad to pareizi izmanto. Ja tev tas neder, tad aizmirsti par redirektu.

Jocīgs tas tev jautājums. Ja tev nebūtu tiesības veidot uz servera failus, tu nāktu prasīt kādu funkciju lietot fopen/file_put_contents vietā?

Link to comment
Share on other sites

  • 2 weeks later...

Piebilde iesācējiem, kuri lieto Wampserver 2.0.

Var gadīties, ka uz mājas datora viss ir kārtībā, bet, pārceļot lapu uz gala serveri, parādās minētā kļūda. Tas notiek AndraP raksta beigās minētās rakstīšanas buferī dēļ. Failā php.ini jānomaina output_buffering=4096 uz output_buffering=0.

Link to comment
Share on other sites

Izveido funkciju - js_redirect kurā uztaisi JS funkciju kas aiznes uz tevis definētu linku! jeb definē konfig failā $config['page'] = 'http://localhost/'; un veido šādi! - js_redirect(); jeb lūk būs info!

 

function js_redirect($page)
{
echo "<script>";
echo "document.location=\"$page\"";
echo "</script>";
}

Tālāk definējam config.php failā vai kaut kur tā.

$config['page'] = 'ADRESE';

un izvadam laukā kur mums gribas iet

js_redirect($config['page']);

 

Priekā .

Link to comment
Share on other sites

  • 1 year later...

Sveicināti visie php`ieši.

Esmu šeit, kā redzat, jauniņais.

 

Izmantoju šo - http://php.lv/f/topic/16159-login-skripts-ar-sessijam/

 

Visu izdarīju kā vajadzētu. Un nonāku pie headers already sent errora. Varbūt varat kā līdzēt.

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\base.php:1) in C:\AppServ\www\base.php on line 2

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\base.php:1) in C:\AppServ\www\base.php on line 2

Link to comment
Share on other sites

  • 1 month later...

tā tad nejiešu melot mācos u.t.t bet ar šo skaidrība netiku var lūdzu man kāds šo kodu salabot lai nebūtu tā erorra un ta cilvēciski paskaidrot kur bija čibele.

 

<?php
require('includes/main.inc.php');
if(!$main->member->isLoggedIn()){
 $already = true;
}else{
 $main->member->logout();
}
if(isset($already)){
 $main->printHeader("Logout");
?>

<div class='red'><div class='inner'>Tu jau esi izgajis !</div></div>

<?php
 $main->printFooter();
} else{
 header("location: ".main_WEB_URL."");
}
?>

Link to comment
Share on other sites

  • 1 month later...

Vienīgā izeja: veikt ciklu pirms HTML izvades, ne izvades laikā.

Piemēram:

if($foo == 'bar'){
header('Location: gtfo');
exit; ///!!!!!!!!!! Pievērs uzmanību.
}else{
///HTML stuff
}

 

Uz client side redirect paļauties ir klajš ambālisms, piedodiet par manu franču valodu.

 

@xperience zīlnieču salons šeit nebūs gan. Kā lai mēs zinām, kas ir $main->printHeader("Logout") un $main->member->logout(); ?

Edited by F3llony
Link to comment
Share on other sites

  • 1 year later...

Sveiki!

Šodien bija dilēma ar session_start. Kļūdu varēja novērst saglabājot failu bez bom, bet to izdarot nerādījās garumzīmes. Lai dabūtu garumzīmes, bija jasaglabā ar bom, bet tad kļūda atkal uzradās. Palīdzēja faila sākumā pielikt "header('Content-Type: text/html; charset=utf8');"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...