The Little Guy Posted January 23, 2012 Share Posted January 23, 2012 I am using AJAX to access this file on my domain (weblyize.com), from my subdomain (ping.weblyize.com), and it keeps going into the if statement, logged is set on the domain, because I can see it when I go to a page that displays it. Anyone know why it is going into the if? If I go to the page directly, it works fine. header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: POST, GET"); header("Access-Control-Allow-Headers: NCZ"); header("Access-Control-Max-Age: 1728000"); session_set_cookie_params(0, "/", ".weblyize.com", false); session_start(); if(!isset($_SESSION['logged']) || !$_SESSION['logged']){ header("HTTP/1.0 400 Bad Request"); header("Status: 400 Bad Request"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/ Share on other sites More sharing options...
sunfighter Posted January 23, 2012 Share Posted January 23, 2012 Your codes for me. Just to be sure your passing the correct values insert this line: echo '|'.$_SESSION["logged"].'|<br />'; Before the if statement to look at your variable. If $_SESSION["logged"] is empty you'll just get a pair of lines. If it has a value that value will appear between the lines. Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310367 Share on other sites More sharing options...
The Little Guy Posted January 23, 2012 Author Share Posted January 23, 2012 I have done a print_r() of the session, and nothing. print_r($_SESSION); but when I go to the actual page (not via ajax) it shows up. Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310456 Share on other sites More sharing options...
ManiacDan Posted January 23, 2012 Share Posted January 23, 2012 Sessions are stored using cookies, and the cookie depends on the subdomain. You'll have to use session_set_cookie_params to force your subdomain to cookie for the whole site. Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310465 Share on other sites More sharing options...
beegro Posted January 23, 2012 Share Posted January 23, 2012 Assuming you're doing this session_set_cookie_params(0, "/", ".weblyize.com", false); in the parent domain. Then the session should work unless your subdomain is on a different box. If it's on a separate box you'll have to figure out how you want to share the session files between them. I'm sure you already know this but I'm just reiterating it to be thorough. Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310466 Share on other sites More sharing options...
The Little Guy Posted January 23, 2012 Author Share Posted January 23, 2012 Could It be because I am using: session_set_cookie_params on every page call before session_start? I am using this: session_set_cookie_params(0, "/", ".weblyize.com", false); on the domain and sub-domain Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310470 Share on other sites More sharing options...
The Little Guy Posted January 24, 2012 Author Share Posted January 24, 2012 Okay, here is what I did: 1. sent the session_id() as a post value 2. before I start the session on the other domain, get it and do: session_id(htmlspecialchars($_POST['token'])); Quote Link to comment https://forums.phpfreaks.com/topic/255570-session-not-working/#findComment-1310493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.