Index setted but undefined index [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
I'm in a ambiguous situation.
Here's the concerned code:
http://prntscr.com/9edm4j
public function verifyReply($reponse)
{
$qr = $this->mStopBOT;
if(isset($_SESSION["stopBOT"]))
{
if($_SESSION["stopBot"] === false)
{
$_SESSION["stopBOT"] = true;
if($qr[$_SESSION["stopBOTq"]][1] == $reponse)
return true;
}
}
return false;
}
And here is the problem:
http://prntscr.com/9ednwm
PHP Notice: Undefined index: stopBot in /home/*************/public_html/inc/classes/Security.inc.php on line 92
The isset() function returns true, but when I use the function, it says that the index is undefined! ?
Regards and Thanks in Advance

You are checking if $_SESSION['stopBOT'] is set but then use $_SESSION['stopBot']
Note the case difference, stopBOT vs stopBot

Related

Undefined offset error in PHP at last line [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
I'm getting an undefined offset error
<?php
function ara($one, $two, $three)
{
#preg_match_all('/' . preg_quote($one, '/') .
'(.*?)'. preg_quote($two, '/').'/i', $three, $m);
return #$m[1];
}
$link = "example.com";
$article = file_get_contents($link);
$sport = ara('data-bin="','"',$article);
$channel = ara('data-videobin="','"',$article);
for ($i=0;$i<50;$i++)
echo"<span class='linko'><a target='_blank' href='example.org/live1.php?id=".($channel[$i]."'>$sport[$i]</a>"."<br></span>"); // error is here
?>
How can I fix it? I'am waiting for your helps. Thanks.
These codes are for a live channel website.
The channel variable has less than 50 elements.
Usually in a loop, you should set the end condition to the size of the array.
for ($i=0;$i<sizeof($channel);$i++)

Undefined variable: url in PHP [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
What am I doing wrong?
I have a error about a undefined variable but it is defined or not?
Undefined variable: url in /mnt/web121/d2/33/58167933/htdocs/includes/functions.php on line 74
$url = "http://www.crime-world.eu";
function logincheck(){
if (empty($_SESSION['username'])){
check_legit($url);
echo "<SCRIPT LANGUAGE='JavaScript'>window.location='index.php';</script>";
exit();
}
check_legit($url);
}
$url is a global variable. Declare it as global in your function.
function logincheck(){
global $url;
...
}
$url is not in the function checklogin scope, you can pase it to the function with function parameter or use it as a global variable.

sum of 2 number with object and method [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
why am I getting these errors?
Undefined variable: num1
Cannot access empty property
class sum{
public $num1=1;
public function fun($num2){
return $this->$num1+$num2;
}
}
$number = new sum();
echo $number->fun(3);
class sum{
public $num1=1;
public function fun($num2){
return $this->num1+$num2;
//removed $^^
}
}
$number = new sum();
echo $number->fun(3);

Undefined index: topic in C:includes\topic_list.php on line 9 [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
<?php
$qr_topic = #mysql_query("SELECT * FROM topics");
while ($topic = #mysql_fetch_array($qr_topic)) {
$highlight = "";
**if ($topic['name'] == $_GET['topic'] || $post['topic_id'] == $topic['id']) {**
$highlight = "class='highlight'";
}
echo "<li ".$highlight."><a href='index.php?topic=".$topic['name']."'>".$topic['name']."<img src='img/".$topic['image']."' width='195' height='90' /></a></li>";
}
?>
Getting Undefined index error, not sure what is wrong ? This could be the line for error.
if ($topic['name'] == $_GET['topic'] || $post['topic_id'] == $topic['id']) {**
You try to use $_GET['topic'] without checking if it exists first, that's why you get that error. I'd recommend you to test if the variable exists first using is_set() or empty().

Undefined index on page load [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
the message is
Notice: Undefined index: flag in C:\xampp\htdocs\myfiles\mobile tracking\index.php on line 63
my code is
<?php
$stat=$_REQUEST['flag'];
if($stat=="FAILED")
{
echo "Username/password doesnot exists";
}
?>
The global variable $_REQUEST['flag'] is probably having value NULL. This is the reason you are getting this error. Well, try using isset(). to check whether the variable is having any value or not.
You should check if the $_REQUEST['flag'] variable has been set:
<?php
$stat= ( isset($_REQUEST['flag']) ? $_REQUEST['flag'] : null) ;
if($stat=="FAILED")
{
echo "Username/password doesnot exists";
}
?>
You received a notice because you didn't initialized the values of the array. Use this construction to prevent them.
if (! array_key_exists('flag', $_REQUEST)) {
$_REQUEST['flag'] = whatever value goes here;
}

Categories