musiclvr Posted December 2, 2011 Share Posted December 2, 2011 I'm just a beginner at PHP so was hoping somebody here could help me with this problem. I need to set a cookie so that it skips the login page if the user is already logged in. I got that part working but once it skips the login page and goes to the product register page, it is all messed up. Here's my code for my index.php file. <?php setcookie('email'); require('../model/database.php'); require('../model/customer_db.php'); require('../model/product_db.php'); require('../model/registration_db.php'); if (isset($_POST['action'])) { $action = $_POST['action']; } else if (isset($_GET['action'])) { $action = $_GET['action']; } else if (isset($_COOKIE['email'])) { include('product_register.php'); } else { $action = 'login_customer'; } if ($action == 'login_customer') { include('customer_login.php'); } else if ($action == 'get_customer') { $email = $_POST['email']; $customer = get_customer_by_email($email); $products = get_products(); include('product_register.php'); } else if ($action == 'register_product') { $customer_id = $_POST['customer_id']; $product_code = $_POST['product_code']; add_registration($customer_id, $product_code); $message = "Product ($product_code) was registered successfully."; include('product_register.php'); } ?> Do you think it's because I have the below part in the wrong place? If so, where does that part go? else if (isset($_COOKIE['email'])) { include('product_register.php'); } I'd really appreciate some help on this. Thanks! Link to comment https://forums.phpfreaks.com/topic/252293-setting-a-cookie/ Share on other sites More sharing options...
peter_parker2010 Posted December 2, 2011 Share Posted December 2, 2011 hi , Remove this from the first line setcookie('email'); place it in relevant if else , rest is fine. with regards, vinit sharma Link to comment https://forums.phpfreaks.com/topic/252293-setting-a-cookie/#findComment-1293414 Share on other sites More sharing options...
musiclvr Posted December 2, 2011 Author Share Posted December 2, 2011 So the setcookie code is in the wrong place? Which if else statement do i put it in? Link to comment https://forums.phpfreaks.com/topic/252293-setting-a-cookie/#findComment-1293670 Share on other sites More sharing options...
peter_parker2010 Posted December 6, 2011 Share Posted December 6, 2011 please put the set cookie code in this loop if ($action == 'login_customer') { include('customer_login.php'); } Link to comment https://forums.phpfreaks.com/topic/252293-setting-a-cookie/#findComment-1294828 Share on other sites More sharing options...
Pikachu2000 Posted December 6, 2011 Share Posted December 6, 2011 Read the manual entry for setcookie regarding the proper arguments to pass to the function, also read the part about cookie data not being available until the next page load. Link to comment https://forums.phpfreaks.com/topic/252293-setting-a-cookie/#findComment-1294902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.