ev5unleash Posted July 2, 2010 Share Posted July 2, 2010 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; } ?> Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 2, 2010 Share Posted July 2, 2010 Your switch looks fine but not the if. Try this: if( isset($_GET['user']) ) { $xid = strtolower($_GET['user']; } else { $xid = 'default'; } Quote Link to comment Share on other sites More sharing options...
ChemicalBliss Posted July 2, 2010 Share Posted July 2, 2010 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- Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 2, 2010 Share Posted July 2, 2010 Ha the default case. Yes, I skipped right over that! Quote Link to comment Share on other sites More sharing options...
ev5unleash Posted July 2, 2010 Author Share Posted July 2, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.