Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP help.


fashizzlepop's Avatar
Member
0 0

Hey I'm trying to make a challenge that helps teach about cookies. What i want them to do is add a cookie with certain info and then go to this page.

Here is the challenge link. http://fashizzlepop.ulmb.com/challenges/cookies/1.php

Here is the pass checking code. Prolly some simple bug… can't figure it out. Other suggestions welcome.



if (isset($_GET['chall'])) {
	switch ($_GET['chall']) {
	case 'cookie1':
		if (isset($_COOKIE["cookie1"])) {
			if ($_COOKIE["cookie1"]=="85e7a731957c903616d0860750fc0dbd"){
			echo "Congratulations! Now try and decypt the md5 hash set as the value for the cookie!"; }
			else { 
			echo "I'm sorry, no cookie found. Cookie either not set or expired!"; }
		else {
		echo "I'm sorry, no cookie found. Cookie either not set or expired!"; }
		break;
	default: 
	echo "I'm sorry, no cookie found! Cookie either not set or expired!"; 
	} 
} 
else
echo "I'm sorry Error in password checking!";
?>```

Mouzi's Avatar
Member
0 0

You have else statement twice? You should learn to read PHP errors they usually tell pretty easily where the problem is.

markupParse error: syntax error, unexpected T_ELSE in /hosted/subs/ulmb.com/f/a/fashizzlepop/public_html/challenges/passcheck.php on line 21

Means that the parser has encountered an else statement, that shouldn't be there, on line 21. That would have answered your problem already :P


fashizzlepop's Avatar
Member
0 0

I know, there are supposed to be 2 if statements and I don't see an extra else anywhere. I also looked at the error and still can't get what's worng.


Mouzi's Avatar
Member
0 0

What's this then:

echo "I'm sorry, no cookie found. Cookie either not set or expired!"; }
else {
echo "I'm sorry, no cookie found. Cookie either not set or expired!"; }```

fashizzlepop's Avatar
Member
0 0

Well if you count it. Theres 3 if's and 3 elses. It's easier to read tabbed out but it erased that.


Mouzi's Avatar
Member
0 0

Yeah, but you can't have two else statements one right after another. If you want to have one else statement for all if statements you should put the second one outside the current if statement it is in.

EDIT: I think you have just misplaced one }


fashizzlepop's Avatar
Member
0 0

yah you're right. I think i got it working now. (i think :P) Thanks for the help.