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
https://forums.phpfreaks.com/topic/206543-php-login-only/
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
https://forums.phpfreaks.com/topic/206543-php-login-only/#findComment-1080383
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
https://forums.phpfreaks.com/topic/206543-php-login-only/#findComment-1080427
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.