close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Clear cart clears everything or nothing

Thread began 4/30/2012 5:41 pm by rgolab68503 | Last modified 5/01/2012 6:47 pm by rgolab68503 | 573 views | 4 replies |

rgolab68503

Clear cart clears everything or nothing

When I add the clear session values to my page I can get it to clear everything by checking the box to "clear all sessions". However, if I select only the cart items in the window nothing gets cleared.

When looking through the forums i came across a similar issue and tried adding the suggestions to save and and restore so my code now looks like this.

<?php
$loginUsername = $_SESSION['user_name'];
$password = $_SESSION['pass_word']
?>
<?php
@session_start();
if ("" == ""){
// WA_ClearSession
$clearAll = TRUE;
$clearThese = explode(",","");
if($clearAll){
foreach ($_SESSION as $key => $value){
unset($_SESSION[$key]);
}
}
else{
foreach($clearThese as $value){
unset($_SESSION[$value]);
}
}
}
?>
<?php session_start();
$_SESSION['user_name'] = $loginUsername;
$_SESSION['pass_word'] = $password;
?>

This however still logs me out. Am I missing something in the restoring of the username and password?

I tried simply using the clear cart function before page load but it just stalls the page for some reason.

<?php
// WA eCart Trigger Clear Cart
if ("" == "") {
$ToyoeCart->ClearCart();
$Redirect_redirStr="checkout_success.php";
if ($Redirect_redirStr != "") {
$ToyoeCart->redirStr = $Redirect_redirStr;
}
$ToyoeCart->cartAction = "ClearCart";
}
?>
<?php
// WA eCart Redirect
if ($ToyoeCart->redirStr != "") {
header("Location: ".$ToyoeCart->redirStr);
}
?>

Ideally what it needs to do is clear the cart however not clear the log in session variables so the visitor can continue to do other activities.

Sign in to reply to this post

Jason ByrnesWebAssist

that first code should work for clearing the cart but leaving the user logged in, if it is not leaving the user logged in, there must be another session variable that is used by the login system.


to help troubleshoot, lets take a look at the login system. After login, what page is the user redirected to? Open that p[age and add the following code just after the <body> tag to write the session contents:

php:
<pre><?php var_dump($_SESSION); ?></pre>




I'm guessing that in addition to the username and user password session variable, there is a use ID session that needs to be reset as well.

Sign in to reply to this post

rgolab68503

Log out clearing cart

Hi Jason,

Thanks for your help and your patience. I am getting closer. It is now clearing the cart properly which is great and it leaves or keeps the login session going but somehow i need to pick up the password. If we simply user the username it is picking up the first "Ron" in the list and logging in as them. It doesn't seem to catch the other two session variables.

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
@session_start();

//store the user session
$userSession = $_SESSION['MM_Username'];
$userSession = $_SESSION['pass_word'];
$userSession = $_SESSION['user_name'];

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
@setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}

// Finally, destroy the session.
session_destroy();
unset($_SESSION);
session_start();
session_regenerate_id();


//reset user session
$_SESSION['MM_Username'] = $userSession;
$_SESSION['pass_word'] = $userSession;
$_SESSION['user_name'] = $userSession;
?>

Per you code here are the session variables when I initially log in ...



<pre>array(4) {
["MM_Username"]=>
string(3) "ron"
["MM_UserGroup"]=>
string(0) ""
["pass_word"]=>
string(8) "changed"
["user_name"]=>
string(3) "ron"
}
</pre>
This is what happens when I order something on the cart and checkout ...

<pre>array(4) {
["MM_Username"]=>
string(3) "ron"
["MM_UserGroup"]=>
string(3) "ron"
["pass_word"]=>
string(3) "ron"
["user_name"]=>
string(3) "ron"
}
</pre>

all the sessions switch to username Ron. I am not storing the sessions properly?

Any suggestions?

Sign in to reply to this post

Jason ByrnesWebAssist

you are using the same variable name for each session:
$userSession = $_SESSION['MM_Username'];
$userSession = $_SESSION['pass_word'];
$userSession = $_SESSION['user_name'];

at the end of the day $userSession is now equal to $_SESSION['user_name'] and there is no variable that contains the others, you need to use a unique variable name for each one:

$MM_Username = $_SESSION['MM_Username'];
$pass_word = $_SESSION['pass_word'];
$user_name = $_SESSION['user_name'];


and make sure to use the correct variable when resetting the sessions.
$_SESSION['MM_Username'] = $MM_Username;
$_SESSION['pass_word'] = $pass_word;
$_SESSION['user_name'] = $user_name;

Sign in to reply to this post

rgolab68503

Clearing cart and logging out

Oops, I completely missed that part. Thanks for sending me in teh right direction. i switched it to:

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
@session_start();

//store the user session
$MM_Username = $_SESSION['MM_Username'];
$pass_word = $_SESSION['pass_word'];
$user_name = $_SESSION['user_name'];

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
@setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}

// Finally, destroy the session.
session_destroy();
unset($_SESSION);
session_start();
session_regenerate_id();


//reset user session
$_SESSION['MM_Username'] = $MM_Username;
$_SESSION['pass_word'] = $pass_word;
$_SESSION['user_name'] = $user_name;
?>

and it works perfectly.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...