PHP Session is being created for every page -
so problem title says php session beingness created every page. when want variable session this
session_start(); echo $_session['error'];
it says "undefined index".
the problem is, in fact 'error' index defined not in current session since php creates new session every page.
how can solve this?
note: set session_start();
every pages' first line, , before header("location:error.php")
set session_write_close();
, after header there die();
method too. i'm working on localhost. using latest version of wamp , jetbrains phpstorm.
edit---------------------
this define session error(this login.php page)
session_start(); $_session['error'] = "enter both username , password"; header('location:error.php'); exit;
when code above run, session named "sess_amvrseubtusk0dpuo4fs35r0q1" created , has line in it
error|s:32:"enter both username , password";
and want read session (this error.php page)
session_start(); echo 'session: ' . $_session['error'];
when code above run, session named "sess_m08lf25stbhg75gj2h0n0vose0" created , empty.
i have 2 of created session files in session directory 1 session file each page.
edit 2----------------------------------
here php.ini file http://pastebin.com/jnspdzjh
edit 3----------------------------------
new php.ini file changes "c:/wamp/tmp" "c:/users/nerzid/phpstormprojects/deneme/session"
http://pastebin.com/zaz37upc
this posted per originally posted question should people wonder.
you may not have defined $_session['error']
, to the lowest degree not posted code:
session_start(); echo $_session['error'];
you first need assign it.
for example:
session_start(); $_session['error'] = "error."; echo $_session['error'];
then on subsequent pages, check if session set => isset()
and/or empty => empty()
or not.
i.e.:
if(isset($_session['error']) && !empty($_session['error'])){ echo $_session['error']; } else{ echo "session not set"; // set new 1 }
if session set variable example:
session_start(); $_session['error'] = "error."; $error_x = $_session['error']; echo $error_x;
also, when using header, add together exit;
header("location:error.php") exit;
always.
sidenote:
since you're working off of localhost, create sure folder writeable.
php session
No comments:
Post a Comment