dobleclick Posted February 22, 2011 Share Posted February 22, 2011 Hello guys,This is my first post. I've looked everywhere in the forum but I couldn't find exactly what I am looking for so here it goes:I need to set up a security question before users can change their addresses (addresses.php).This is the code I have right now:Modified addresses.php <?php /* SSL Management */ $useSSL = true; include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/init.php'); if (!$cookie->isLogged()) Tools::redirect('authentication.php?back=addresses.php'); $customer = new Customer(intval($cookie->id_customer)); if (!Validate::isLoadedObject($customer)) die(Tools::displayError('customer not found')); include(dirname(__FILE__).'/header.php'); ?> MY ADDRESSES To be able to view and edit your addresses you need to verify your identity by answering this security question: What is your favorite color? <form method="POST" action="addresses_list.php"> <input type="text" name="secret_question" size="20"><br> <input type="submit" value="Continue" name="private"> </form> <?php include(dirname(__FILE__).'/footer.php'); ?> As you can see, I edited the file. Theres a form. You enter the answer and then it takes you to "addresses_list.php" which is the original file but with my php code to verify the correct answer. Heres what I got so far:Addresses_list.php <?php /* SSL Management */ $useSSL = true; include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/init.php'); if (!$cookie->isLogged()) Tools::redirect('authentication.php?back=addresses.php'); $customer = new Customer(intval($cookie->id_customer)); if (!Validate::isLoadedObject($customer)) die(Tools::displayError('customer not found')); include(dirname(__FILE__).'/header.php'); if ($_POST["secret_question"]=="securityanswer") { $valid="yes"; } else { $valid="no"; } if ($valid=="yes") { $smarty->assign('addresses', $customer->getAddresses(intval($cookie->id_lang))); $smarty->display(_PS_THEME_DIR_.'addresses_correct.tpl'); } else { $smarty->assign('addresses', $customer->getAddresses(intval($cookie->id_lang))); $smarty->display(_PS_THEME_DIR_.'addresses_wrong.tpl'); } include(dirname(__FILE__).'/footer.php'); ?> So, essentially, if the security question is valid it displays the addresses page, and if not, it displays the error page.My problem is, that I want to grab the user's secret answer from the database, instead of hardcoding it in the php file. I dunno how to do that!!! I was thinking that maybe i could read the costumer id from the cookie and put that into a variable, so that way it can query the database and use that as secret answer to verify against. I already created the secret question field in ps_costumer table, and modified the user registration form. All I need is to get the user ID from the cookie and pass it into a variable. How do I do that?!I'm very newbish in PHP, please help.THANKS. Link to comment Share on other sites More sharing options...
dobleclick Posted February 22, 2011 Author Share Posted February 22, 2011 Nevermind, I figured it out!!! yay!!!It is actually very simple: $costumer_id = $cookie->id_customer; So that turns the variable customer_id and asigns the id_costumer value from the cookie. Voila!If you got any questions on something similar to this, I'd be glad to help you out.Thanks! Link to comment Share on other sites More sharing options...
Radu Posted February 22, 2011 Share Posted February 22, 2011 it's a nice feature, can you please place [sOLVED] in front of the post title so other can see directly there is a solution to this kind of problem? thanks Link to comment Share on other sites More sharing options...
dobleclick Posted February 23, 2011 Author Share Posted February 23, 2011 Sure, just did!Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now