Undefined variable: url in PHP [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 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.

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++)

Index setted but undefined index [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.
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

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: search in C:\wamp\www\search1 (2).php on line 4 [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.
This is my code:
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button)
echo "you didn't submit a keyword!";
else
And I'm getting this error:
Undefined index: search in C:\wamp\www\search1 (2).php on line 4
Use isset() before reading an array key in $_GET/$_POST/$_REQUEST.
$button = isset($_GET['submit']) ? $_GET['submit'] : false;
$search = isset($_GET['search']) ? $_GET['search'] : false;
if(!$button) echo "you didn't submit a keyword!";
PHP Undefined Index

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