Undefined index error on Home.php

Closed
MohdNizam - Updated on Jan 17, 2018 at 04:57 AM
BunoCS Posts 15472 Registration date Monday July 11, 2005 Status Moderator Last seen March 25, 2024 - Jan 17, 2018 at 05:03 AM
I am getting Undefined Index error at home.php but all linked files are in the same directory. this is the log file. Please help
PHP Notice: Undefined index: page in home.php on line 56
PHP Notice: Undefined index: page in home.php on line 92
PHP Notice: Undefined index: page in home.php on line 94
PHP Notice: Undefined index: page in home.php on line 96
PHP Notice: Undefined index: page in home.php on line 98
PHP Notice: Undefined index: page in home.php on line 100
PHP Notice: Undefined index: page in home.php on line 102
PHP Notice: Undefined index: page in home.php on line 104
PHP Notice: Undefined index: page in home.php on line 106

<?php
    if(array_key_exists("page", $_REQUEST) && $_REQUEST["page"]=="ajaxbook")
    {
    setcookie("pageid_of_book$bookID", $pageid, strtotime('+365 days'));
    }

    header('HTTP/1.1 200 OK', TRUE);
    header("Status: 200");

    include_once './config.php';

    $uri = $_SERVER["REQUEST_URI"];

    if(strpos($uri, ".php")===false)
    {
    $URLParts = explode('/', trim(strtolower($uri),"/"));

    if(count($URLParts)>=1){
        $_REQUEST["page"] = $URLParts[0];
    } else {
        $_REQUEST["page"] = "books";
    }

    if(count($URLParts)>=2){
        $_REQUEST["id"] = $URLParts[1];
    } else {
        if($_REQUEST["page"]=="books"){
            $_REQUEST["id"] = 0;
        }
    }

    if($_REQUEST["page"]=="book"){

        if(count($URLParts)>=3 && $URLParts[2]=="search"){
            $_REQUEST["searchkeywords"] = urldecode($URLParts[3]);
        } else {        
            if(count($URLParts)>=3){
                $_REQUEST["pageid"] = $URLParts[2];
            }
        }
    }

    if(count($URLParts)>=3 && $_REQUEST["page"]=="authors"){
        if($URLParts[1]=="search"){
            $_REQUEST["searchkeywords"] = urldecode($URLParts[2]);
        }
    }

    if(count($URLParts)>=4 && $_REQUEST["page"]=="books"){
        if($URLParts[2]=="search"){
            $_REQUEST["searchkeywords"] = urldecode($URLParts[3]);
        }
    }
    }

    if(strpos($_REQUEST["page"],"ajax") !== false) {

    if($_REQUEST["page"] == "ajaxtitles") {
        include './systitles.php';
        showAjaxBody();
    }

    if($_REQUEST["page"] == "ajaxauthors") {
        include './sysauthors.php';
        showAjaxBody();
    }

    if($_REQUEST["page"] == "ajaxbooks") {
        include './sysbooks.php';
        showAjaxBody();
    }

    if($_REQUEST["page"] == "ajaxbook") {
        include './syspage.php';
        ?>
        <div id='dynamicarea'>
            <div class='mainbar'>
                <?php showMainBar(); ?>
            </div>
            <div class="mainarea">
                <?php showBody(); ?>
            </div>
        </div>
        <?php
    }

    die();
    }

    $pageTitle = "";

    if($_REQUEST["page"] == "books"){
    include './sysbooks.php';
    }else if($_REQUEST["page"] == "book" && !array_key_exists("pageid", 
    $_REQUEST)){
    include './sysbook.php';
    }else if($_REQUEST["page"] == "book" && array_key_exists("pageid", 
    $_REQUEST)){
    include './syspage.php';
    }else if($_REQUEST["page"] == "authors"){
    include './sysauthors.php';
    }else if($_REQUEST["page"] == "about"){
    include './sysabout.php';
    }else if($_REQUEST["page"] == "author"){
    include './sysauthor.php';
    }else if($_REQUEST["page"] == "title"){
    include './syspage.php';
    }else if($_REQUEST["page"] == "mybooks"){
    include './sysmybooks.php';
    }

1 response

BunoCS Posts 15472 Registration date Monday July 11, 2005 Status Moderator Last seen March 25, 2024 1,534
Jan 17, 2018 at 05:03 AM
Hello,

I have edited your post to add code tags. With this, I saw that it seems to have some syntax error around line [75-84]. I'm not saying it is the reason why you have this error but you have to fix it.
Moreover, to reduce bugs opportunities, why don't you store
$_REQUEST["page"]
one time for all?

Fix these remarks and let us know if issues are still here.
0