Jump to content

PHP Login only


ev5unleash

Recommended Posts

Hi Everyone,

 

I'm a newbie and teaching myself PHP. I'm creating a Mangagement System and I'm trying to create a login system with just PHP until I learn more about PHP and MySQL. Could someone take a look at this code and tell me what I'm doing wrong? What I want this script to do is if index.php is called it will direct to fail.php, if user=(anything other than what is a case) then redirect to fail.php and if index.php?user=test is called, redirect to templogin/test.php.

<?php

if( !isset($_GET['user']) )
{
    $xid = 'default';
}
elseif { $xid = 'default'; }
   

else { $xid = strtolower($_GET['user']);

switch($xid)
{
case 'test':
  include('templogin/test.php');
break;
case 'default':
  include('fail.php');
break;
} 

?>

 

Link to comment
Share on other sites

God thing abotu switches is they are dead simple:

 

<?php
// using ISSET() is a good way of removing those "Notice: Undefined Variable...." errors:
$xid = (isset($_GET['user']))? $_GET['user'] : NULL;

switch($xid)
{
   default:
      include('fail.php');
   break;

   case 'test':
      include('templogin/test.php');
   break;
}

?>

 

Also though, to make your script slightly more secure (you should learn more php though before you get too much into security), define a variable on this page, and on the "test.php", check if that variable exists (its better to use a CONSTANT since some webservers use GLOBALS).

 

eg:

 

index.php

<?php

// Make sure people go through this script:
define("START_ON_INDEX", TRUE);

// using ISSET() is a good way of removing those "Notice: Undefined Variable...." errors:
$xid = (isset($_GET['user']))? $_GET['user'] : NULL;

switch($xid)
{
   default:
      include('fail.php');
   break;

   case 'test':
      include('templogin/test.php');
   break;
}

?>

 

templogin/test.php

<?php

if(!is_defined(START_ON_INDEX)){
   exit("DENIED");
}else{
   echo("Allowed");
}

?>

 

Hope this helps,

-cb-

Link to comment
Share on other sites

Thanks everyone for the help! I've done what I needed to do. But since I really only know includes and such I'm just using the same code for each section of the login (ex. user if test > test.php if pass is test > testpriv (drop down box option) include certain page. Anyone have better idea. I'm reading a book on PHP and MySQL but I'm only 1/10 through it :( if anyone could recommend me to something that can help me construct a login system with PHP and MySQL that'd be great!

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.