-3

I'm experimenting with php, trying to understand how it works, and converted a static html site to a dynamic php site, just to see if I could get it done. I managed to get it to work, but I get a error saying

Notice: Undefined index: page in C:\xampp\htdocs\alt\index.php on line 12

(this is line 1 in the code below). Of course I managed to get this away from displaying by using and @ in the code, but I still wonder if I am doing something wrong... It works nevertheless as it should.

if (!$_GET['page']){
    include 'content/index.inc.php';
}
else {
    $page = htmlspecialchars($_GET['page']);
        $path = 'content/'.$page.'.inc.php';
        if (file_exists('content/'.$page.'.inc.php')){
            include 'content/'.$page.'.inc.php';
        }
        else{
            include 'content/error.inc.php';
        }
}
Beni Cherniavsky-Paskin
  • 9,483
  • 2
  • 50
  • 58
Vlegel
  • 3
  • 1

1 Answers1

0

Try

<?PHP
if(!isset($_GET['page'])) {
    include 'content/index.inc.php;
}
Fallen
  • 4,435
  • 2
  • 26
  • 46
  • 2
    Nope. THe second part will issue a notice if page is not set – Ryan Jul 26 '14 at 18:43
  • if it is not set will it check the condition after the `||` ? – Fallen Jul 26 '14 at 18:45
  • care to explain the downvote please? – Fallen Jul 26 '14 at 18:47
  • Actually, the way you have it set up would not show a notice because evaluation would stop after the first, but if you reversed the conditions it would show the notice. Either way the second part is not necessary. – Ryan Jul 26 '14 at 18:48
  • @true: when you write a code, order of condition is important. I've not written it in reversed way because that way is incorrect. – Fallen Jul 26 '14 at 18:50
  • I wasn't the down-voter, but the second part will not have any effect and is completely useless. The second part by will issue a notice by itself. And the down-vote was valid because your code was bad. But now that you have edited it, someone decided to take there upvote back – Ryan Jul 26 '14 at 18:50
  • It worked, but it didn't needed the part after ||. Either way, I understand now what I did wrong. Thanx a great deal! – Vlegel Jul 26 '14 at 18:51
  • I kept that in place because it was part of your code and you might need to check that. – Fallen Jul 26 '14 at 18:51
  • @Vlegel: If it was the answer you're looking for please mark it as the accepted answer – Fallen Jul 26 '14 at 18:53
  • 1
    oh, yes, was wondering how to do that, but just figured that out. thanx again! – Vlegel Jul 26 '14 at 18:55