Autor | Zpráva | ||
---|---|---|---|
soucekgns Profil |
#1 · Zasláno: 30. 3. 2011, 21:59:33 · Upravil/a: soucekgns
Mohu se zeptat, co přesně tato tvrzení říkají, trochu to nechápu...
Zkoušel jsem to najít v jiných diskusích, ale nic funkčního jsem nenašel Hlavně na jiných stránkách mi tento script fungoval... tak nevím, jestli to není nějakým limitem na scripty nebo na cookies, protože ve stránce má anketu s ukládáním cookies... Díky za rady Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /3w/wz.cz/a/aktenis/index.php:203) in /3w/wz.cz/a/aktenis/index.php on line 280 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /3w/wz.cz/a/aktenis/index.php:203) in /3w/wz.cz/a/aktenis/index.php on line 280 Zde je kód index.php: <?php require('_login_users.php'); require('_login_class.php'); $login = new login_class; $today_ts = strtotime("now"); $today_m = date('n', $today_ts); $pass_login = FALSE; $login->domain_code = $domain_code; $login->today_ts = $today_ts; $login->today_m = $today_m; $login->users = $users; $login->num_1 = $random_num_1; $login->num_2 = $random_num_2; $login->num_3 = $random_num_3; if (!$login->verify_settings()) { echo '<strong>Invalid Admin Settings for Login Script</strong><br />Check your settings and retry logging in'; exit(); } if (isset($_COOKIE[$domain_code.'_uid']) && $_COOKIE[$domain_code.'_uid']!='' && isset($_COOKIE[$domain_code.'_cid']) && $_COOKIE[$domain_code.'_cid']!='') { $key_uid = $login->cleanse_input($_COOKIE[$domain_code.'_uid']); $key_cid = $login->cleanse_input($_COOKIE[$domain_code.'_cid']); if (!$login->verify_login($key_uid, $key_cid)) { $login->error_message = 'Login has expired'; } else { $pass_login = TRUE; } } if (!$pass_login) { $need_login = TRUE; if (isset($_POST['login'])) { $login_user = $login->cleanse_input($_POST['username']); $login_pass = $login->cleanse_input($_POST['password']); if ($login->check_login($login_user, $login_pass)) { $login->encryption_key($login_user); $need_login = FALSE; } else { $login->error_message = 'Invalid login username and password'; $need_login = TRUE; } } } ?> <?php if (!$need_login) { session_start(); $_SESSION['username']=$username; } else { session_start(); unset($_SESSION['username']); } ?> _login_class.php: <?php class login_class { var $domain_code = ''; var $today_ts = ''; var $today_m = ''; var $error_message = NULL; var $users = ''; var $num_1 = ''; var $num_2 = ''; var $num_3 = ''; var $username = ''; function verify_settings () { $verified = TRUE; if ($this->num_1<1 || $this->num_1>500) $verified = FALSE; elseif ($this->num_2<500 || $this->num_2>1000) $verified = FALSE; elseif ($this->num_3<1 || $this->num_3>5) $verified = FALSE; foreach ($this->users as $user => $pass) { preg_match('/([^A-Za-z0-9-_\s\s+])/', $user, $user_result_{$user}); if (!empty($user_result_{$user})) $verified = FALSE; } return $verified; } function encryption_key ($user) { $key_uid = $this->user_encryption($user); $key_cid = $this->code_encryption($key_uid); setcookie($this->domain_code.'_uid', $key_uid, time() + (86400 * 5)); setcookie($this->domain_code.'_cid', $key_cid, time() + (86400 * 5)); } function user_encryption ($user) { return md5($user); } function code_encryption ($key_cid, $encrypt = 1) { if ($encrypt == 1) { $key_code = preg_replace('/([^0-9+])/', '', $key_cid); switch ($this->num_3) { case 1: $key_code = floor((($key_code + $this->num_2 + (($this->num_1 * 2) * $this->num_2)) / $this->num_1) / $this->num_2); break; case 2: $key_code = ceil(((($this->num_2 + $this->num_1) * $this->num_1 + $key_code + $this->num_2 - (10 * $this->num_1)) / ($this->num_1 * 50))/100000000); break; case 3: $key_code = floor((((($key_code - $this->num_2 + (($this->num_1 * 3) * $this->num_2)) + $this->num_1) / $this->num_2))/100000000); break; } $key_code = substr($key_code, 0, 10); return $key_code; } } function check_login ($username, $password) { foreach ($this->users as $user => $pass) { if ($username == $user && $password == $pass) { $this->username = $username; return TRUE; } } return FALSE; } function verify_login ($key_uid, $key_cid) { if ($key_cid = $this->code_encryption($key_uid)) { foreach ($this->users as $username => $password) { if ($key_uid == $this->user_encryption($username)) { $this->username = $username; return TRUE; } } } return FALSE; } function error_login () { if (isset($this->error_message)) { echo '<span class="error">'.$this->error_message.'</span><br /><br />'; } } function cleanse_input($input) { $input = trim($input); if (get_magic_quotes_gpc()==1) { } else { $input = addslashes($input); } $input = htmlentities($input); return $input; } } ?> |
||
Davex Profil |
#2 · Zasláno: 30. 3. 2011, 22:02:34
Před voláním funkce
session_start() nesmí být žádný výstup. Ani ten prázdný řádek mezi
?> <?php |
||
soucekgns Profil |
#3 · Zasláno: 30. 3. 2011, 22:09:08
To nefunguje... a hlavně ten script, který jsem zde napsal funguje úplně přesně jinde (i s mezerou)
ukázka pouze scriptu hlavní stránka jméno: soucek heslo: gymstola |
||
ShiraNai7 Profil |
#4 · Zasláno: 30. 3. 2011, 23:04:16
Viz FAQ - headers already sent… řeší se to tu 100x denně.
|
||
Joker Profil |
#5 · Zasláno: 30. 3. 2011, 23:21:54
soucekgns:
„headers already sent“ To už se tu řešilo tolikrát, že to je i v FAQ. Rozšířil jsem ale příslušný bod FAQ o doporučení dávat session_start co nejvíce na začátek skriptu. Jinak: „on line 280“ Co dělá session_start() na řádku 280? Obvykle není důvod to dávat někam jinam než jako první příkaz skriptu. if (!$need_login) { session_start(); … } else { session_start(); … } |
||
soucekgns Profil |
#6 · Zasláno: 31. 3. 2011, 15:04:31
Joker:
„Co dělá session_start() na řádku 280?“ Session není na 280 řádku, to právě nechápu proč to tak píše... „To psal programátor placený za počet řádků kódu?“ ne nepsal! |
||
ShiraNai7 Profil |
#7 · Zasláno: 31. 3. 2011, 19:01:58
soucekgns:
„Session není na 280 řádku, to právě nechápu proč to tak píše...“ ...in /3w/wz.cz/a/aktenis/index.php on line 280 ... Řekl bych že je, když to tvrdí PHP. „ne nepsal!“ Ale vypadá to tak :) |
||
Lamicz Profil |
#8 · Zasláno: 31. 3. 2011, 21:58:00 · Upravil/a: Lamicz
Joker:
Bacha, třeba coding standards Kohany to takhle doporučují, dokonce vše na novém řádku, stejně jako ne camel-case proměnný, ale old-school $nejaka_promenna a metody jak má on ;) Jsem čuměl jak puk... |
||
Časová prodleva: 7 dní
|
|||
Joker Profil |
#9 · Zasláno: 8. 4. 2011, 08:07:58 · Upravil/a: Joker
Když už jsem se k tomu vrátil:
Lamicz: „třeba coding standards Kohany to takhle doporučují, dokonce vše na novém řádku“ O tom jsem nemluvil, to je v pořádku. Šlo mi o to, proč obě větve začínají úplně tím samým. if (!$need_login) { session_start(); $_SESSION['username']=$username; } else { session_start(); unset($_SESSION['username']); } session_start(); if (!$need_login) { $_SESSION['username']=$username; } else { unset($_SESSION['username']); } |
||
Časová prodleva: 13 let
|
0