会话cookie不会持久存储在本地页面,远程服务器上?

I have a page on my local computer with a script that interacts with a remote server. For every request, it gets a different PHPSESSID value. Does this have something to do with the page not being associated with a domain? Is there a way to solve this, perhaps maybe manually setting the PHPSESSID or something in php.ini?

Look, I don't know where the downvotes are coming from or the request to close, either. Just seems like trolling to me. This is not a coding error. This is a server error. Code will do nothing. Seriously, as plain and standard as you can be, like:

$.post('http://example.com/server.php',{'stuff':'data'},function(){

});
// PHPSESSID is 545ty789gh78rhr

Then, when I call it again:

$.post('http://example.com/server.php',{'stuff2':'data'},function(){

});
// PHPSESSID is fnunurhf894fh

And then, on the php page:

session_start();
if(isset($_POST['stuff']) $_SESSION['variable'] = '123';

if(isset($_POST['stuff2']) echo $_SESSION['variable']; // Returns nothing, as the PHPSESSID cookie value has changed

Thus, I'm thinking it's either in php.ini or has something to do with how php handles session cookies with no http domain (just a local script accessing the server). I'm wondering if there's something in php.ini that would solve it or perhaps if there's a way to manually set the PHPSESSID's (if there's no way through php.ini).

I think your issue is that cookies are stored on a per domain level. Your browser is operating on localhost, and the server is operating on example.com. So when the first ajax request is made, the browser gathers all the localhost cookies and sends them along. The server finds no example.com PHPSESSID cookie, so it creates one and starts a new session. When the request comes back to the browser a cookie is set for example.com. When the second request is made the browser looks for any cookies it has for localhost, finds none, and repeats the process.

Cross domain ajax requests are not allowed by default. You may be able to solve the problem by trying a jsonp request. See jQuery's documentation for more info.