I write a shopping cart in my local server (WAMPSERVER) with session variable. The another site is equal to my session variable $_SESSION['cart']. So I add a product to my cart the another site is also update and if I add product in another site my cart also update. How can I solve this problem.
[edit] I mean my two site is equal in session variable 开发者_JAVA技巧name. So they conflict.
If you want to share session data (this is vaguely what your question sounds like), then you can either:
- Store the session data in a database accessible from both servers. Load $_SESSION manually depending on a manually managed cookie id.
- Setup a network filesystem that both servers share. Look up where PHP stores the session files with http://www.php.net/manual/en/function.session-save-path.php and make it available on both servers. This depends on the used network filesystem, but is potentially unreliable. (But OTOH you are using WAMP anyway..)
Some other (and likely better) solutions are listed here: Cross domains sessions - shared shopping cart cross domains
function: session_save_path ([ string $path ] ) maybe help. use different path for each site.
OR
This problem is like the problem in installing multiple sites in one database, in this case you should use prefix_ for your tables.
like this you should use PREFIX_ anywhere you use session.
for example in Database we have something like this:
$sql = "SELECT * FROM
in this case we need something like that:
".Config::getInstance()->dbprefix."users
WHERE ...;";
$_SESSION[Config::getInstance()->domainname."card"];
It's very difficult to to understand what you're saying. So forgive me if I'm a bit off.
From what I understand you currently have a website(example.com) and a local website through WAMP(presumably, localhost) and you want the two $_SESSION['cart'] variables to act as one?
Or rather simpler, you want your localhost cart synchronized with your online cart and vice versa. Right?
If you have complete control over both sites, I would suggest passing an encrypted session id through the url. As in:
pseudo code
temp_var = localhost_cookie
mydomain.com/page.php?a=temp_var
mydomain_cookie = gets a
destroy temp_var
Untested and that's really all I can think of right now.
精彩评论