Undefined index: page

hi im getting this error with this code and i cant figure it out, im a newbie so i know its not pro standards but im trying :slight_smile:

[php]<?php

if ( ! isset($_SERVER[‘HTTPS’])) {
header(‘Location: https://’ . $_SERVER[“SERVER_NAME”] . $_SERVER[‘REQUEST_URI’]);
}

//PAGE NAME

if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘news’))
{
$pagename = ‘Media - News’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘announcements’))
{
$pagename = ‘Media - Announcements’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘blueprints’))
{
$pagename = ‘Media - Blueprints’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘off_topic’))
{
$pagename = ‘Media - Off Topic’;
}
else
{
$pagename = ‘Media’;
}
//THEME HEADER
THEMEHEADER();

if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘news’))
{
require MEDIA_BASEDIR.‘media_news.php’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘announcements’))
{
require MEDIA_BASEDIR.‘media_announcements.php’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘blueprints’))
{
require MEDIA_BASEDIR.‘media_blueprints.php’;
}
else if (in_array($_GET[‘page’], PAGES, true) && ($_GET[‘id’] == ‘off_topic’))
{
require MEDIA_BASEDIR.‘media_news_off_topic.php’;
}
else
{
require MEDIA_BASEDIR.‘media_announcements.php’;
require MEDIA_BASEDIR.‘media_news.php’;
require MEDIA_BASEDIR.‘media_blueprints.php’;
require MEDIA_BASEDIR.‘media_news_off_topic.php’;
}

//THEME FOOTER
THEMEFOOTER();

?>[/php]

my error:

[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 8
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 12
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 16
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 20
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 31
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 35
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 39
[13-Nov-2016 10:16:00 UTC] PHP Notice: Undefined index: id in /home/zonepimp/public_html/pages/media.php on line 43

thankyou for your time :slight_smile:

the page in question: https://www.zonepimps.co.uk/?page=media

You never check if $_GET[‘page’] or $_GET[‘id’] are set before using them in the code

The https redirect is better to do outside of php (apache/ngix)

im sorry for my nooby reply but i dont fully understand…

how do i check if these are set?

where would you put the redirect?

thankyou for fast reply

ok i think iv got it i googled your answer and i changed my code

[php]if (empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)[/php]

??
im still unsure about what you mean about the header for https

thankyou

Still wrong. Look up isset.

http://www.php.net/manual/en/function.isset.php

isset — Determine if a variable is set and is not NULL

sorry i had to change it again

[php]<?php

if ( ! isset($_SERVER[‘HTTPS’])) {
header(‘Location: https://’ . $_SERVER[“SERVER_NAME”] . $_SERVER[‘REQUEST_URI’]);
}
//PAGE NAME

if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘announcements’) > 0)
{
$pagename = ‘Media - Announcements’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)
{
$pagename = ‘Media - Blueprints’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘off_topic’) > 0)
{
$pagename = ‘Media - Off Topic’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘news’) > 0)
{
$pagename = ‘Media - News’;
} else {
$pagename = ‘Media’;
}
//THEME HEADER
THEMEHEADER();

if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘news’) > 0)
{
require MEDIA_BASEDIR.‘media_news.php’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘announcements’) > 0)
{
require MEDIA_BASEDIR.‘media_announcements.php’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)
{
require MEDIA_BASEDIR.‘media_blueprints.php’;
}
else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘off_topic’) > 0)
{
require MEDIA_BASEDIR.‘media_news_off_topic.php’;
} else {
require MEDIA_BASEDIR.‘media_announcements.php’;
require MEDIA_BASEDIR.‘media_news.php’;
require MEDIA_BASEDIR.‘media_blueprints.php’;
require MEDIA_BASEDIR.‘media_news_off_topic.php’;
}
//THEME FOOTER
THEMEFOOTER();

?>[/php]

i tried the isset and i couldont work it out… if you could show me an example or maybe edit my code so i can see how it should be?

thankyou for your time and fast replys :slight_smile:

i know what you mean for my https now, it just clicked… i will look into that.

How are you expecting TEXT to be greater than NUMBERS? Your whole code and logic is a mess. You might want to go through some basic tutorials before you try to move forward.

i just need an example of how to use isset in this code so i dont get the undefined index error

sorry im a noob and just want to make this site for my hobby.

please help me, dont abandon me :frowning:

thankyou again

What EXACTLY are you wanting to do? And I don’t mean how to do what you think should be done.

i want to have each content shown only when they are called within the ?page=media page and carry my links on so ?page=media&id=news for example

i realy dont know how to explain it ill post my index this mite help?
i cant stress enough that im not a coder this is for my hobby site i dont intent to make money from this.

heres my index…

[php]<?php
// Directory Of Page_Include
const INCLUDE_BASEDIR = DIR.’/page_include/’;
// Directory Of Pages
const PAGES_BASEDIR = DIR.’/pages/’;
// Directory Of Themes
const THEME_BASEDIR = DIR.’/themes/’;
// Directory Of Blocks
const BLOCKS_BASEDIR = DIR.’/page_include/blocks/’;
// Directory Of News
const MEDIA_BASEDIR = DIR.’/pages/media/’;

require_once INCLUDE_BASEDIR.'page_config.php';
require_once THEME_BASEDIR.'/'.$theme_name.'/theme.php';
require_once INCLUDE_BASEDIR.'page_blocks.php';

const PAGES = [
// Array Of Active Pages
'media',
'our_world',
];

if (!isset($_GET[‘page’]))
{
// Default Index Page
require PAGES_BASEDIR.$DEFAULT_PAGE;
}
else if (in_array($_GET[‘page’], PAGES, true) && is_readable(PAGES_BASEDIR.$_GET[‘page’].’.php’))
{
// Displays The Called Link
require PAGES_BASEDIR.$_GET[‘page’].’.php’;
}
else
{
http_response_code(404);
// Display Error404 Page
require PAGES_BASEDIR.‘Error404.php’;
}

?>[/php]

thankyou for your time

Rather than trying to decipher your code attempt, just start here:

[php]<?php
/*

  • This file: display_pages.php
  • Acts as a Router to display pages
  • Restricts access to certain files

*/

//------------------------------------------------------------------------
// Restrict access to these files
//------------------------------------------------------------------------

// Specify some disallowed paths
$restricted_files = array(
‘header’,
‘footer’,
‘navbar’,
‘menu’,
);

//----------------------------------------------------------------------------------------
// Display Pages
//----------------------------------------------------------------------------------------

if (isset($_GET[‘p’]))
{
$page = basename($_GET[‘p’]);

// If it's not a disallowed path, and if the file exists
if (!in_array($page, $restricted_files) && file_exists("./includes/$page.php"))
    {
    $include = "./includes/$page.php";
    }
else
    {
    $include = './includes/404.php';
    }
}

else
{
$include = ‘./includes/default.php’;
}
?>[/php]

im sorry i dont mean to be rude but my index code is fine, i dont get errors there, im just having a problem with this code

example of one line that is failing for me…
[php]if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)[/php]
other then the error my site works fine…

i just need to make this line not get a Undefined index error…
i appriciate your time and making that code for me i will try and use it but for now i cant move on untill i fix this error :slight_smile:
thankyou again

The answer to your problem is in the code I gave you. Look at it closely.

are you saying if i change my index code to this it will alow the rest work as is? if you will…

thankyou

i dont understand how this
[php] if (!in_array($page, $restricted_files) && file_exists("./includes/$page.php"))[/php]
would replace this
[php]if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)[/php]

i realy cant see how i add the ==media and so on… i need to see and manualy edit the pages in this part i dont use database or anything…

thankyou

i realy cant see how i add the ==media and so on

You don’t. It is an automatic handler. It works as, if this page exists AND it can be viewed by itself, view the page. So, as long as your pages follow the same naming convention and place it is the same directory, it will find it. If it doesn’t exist, it will return a 404 page, but you could have it return to the homepage if preferred.

It is nice clean code.

i understand that but i dont understand how i can get the second page in there i.e

here there are two pages, if you will being called at the same time
[php]else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)[/php]

so page=media shows all of this

?page=media&id=blueprints
[php]else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘blueprints’) > 0)[/php]
?page=media&id=news
[php]else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘new’) > 0)[/php]
?page=media&id=off_topic
[php]else if (!empty($_GET[‘page’] == ‘media’) && ($_GET[‘id’] == ‘off_topic’) > 0)[/php]

etc
how do i get the
&& ($_GET[‘id’] == ‘off_topic’
in there so i can call other pages with in the ?page=media so the link carrys on like this ?page=media&id=news

i only see one being called here
[php] if (!in_array($page, $restricted_files) && file_exists("./includes/$page.php"))[/php]
here is the site to see the media page https://zonepimps.co.uk/?page=media

thankyou

Why are you so stuck on your bad code? I gave a simple clean answer to your problem. You can’t fix bad code with more bad code. Your whole approach is wrong.

Sponsor our Newsletter | Privacy Policy | Terms of Service