Jump to content

Setting a cookie


musiclvr

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.