php $_GET['page'] 未定义索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8769493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:27:55  来源:igfitidea点击:

Undefined index with $_GET['page']

phpget

提问by user1128882

browser - Notice: Undefined index: page in C:\xampp\htdocs\index.php on line 78

浏览器 - 注意:未定义索引:第 78 行 C:\xampp\htdocs\index.php 中的页面

78 line - switch($_GET['page']){

78线- switch($_GET['page']){

all code

所有代码

<?php
switch($_GET['page']){
case 1:
include_once('/p/fizika.php');
break;
case 2:
include_once('/p/geom.php');
break;
case 3:
include_once('/p/algebra.php');
break;
case 4:
include_once('/p/kalk.php');
break;
default:
include_once('/p/home.php');
break;
}
?>

回答by Shakti Singh

This Notice thrown when you try to use an array index which does not exists. The $_GET['page']is not set.

当您尝试使用不存在的数组索引时抛出此通知。在$_GET['page']未设置。

You should check if the variable index is exists using isset()

您应该使用isset()检查变量索引是否存在

if(isset($_GET['page']))
{
  switch($_GET['page']){
  case 1:
  include_once('/p/fizika.php');
  break;
  ...
  ...
}

This is now Notice free.

这现在是免费通知。

回答by Prof83

$_GET['page']is not set

$_GET['page']未设置

$_GETrefers to the params in the url

$_GET指的是url中的参数

so $_GET['page']is referring to file.php?page=123

所以$_GET['page']是指file.php?page=123

回答by Rajat Singhal

This means that the $_GET['page']variable is not set...

这意味着$_GET['page']未设置变量...

So you should add ?page=1in the url or either set the get variable form where the request for the page s getting generated

因此,您应该添加?page=1url 或设置 get 变量表单,其中生成页面请求

Or if you want to execute without it is being set

或者如果你想在没有设置的情况下执行

Apply

申请

if(isset($_GET['page']))
{
   //Logic
}