0

I've a script that assigns varibale to a specific session. It works perfectly on localhost but after uploading online, it just wouldn't work on the web. i.e

Here is the link that sends the variable through $_GET to the script

<a href="user_entry_chk.php?pubc_req&amp;c_id=<?php echo $course_details['id']; ?>">Register for this course</a>

Here's the script meant to assign variable to the session

if (isset($_REQUEST['pubc_req'])) {



$c_id = $_GET['c_id'];

session_name("pubc_cart");
session_start();

$pubc_cart = $_SESSION[pubc_cart];
if ($pubc_cart) {

//$get_pub_arr[] = array();
$pubc_cart = $_SESSION[pubc_cart];

$get_pubc_arr[] = array();
$get_pubc_arr = $_SESSION[pubc_cart];

if(in_array($c_id, $get_pubc_arr)){ 

//$_SESSION['inh_cart'] = array();

?>
    <script language="javascript">
    window.location = "user_allc_booking.php?ex_pub_cid=<?php echo $c_id; ?>";
    </script>
<?php

}
else {

//$_SESSION['pubc_cart'] = array();
$_SESSION[pubc_cart][] = $c_id;
//$pubc_cart[] = array();
//$pubc_cart = $_SESSION['pubc_cart'];

}

} else {
$_SESSION[pubc_cart][] = $c_id;
//$pubc_cart[] = array();
//$pubc_cart = $_SESSION['pubc_cart'];
}
//$_SESSION['pubc_cart'] = $pubc_cart;


?>
    <script language="javascript">
    window.location = "user_allc_booking.php";
    </script>
<?php



$pub_query_course_info = @mysql_query("select * from public_courses where id='".$c_id."'");
$pub_course_det = array();
$pub_course_det = @mysql_fetch_assoc($pub_query_course_info);   
$pub_course_title = $pub_course_det['title'];



}

In addition:

There's another session that works perfectly both locally and on the web for the same application.

This session is $_SESSION['member_id']

The member_id session handles the login id for all users while registering for courses. It's working fine except for the pubc_cart which holds the course id.

Im really puzzled. Is there another way to assign variable to session different from this or do you have to write a different script locally and then a different one for the web... Pls I'm really confused here.. Would be glad to get help.

Sms
  • 147
  • 1
  • 9
  • 20
  • Turn on error_reporting, remove all the @ before function calls, and look at what the errors are. That will help you, instead of blind debugging. – Bgi Feb 06 '13 at 15:10
  • Please don't use `$_SESSION[pubc_cart]`, use `$_SESSION['pubc_cart']` instead. Maybe this already fixes the problem? – Martin Müller Feb 06 '13 at 15:20
  • @martin muller: I was using this $_SESSION['pubc_cart'] but i chnaged to $_SESSION[pubc_cart] while debbuging...So it's still the same result.. – Sms Feb 06 '13 at 15:41

1 Answers1

0

It can be due to the reason that your session expires too fast on another server. Start by making sure you're setting the session variable correctly. It's possible that sessions either aren't enabled or aren't configured correctly in the php.ini file on your server.

You can try putting this in front of the file to see any errors. When you see the error you can figure out where you have gone wrong.

error_reporting(E_ALL);
ini_set('display_errors', 1);
Techie
  • 44,706
  • 42
  • 157
  • 243
  • Thanks for your response. But i dont think it's configuration cos there's another session ($_SESSION['member_id']) which handles the login id for all users while registering for courses. It's working fine except for the pubc_cart which holds the course id. So i think it's something else. – Sms Feb 06 '13 at 15:16
  • 1
    @Bgi I have given him a solution to fix the issue if you read the answer – Techie Feb 06 '13 at 15:19
  • @Dasun Here is the error message i got after inserting the error_reporting function.. ---- Notice: Use of undefined constant pubc_cart - assumed 'pubc_cart' – Sms Feb 06 '13 at 15:51
  • http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean – Techie Feb 06 '13 at 15:53