1

I have made a registration form and a login form using PHP.

The registration form saves user's information to a database.

But as I am pretty new to PHP I want to achieve this think. I have also made a whole e-commerce website with Drupal commerce(commerce kickstart) but I want as an entrance page to be this registration form and when I grant them access to be able to see the whole content of my e-commerce website.While i say grant them access when they give me the fields of the registration form,they wont be able to enter the website until I send them a password. So my question is : How can I achieve not be able to see the entire website?What I need to do to protect it? I mean I need to add code on the registration form? on the login form or the template/theme?

I know that I have to use $_SESSION[] and $_COOKIE[]

For example

if($_SESSION['loggedIN'] ===false){ header('location:login_page.php')}

but I do not know where to put the code so as to work. In which part of the commerce kickstart do I have also to say that the e-commerce website would be on a sub-domain as the domain will be used for the registration form if this helps.

Thanks!

2

Ah, you don't need to be doing stuff like that with PHP. Drupal has plenty of tools to handle permissions for users.

Drupal already has the ability to allow you to make sure users need to be approved by an admin - check the user settings.

As for restricting access to "enter" site... well you need to review your user permissions table. "enter" is a pretty vague word to be using in Drupal terms.

1

I don't really understand why do you use custom login and register form instead of Drupal one. As for me, this is not a good approach.

Nevertheless, if your login form setups $_COOKIE['loggedIN'] variable then it can be used in Drupal.

In code of your form save cookie in a way it can be available to domain and any subdomain

setcookie('loggedIN', TRUE, 0, '/', 'domain.com', FALSE, TRUE);

This will setup cookie that will be expired on the end of the session.

Create simple drupal module "mylogin" by name (http://drupal.org/node/1074360). In mylogin.module file place this code:

/* hook init */
function mylogin_init() {
  global $user;
  if (!$user->uid) {
    /* Check cookie only for anonymous Drupal users. If user is logged-in using Drupal login form then he will not be affected.*/
    if (empty($_COOKIE['loggedIN'])) {
      header('Location: http://domain.com/login.php');
      exit;
    } 
  }
}

mylogin_init() function will be executed on any page, and redirect any users that don't have a Drupal session to your custom login form.

NOTICE! My advice - not to use this method but to use standard Drupal register and login forms instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.