-1

So I am grabbing data through AJAX in order to redirect the user to a page , but the PHP session data gets lost after being redirected to the page ... Below is my code , can anyone tell me what might be causing that ... I'm copying the relevant code below

  $("#activation").click(function(event){
          event.preventDefault();
        var first_name = $("#first_name").val();
        var last_name = $("#last_name").val();
        var customer_phone = $("#customer_phone").val(); 
        var pin = $("#pin").val();
        var carrier_id = $("#selCarrier option:selected").val();  
        var phone_number = ValidateMobNumber('customer_phone'); 

            $.ajax({
                url:"add_customer.php", 
                data:{first_name:first_name,last_name:last_name,pin:pin,carrier_id:carrier_id,customer_phone:customer_phone},
                type:"POST", 
                success:function(result){
                var customer_id = result;

                var url ="http://www.example.com/store/activation.php?id="+customer_id;

                if(customer_id !=""){
                window.location.href = url;
                return false;
                }
                else {

                  alert("Please enter a first name , last name and pin for activation");
                }


               } 
           });

        });
nietonfir
  • 4,797
  • 6
  • 31
  • 43
Stevie Nix
  • 1
  • 1
  • 4
  • 2
    How are you using your session ? Show us the PHP part of your code :) – Kevin Labécot Aug 12 '14 at 14:07
  • Is `session_start();` inside all pages using sessions, including the same session name assignments? – Funk Forty Niner Aug 12 '14 at 14:07
  • We really need to see the php... Are you sure you used session_start() on the page you think your session is getting lost? – mickzer Aug 12 '14 at 14:08
  • Yes , PHP session_start() is included .. Not the name though .. I usually use session_start on all page using the session – Stevie Nix Aug 12 '14 at 14:09
  • 1
    Here's a list of things to check: http://stackoverflow.com/a/17242347/2482557. In particular, take a look at #7. `www.example.com != example.com` – Nate Kibler Aug 12 '14 at 14:13
  • Check your cookies. PHP sets a cookie called `PHPSESSID`. – Arnold Daniels Aug 12 '14 at 14:21
  • I believe I fixed it , I just omitted the http://www.xxx./ and used only the file name and it worked – Stevie Nix Aug 12 '14 at 14:22
  • if that fixed the problem it is because the session cookie was set for a specific domain only, and not all subdomains of the domain... This often happens when mixing urls with and without www – Salketer Aug 12 '14 at 14:27

1 Answers1

1

I was having the same problem, but changing the absolute path to a relative one fixed it for me.

I changed this

window.location.replace('http://www.example.com/folder/subfolder/subfolder/file.php');

To this

window.location.replace('../../folder/subfolder/subfolder/file.php');

Hope it helps.