Set the session of subdomain using ajax

John Christian De Chavez

I'm using a domain like www.example.com and a sub-domain like sub.example.com.

I'm trying to call the Login function of sub.example.com. In the end I cant set the session of sub.example.com for future functions to be called.

I'm using CodeIgniter in my sub-domain and my root domain just has an HTML page with native JavaScript. I wanted to use sub.example.com as my endpoint for all my sub-websites.

I tried changing the config of my subdomain(CI) to

$config['cookie_prefix']    = "";
$config['cookie_domain']    = ".example.com";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;

and also the index.php file of my www.example.com to:

session_set_cookie_params(0, '/', '.example.com');
session_start();
John Christian De Chavez

I solved my problem by setting header("Access-Control-Allow-Credentials: true");[SERVER-SIDE] and $http.defaults.withCredentials = true;[CLIENT-SIDE] using Angular $httpProvider upon request

And also don't forget to set the header("Access-Control-Allow-Origin: www.example.com");[SERVER-SIDE] my root domain to have an access to my sub-domain.

but if you have multiple domains/sub-domains to allow you can use below code

$http_origin = $_SERVER['HTTP_ORIGIN'];

if ($http_origin == "http://www.domain1.com" || $http_origin == "http://www.domain2.com" || $http_origin == "http://www.domain3.info")
{  
    header("Access-Control-Allow-Origin: $http_origin");
}

for more info Access-control-allow-credentials

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Updating session using AJAX

From Dev

Django: set session via Ajax

From Dev

Accesing and removing session that was set with Ajax

From Dev

Access PHP $_SESSION using AJAX

From Dev

login page using ajax and php and set a session but i am not getting the value of the session after successful login on another php page in server

From Dev

Set Magento 2 session variable over AJAX

From Dev

jQuery AJAX - Set PHP Session variable

From Dev

jQuery and ajax to set session variable in PHP

From Dev

Set session variable with ajax call and refresh partial

From Dev

set cookie in php and run the session through ajax

From Dev

Ajax Call From Subdomain

From Dev

Cannot acces Magento session on subdomain

From Dev

Cannot acces Magento session on subdomain

From Dev

How can update my session using ajax?

From Dev

Using PHP Session Variables and an Ajax Loign

From Dev

checking session timeout when using AJAX

From Dev

Setting a session variable in PHP using AJAX

From Dev

Using Ajax to create session and echo results

From Dev

Using session_start() with AJAX without warnings

From Dev

Get session value using JQuery/Ajax

From Dev

Setting a session variable in PHP using AJAX

From Dev

Add variable from session to another session using ajax

From Dev

secret key not set in flask session, using the Flask-Session extension

From Dev

Is it possible to set MySQL session variables using mysqlimport?

From Dev

Set Session attribute using expression language

From Dev

where to set session in laravel using AuthenticatesAndRegistersUsers, ThrottlesLogins;

From Dev

Set php session from ajax in iframe fetcher to be identified

From Dev

Using the subdomain as a parameter

From Dev

Localhost, subdomain, using XAMPP

Related Related

  1. 1

    Updating session using AJAX

  2. 2

    Django: set session via Ajax

  3. 3

    Accesing and removing session that was set with Ajax

  4. 4

    Access PHP $_SESSION using AJAX

  5. 5

    login page using ajax and php and set a session but i am not getting the value of the session after successful login on another php page in server

  6. 6

    Set Magento 2 session variable over AJAX

  7. 7

    jQuery AJAX - Set PHP Session variable

  8. 8

    jQuery and ajax to set session variable in PHP

  9. 9

    Set session variable with ajax call and refresh partial

  10. 10

    set cookie in php and run the session through ajax

  11. 11

    Ajax Call From Subdomain

  12. 12

    Cannot acces Magento session on subdomain

  13. 13

    Cannot acces Magento session on subdomain

  14. 14

    How can update my session using ajax?

  15. 15

    Using PHP Session Variables and an Ajax Loign

  16. 16

    checking session timeout when using AJAX

  17. 17

    Setting a session variable in PHP using AJAX

  18. 18

    Using Ajax to create session and echo results

  19. 19

    Using session_start() with AJAX without warnings

  20. 20

    Get session value using JQuery/Ajax

  21. 21

    Setting a session variable in PHP using AJAX

  22. 22

    Add variable from session to another session using ajax

  23. 23

    secret key not set in flask session, using the Flask-Session extension

  24. 24

    Is it possible to set MySQL session variables using mysqlimport?

  25. 25

    Set Session attribute using expression language

  26. 26

    where to set session in laravel using AuthenticatesAndRegistersUsers, ThrottlesLogins;

  27. 27

    Set php session from ajax in iframe fetcher to be identified

  28. 28

    Using the subdomain as a parameter

  29. 29

    Localhost, subdomain, using XAMPP

HotTag

Archive