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
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
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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.