Automatically add product after login redirect php ajax

hi all

i am able to add item to wishlist with ajax if user is already logged in.

<a href="javascript:void(0);" onClick="getWISHID(id)">add to wishlist</a>

but if customer is not logged in then i want to redirect him to login page

so on top of my “wish.php” i have added

if($notlogin)
{
echo "<script language='javascript'>";
echo "window.location='".$domain."login.php'";
echo "</script>";
}

with this he is redirected to login page

and the then rest of the code which add product to wishlist doesnt works because he get redirect to login page.

so
i want that on redirecting, when he gets logged in then the product should automatically get added to his wishlist

how to do it ??

vineet

why not using PHP’s header() function to do that?

hi dormilich

i tried it first with header() but it didnt redirect so i used javascript redirect

but redirection is not a problem.

redirection is working fine

problem is how to automatically add to wishlist upon login

vineet

One way would be to add the product id to the URL for login.php when you do the redirect, then when the user logs in correctly, have your login script call the code to add the id into the wishlist. Obviously you’d need some checks on the id before just blindly storing it.

echo "window.location='".$domain."login.php?pendingwishlist='" . $productid;

Another way might be to stick it in a session variable as a “pending adding to wishlist” product id, and have the login code check for that.

Basically you’re going to need to pass the product id into the login code somehow, and have that add it on successful login, there’s probably other ways of doing it.

that will not work when JavaScript is off - you need a server side equivalent for those visitors

thanks droopsnoot

i understood it

vineet

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.