tags:

views:

90

answers:

3

Out of my head. How to fix this one. My session not working on hostgator server. But on other server it working fine.

Here an example the code.

<form action="/payment-select/" method="post">
 <select name="payment" onchange="this.form.submit()">
 <option value=""<?php if(empty($_SESSION['payment'])) { echo ' selected="selected"'; } ?>><?php echo $lang_please_select; ?></option>
 <?php 
  $sp = 'SELECT * FROM payment';
  $qp   = $db->rq($sp);
  while($payment = $db->fetch($qp)) {
  ?>
 <option value="<?php echo $payment['bank']; ?>"<?php if($_SESSION['payment'] == $payment['bank']) { echo ' selected="selected"'; } ?>><?php echo $payment['bank']; ?></option>
 <?php } ?>
 </select>
 </form>

The /payment-select/

include_once('includes/connection.php'); // session_start() here
include_once('includes/formatting.php');

$_SESSION['payment'] = strip_html_tags($_POST['payment']); 

header("location:/payment/");
exit();

Update

  1. All required pages have session_start() on the top.
  2. I install the script to server A working fine. Then server B fine.. But on hostgator with same phpinfo the $_SESSION['payment'] won't save after header redirect to /payment/ page.

I'm not share the session between server. It's something like I install wordpress on server A ok, Server B ok and Server C problem. ( the situation by example )

A: 

It would be helpful to clarify how this isn't working. My initial suggestion would be whether you have session_start(); included on all the pages where $_SESSION is utilised. Without knowing further what is not functioning it's hard to suggested anything further.

simnom
yes.. all of required pages have the `session_start()` on the top
kampit
A: 

Sessions are not shared between different servers, so you'll have to work out some way to pass those variables along with the transactions - assuming they are on different machines.

danp
+1  A: 

Sessions are not shared between servers. If you are passing a user with a session on one server to a page on another (where you would like to persist the session) you will need to develop a method of handing that off. Preferably with a token and encrypted serialized $_SESSION which can then be authenticated and loaded.

Host 1

$s = serialize($_SESSION);
$enc = encrypt($s); // However you want to encrypt it, I recommend it.
$token = gen_token(); // Again, find a good way to generate a secure token;

Host 2

$token = $_POST['token'];
if(is_valid($token))
{
    // Load the session (wrapped in a function, basically loop through the
    // array and load the respective values.
    load_session(unserialize(decrypt($_POST['enc'])));
}
Josh K
Yes.. `the session_start()` is on that page. This is simple shop script. I just install to server A the script working fine. Then server B fine.. But on hostgaor with same phpinfo the `$_SESSION['payment']` won't save.
kampit
Ok question update. I'm not share the session between hosting.
kampit