This makes no sense. It works in localhost, but not in my server.
Before submiting the form, if I var_dump()
the $_SESSION
it retrieves me the following:
array(2) { ["email"]=> string(40) "082b6eff9db5019e6a28f586a679b7f72fab27f4" ["id"]=> int(5) }
The form is this one:
<form method='POST' action='response.php?type=add_customer'>
<input type='text' name='customer'/>
<input type='submit' value='add'/>
</form>
If I var_dump()
the $_SESSION
on response.php I get: array(0) { }
if(!isset($_SESSION)){ session_start(); }
var_dump($_SESSION);
How d'hell is this possible?
Because it works localhost but not in my server..could it be a php.ini problem? If so, what?
EDIT (1): Changed my code to this (in response.php):
session_start();
if(isset($_REQUEST['type'])){
switch ($_REQUEST['type']){
case 'add_customer':
var_dump($_SESSION);
break;
}
}
Continues not to work. It retrieves an empty array.
EDIT (2): Solved. If someone could explain to me why this:
session_start();
var_dump($_SESSION); // doesn't work
print_r($_SESSION); // doesn't work
echo $_SESSION['id']; // works
I appreciate. Because the problem was this.
Put session_start();
as the first thing after the <?php
tag at the top of every page were you want your $_SESSION
data to persist
Not good to combine GET and POST. Update your form to the following
<form method="POST" action="response.php">
<input type="hidden" name="type" value="add_customer" />
<input type="text" name="customer" />
<input type="submit" value="add" />
</form>
session_start();
print_r($_SESSION);
put these two lines in both your pages. (right after the opening < ? php tag at the very to of your page, before any includes, before any output (empty spaces, bom characters, etc)
Under normal conditions, these should print exactly the same.
Now, since your second page does not have any session variables, i am guessing that the sessions are not set. So my best guess is that something is blocking/preventing your sessions or deletes/unset them.
Are you sure that you don't load/include anything above the following line?
if(isset($_REQUEST['type'])){
EDIT 1: Lets try someting:
Create folder sessions in your www directory. Set permissions to 777 for starters.
<?php
session_save_path('/home/project/www/sessions');
ini_set('session.gc_probability', 1);
session_start();
print_r($_SESSION);
?>
Put above code on top of page and check if you get anything