Jump to content

Problem with session


nati

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745485
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745501
Share on other sites

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');}
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745504
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745522
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745530
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745543
Share on other sites

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');*/}
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745555
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/142288-problem-with-session/#findComment-745816
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.