Tom10 Posted April 10, 2015 Share Posted April 10, 2015 (edited) <?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 April 10, 2015 by Tom10 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted April 10, 2015 Solution Share Posted April 10, 2015 (edited) 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 April 10, 2015 by Barand 1 Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 Thank you Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 (edited) I have another problem , 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 April 10, 2015 by Tom10 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 10, 2015 Share Posted April 10, 2015 You need to wrap your links in a condition to only display if no page has been specified if(!isset($_GET['page'])) { // output links } // your switch/case statement here Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 (edited) 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 April 10, 2015 by Tom10 Quote Link to comment Share on other sites More sharing options...
Barand Posted April 10, 2015 Share Posted April 10, 2015 Then it's time to re-read the early bits of the PHP manual http://php.net/manual/en/language.basic-syntax.php Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 <?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 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted April 10, 2015 Share Posted April 10, 2015 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? 1 Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 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 Quote Link to comment Share on other sites More sharing options...
Tom10 Posted April 10, 2015 Author Share Posted April 10, 2015 Thanks that has solved the problem 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.