Jump to content

Case and Break


Tom10

Recommended Posts

<?php

if(isset($_GET['page']) && !empty($_GET['page']))
{
switch($_GET['page'])
{
case: 'home':
{
echo "<center><h1>Home Page</h1></center>";
}

break;

case: 'challenge':
{
echo "<center><h1>Challenege Page</h1></center>";
}

break;

case: 'languages':
{
echo "<center><h1>Languages Page</h1></center>"
}

break;

case: 'passwords':
{
echo "Passwords Page";
}

break;
}
}

?>

<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=home' ?>"> Home </A> <BR />
	<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=challenge' ?>"> Challenge </A> <BR />
	<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=languages' ?>"> Languages </A> <BR />
	<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=passwords' ?>"> Passwords </A> <BR />
 
Hi so i am currently learning about case and break and i am getting the following error
Parse error: syntax error, unexpected ':' in
case: 'home':

Apparently is where the error is coming from

Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/
Share on other sites

you don't want the the : after case: and you dont need those internal {..}s

switch ($_GET['page'])
{
    case 'home':
        echo "<center><h1>Home Page</h1></center>";
        break;
    case 'Language':
        echo "<center><h1>LanguagePage</h1></center>";
        break;
}
Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/#findComment-1508694
Share on other sites

Here is an example i found, but i don't understand why he has put ?> closing tags

if(isset($_GET['page']) && !empty($_GET['page'])) {
switch($_GET['page']) {
case 'home': {
?>
<CENTER>
<H1> <U> Home </U> </H1>
This is a sitemap of all the links and pages for this file, from here you can navigate to other pages.

<H3> <U> Sitemap </U> </H3>
<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=home' ?>"> Home </A> <BR />
<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=challenge' ?>"> Challenge </A> <BR />
<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=languages' ?>"> Languages </A> <BR />
<A HREF="<?php echo htmlspecialchars(htmlspecialchars($_SERVER['PHP_SELF'])) . '?page=passwords' ?>"> Passwords </A> <BR />
<?php
}
break;
case 'challenge': {
?>
<CENTER>
<H1> <U> The Challenge </U> </H1>
Somewhere in this script is a vulnerability I have hidden! A key has been hidden somewhere which will lead on to the next part of the Challenge.

<BR /> <BR />
<H3> <U> Files on this server </U> </H3>
Below is a list of files in this directory so you can complete the challenge. This should be all you need to complete this challenge, the rest will test your hacking knowledge!
<BR /> <BR />

<H3> <U> File List </U> </H3>
<?php
foreach(preg_grep('/^([^.])/', scandir(getcwd())) as $files) {
if($files != '.' | $files != '..') {
print($files . ' <BR />');
}
}
}
break;
Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/#findComment-1508704
Share on other sites

<?php

		if(isset($_GET['page']) && !empty($_GET['page']))
		{
			switch($_GET['page'])
			{
				case 'home':

						?>
							<html>
								<b>Home Page</b>
							</html>
						<?

				break;
				case 'challenge':

					?>
						<html>
								<b>Challenege</b>
						</html>
					<?

				break;

				case 'languages':

					?>
						<html>
								<b>Languages</b>
						</html>
					<?

				break;

				case 'passwords':

				?>

						<html>
							<b>Passwords</b>
						</html>

				<?

				break;
			}
		}
	?>

Parse error: syntax error, unexpected end of file

Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/#findComment-1508712
Share on other sites

Parse error: syntax error, unexpected end of file

 

Have you tried using the full PHP open tag? Try changing this "<?" to "<?php" in the various locations. Note that more information about the PHP tags can be found here:

http://php.net/manual/en/language.basic-syntax.phptags.php

 

Also, are you planning to build an entire website using a single PHP script...or are you just experimenting with switch?

Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/#findComment-1508715
Share on other sites

Have you tried using the full PHP open tag? Try changing this "<?" to "<?php" in the various locations. Note that more information about the PHP tags can be found here:

http://php.net/manual/en/language.basic-syntax.phptags.php

 

Also, are you planning to build an entire website using a single PHP script...or are you just experimenting with switch?

ok thanks i will try that, and i am just experimenting with switch

Link to comment
https://forums.phpfreaks.com/topic/295412-case-and-break/#findComment-1508717
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.