login through switch only working for default

Hi

I have a simple 1 page cms for editing some text on small websites. i am adding a multiple user function.
the correct user with it's credentials is chosen through the url:
index.php?user=home

it works correct, except for this part:

$ppp = md5($password);
            define('SMC_PASS', $ppp);

SMC_PASS is for a login for a sitemap page i put in an iframe. i can log in correctly to the sitemap in the iframe with the default or "else" credentials but not with the home or start passwords.
(= only password protected)

why could this be?
the rest works well, i can login to the cms page with all 3 cases.. only the sitemap pass (SMC_PASS) doesn't login for case home and start.

thanks
<?

if(!empty($_GET['user']))
	{
		switch($_GET['user'])
		{
		case "home":
			$username23 = "home"; //
			$password = "home"; //
			define ("USERN", $username23);
		break;
		
		case "start":
			$username23 = "start"; // 
			$password = "start"; //
			define ("USERN", $username23);
		break;
	
		default:
			$usernameadmin = "peps"; //
			$password = "peps"; //
			define ("USERN", $usernameadmin); //
			$username23 = "";
			break;
		}
	}
else 
	{
	$usernameadmin = "peps"; //
	$password = "peps"; //
	define ("USERN", $usernameadmin); //
	$username23 = "";
	}
	
//Site password
	define ("PASSW", $password);
	
	$ppp = md5($password);
		define('SMC_PASS', $ppp);
	?>

Open in new window

peps03Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peps03Author Commented:
for some reason the case: "home" & "start" password aren't passed to:
define('SMC_PASS', $ppp);

because if i make it like this it will work:
define('SMC_PASS', md5(home));

> now case "home" can log in..

what is wrong with the code??

0
Ray PaseurCommented:
Looking at the code sample above, all it appears to do is define some constants or clear some variables.  As a matter of good programming practice, your defined constants should actually be constant -- that is, they should not be set conditionally, like variables.  Since we cannot see how you use the constants and variables, it is impossible to know exactly what is going wrong.

Regarding this statement: define('SMC_PASS', md5(home)); -- you might want to add error_reporting(E_ALL); to the top of all your scripts.  As written that statement will look for a constant named home and attempt to make the md5() string from the value in that constant.  If the constant is not defined, PHP will silently use NULL as input to the MD5() function.  In other words, it will always produce the same md5() string.

If you want to learn about login and logout processes, I have an article here that might be helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

Best of luck with the project, ~Ray
0
peps03Author Commented:
Hi Ray,

Thanks for the reaction!

i read some stuff about constants and variables on php.net.

I replaced the constants with variables. but now i have the problem that i get an undefined variable 'username' and 'password'

could this be because the variables are in a function and the $username and $password are defined on another page that is included?

how can i fix this?

thanks!
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Ray PaseurCommented:
Undefined variable is pretty clear information.  You may be looking at an issue of variable scope - inside functions and classes, the variable scope may only apply to the current function and class.
http://www.php.net/manual/en/language.variables.scope.php

You can put these variables into a function's argument list, or set them as properties of a class with a "setter" method.  Or you can add them to the $GLOBALS array.  $GLOBALS is a "superglobal" array - that is, it exists in every scope and namespace.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peps03Author Commented:
Thanks for the directions, i finally figured it out!

Kind regards!
0
Ray PaseurCommented:
Thanks for the points -- glad I could help.  All the best, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.