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!