2

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 )

iamafish
  • 817
  • 3
  • 13
  • 24

4 Answers4

2

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
  • 28,364
  • 20
  • 86
  • 132
  • 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. – iamafish Aug 10 '10 at 16:12
  • Ok question update. I'm not share the session between hosting. – iamafish Aug 10 '10 at 16:17
  • @kampit I think you really didn't get the idea on this answer. He pointed your issue's core on the first sentence and proposed a solution. This mostly do answer your question. You'd have some work replacing all code using SESSION to use this instead. – cregox Feb 21 '11 at 19:14
0

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
  • 2,590
  • 1
  • 24
  • 34
0

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
  • 14,876
  • 6
  • 42
  • 48
0

For what it's worth, I has a similar problem on hostgator. Disabling the "php.ini QuickConfig" in cPanel fixed the problem, so it was probably an incorrect setting on that page. I suspect it was an incorrect path, but can't confirm it.

sdcoder
  • 496
  • 2
  • 4