0

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 name. So they conflict.

4
  • 6
    I do not understand your question. Can you clarify? Commented Jan 15, 2011 at 13:41
  • Are you trying to make a session based shopping cart that works across domains? If so, are the domains just different hostnames (a.abc.com, b.abc.com) or totally different? Commented Jan 15, 2011 at 13:42
  • It's difficult to tell what is being asked here... Commented Jan 15, 2011 at 13:44
  • I create my shopping cart in local server(WAMPSERVER). The session name of my two sites is equal in session name $_SESSION['cart']. Commented Jan 15, 2011 at 13:59

3 Answers 3

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

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 ".Config::getInstance()->dbprefix."users WHERE ...;"; in this case we need something like that: $_SESSION[Config::getInstance()->domainname."card"];

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.