nati Posted January 24, 2009 Share Posted January 24, 2009 Hello everybody, I have a site at http://www.djordjeweb.nl/compshop/. Locally, everything works normally, but on web session doesn't start at all. In top right corner there is a link "Prijava" which means "Login". Here is code for starting session. <?php $logovan = $_GET['ime']; $proizvod = $_GET['proizv']; if ($logovan != '') { session_start(); session_regenerate_id(); $_SESSION['sesija_sesname'] = session_id(); $_SESSION['sesija_loguser'] = $logovan; $_SESSION['sesija_tekuca_kat'] = 0; $_SESSION['sesija_artikal'] = $proizvod; $_SESSION['sesija_korpa'] = ''; $_SESSION['sesija_ukupna_cena'] = 0; $_SESSION['sesija_ukupno_artikala'] = 0; if ($proizvod == '') {header('Location: index.php');} else {header('Location: detail.php');} } ?> Where am I wrong, can anyone help, please? Tnx in advance, Nati Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/ Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 try putting session start at the top of the code, make sure it is before everything else (including any PHP or html code) Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745437 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 I put session_start at the top, as you suggested, but it still doesn't work . Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745446 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 Is the IF statement being run, try putting an echo in the statement. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745450 Share on other sites More sharing options...
revraz Posted January 24, 2009 Share Posted January 24, 2009 Have you checked your PHP.INI to verify the session save path is valid? Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745457 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 Quick way to do it if you don't have access to php ini echo ini_get('session_save_path'); I think that is correct Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745462 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 If statement is run, but now some errors occured. First line is my message. if statement works Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php:7) in /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php on line 18 I'll put now a code to see session_save_path. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745485 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Here is my new code for starting session with your suggestions: <?php session_start(); $logovan = $_GET['ime']; $proizvod = $_GET['proizv']; if ($logovan != '') { echo "Session path: ".ini_get('session_save_path'); session_regenerate_id(); $_SESSION['sesija_sesname'] = session_id(); $_SESSION['sesija_loguser'] = $logovan; $_SESSION['sesija_tekuca_kat'] = 0; $_SESSION['sesija_artikal'] = $proizvod; $_SESSION['sesija_korpa'] = ''; $_SESSION['sesija_ukupna_cena'] = 0; $_SESSION['sesija_ukupno_artikala'] = 0; if ($proizvod == '') {header('Location: index.php');} else {header('Location: detail.php');} } ?> And here is what I get when I try to login: Session path: Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php on line 7 Warning: Cannot modify header information - headers already sent by (output started at /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php:7) in /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php on line 16. Session_save_path is empty ??? You can try to log in as natasa/natasa. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745501 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 try , i disabled the header to stop it redirecting and producing errors <?php session_start(); session_regenerate_id(); $logovan = $_GET['ime']; $proizvod = $_GET['proizv']; if ($logovan != '') { echo "Session path: ".ini_get('session_save_path'); $_SESSION['sesija_sesname'] = session_id(); $_SESSION['sesija_loguser'] = $logovan; $_SESSION['sesija_tekuca_kat'] = 0; $_SESSION['sesija_artikal'] = $proizvod; $_SESSION['sesija_korpa'] = ''; $_SESSION['sesija_ukupna_cena'] = 0; $_SESSION['sesija_ukupno_artikala'] = 0; if ($proizvod == '') {//header('Location: index.php');} else {//header('Location: detail.php');} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745504 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Here is the result with commented header commands: Session path: Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in /home/fuzzy/domains/djordjeweb.nl/public_html/compshop/sesija.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745522 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 Then i take it you aren't showing us the full code Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745528 Share on other sites More sharing options...
uniflare Posted January 24, 2009 Share Posted January 24, 2009 ou cannot echo/print/print_r/break ?> or otherwise send any output to the browser before you use session_regenerate_id() or session_start(); There is a sticky topic on header errors, just need to look: "HEADER ERRORS - READ HERE BEFORE POSTING THEM" on the main php help forum: http://www.phpfreaks.com/forums/index.php/board,1.0.html Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745530 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 Or just read my first reply try putting session start at the top of the code, make sure it is before everything else (including any PHP or html code) Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745535 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 At first, I have to say I do show you the full code, but now I noticed you also deleted a line: session_regenerate_id(); which I didn't delete. You mentioned only headers, sorry, I'll delete this line and see what will I get. Second, session_start is on the top. Third, echo command I was suggested to put to see if "if ($logovan != '')" is being run. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745543 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 I didn't delete anything Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745545 Share on other sites More sharing options...
uniflare Posted January 24, 2009 Share Posted January 24, 2009 read my post, your header errors will be fixed if you follow the instructions. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745546 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Sorry one more time, you moved session_regenerate_id under the session_start, I see now. New change will be upload now. Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745550 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Here is what I get now: Session path: And my code is: <?php session_start(); session_regenerate_id(); $logovan = $_GET['ime']; $proizvod = $_GET['proizv']; if ($logovan != '') { echo "Session path: ".ini_get('session_save_path'); $_SESSION['sesija_sesname'] = session_id(); $_SESSION['sesija_loguser'] = $logovan; $_SESSION['sesija_tekuca_kat'] = 0; $_SESSION['sesija_artikal'] = $proizvod; $_SESSION['sesija_korpa'] = ''; $_SESSION['sesija_ukupna_cena'] = 0; $_SESSION['sesija_ukupno_artikala'] = 0; if ($proizvod == '') {/*header('Location: index.php');*/} else {/*header('Location: detail.php');*/} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745555 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 Ahh my bad, just googled it should be ini_get('session.save_path'); Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745558 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Ah, no problem, mistakes happen, I'll change it . Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745562 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 Hmm, the result is the same Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745567 Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 add error_reporting(E_ALL); to the top before session_start(); are their any errors? Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745569 Share on other sites More sharing options...
nati Posted January 24, 2009 Author Share Posted January 24, 2009 No errors, still just: Session path: Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745579 Share on other sites More sharing options...
nati Posted January 25, 2009 Author Share Posted January 25, 2009 Hello again , I found what made my session didn't work, but I still don't understand why ???. I made changes to pages which use session variables and wrote $_SESSION['blabla'] instead of $blabla and now it works! What I am confused about is that I thought (obviously wrong ) session variables should be declared as $_SESSION['blabla'] once and lately could be referenced to as $blabla. That worked fine at my local environment. What can cause that works in one environment and doesn't work in another? And what is correct way to do? Tnx a lot! Nati Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745816 Share on other sites More sharing options...
DeanWhitehouse Posted January 25, 2009 Share Posted January 25, 2009 PHP version might be different Quote Link to comment https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.