Jump to content

Case and Break


Tom10
Go to solution Solved by Barand,

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

Edited by Tom10
Link to comment
Share on other sites

  • Solution

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;
}
Edited by Barand
  • Like 1
Link to comment
Share on other sites

I have another problem


a9e38597c2855bef9f9b1d808c2234e0.png


e06029245cdee95f56ced503667755f1.png


When i click a link how do i clear everything and have a fresh page? when i click challenge the page stays the same except it echo's challenge page but is there a way when i click challenge to remove all the links and add new content?


Edited by Tom10
Link to comment
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;
Edited by Tom10
Link to comment
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
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?

  • Like 1
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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