redirect - Undefined index error on php url redirection script
Get the solution ↓↓↓I have a small php script for url redirection. I'm not a programmer, the script is composed by a freelancer a few years ago, but now I'm unable to contact him. I recently migrate my website to another server and start getting errors due to this script. I try some basic tricks I know but I'm unable to avoid errors. I will appreciate any ideas
Here is the script:
if(!empty($_GET['idsub'])||!empty($_GET['idsub2'])||!empty($_GET['idf'])||!empty($_GET['idp']))
header("Location: /_".preg_replace('/\.php$/','',$_GET['idsub'])."/_".preg_replace('/\.php$/','',$_GET['idsub2'])."/_".preg_replace('/\.php$/','',$_GET['idf'])."/_".preg_replace('/\.php$/','',$_GET['idp']).($_GET['page']?"?page=".$_GET['page']:''),301);
if($_GET['idp']=='.php')unset($_GET['idp']);
if($_GET['idsub']=='.php')unset($_GET['idsub']);
if($_GET['idsub2']=='.php')unset($_GET['idsub2']);
if($_GET['idf']=='.php')unset($_GET['idf']);
if($_GET['demmi']!='true' && (!empty($_GET['idsub'])||!empty($_GET['idsub2'])||!empty($_GET['idf'])||!empty($_GET['idp']))){
$key=(empty($_GET['idf'])?'':'1').(empty($_GET['idsub'])?'':'2').(empty($_GET['idsub2'])?'':'3').(empty($_GET['idp'])?'':'4');
$vals=(empty($_GET['idf'])?'':'/'.preg_replace('/.php$/','',$_GET['idf'])).(empty($_GET['idsub'])?'':'/'.preg_replace('/.php$/','',$_GET['idsub'])).(empty($_GET['idsub2'])?'':'/'.preg_replace('/.php$/','',$_GET['idsub2'])).(empty($_GET['idp'])?'':'/'.preg_replace('/.php$/','',$_GET['idp']));
$vals=preg_replace('/\/([^\/]*)$/','./$1',$key.$vals);
header("Location: /$vals".(empty($_GET['page'])?'':'?page='.$_GET['page']),301);
}
if($_GET['demmi']=='true' )
{
$key=str_split($_GET['key']); $i=0;
$vals=explode('/',str_replace('./','/',$_GET['vals']));
foreach($key as $h)
{switch($h)
{case '1': $_GET['idf']=$vals[$i].'.php'; break;
case '2': $_GET['idsub']=$vals[$i].'.php'; break;
case '3': $_GET['idsub2']=$vals[$i].'.php'; break;
case '4': $_GET['idp']=$vals[$i].'.php'; break;}
$i++;}
}
$idf=$_GET['idf'];
$idsub=$_GET['idsub'];
$idsub2=$_GET['idsub2'];
$idp=$_GET['idp'];
$page=$_GET['page'];
if (isset($page)) {
$page=$page;
} else {
$page=1;
}
And here are the errors I get:
PHP Notice: Undefined index: idp in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idsub in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idsub2 in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idf in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: demmi in /home/typol0/public_html/control/index.php on line 7
PHP Notice: Undefined index: demmi in /home/typol0/public_html/control/index.php on line 14
PHP Notice: Undefined index: idf in /home/typol0/public_html/control/index.php on line 25
PHP Notice: Undefined index: idsub in /home/typol0/public_html/control/index.php on line 26
PHP Notice: Undefined index: idsub2 in /home/typol0/public_html/control/index.php on line 27
PHP Notice: Undefined index: idp in /home/typol0/public_html/control/index.php on line 28
PHP Notice: Undefined index: page in /home/typol0/public_html/control/index.php on line 29
Answer
Solution:
In terms of programming, an undefined index means, that there is not value defined in the array specific to the index. Now to understand how this works, the $_GET method array does not have any values defined Which is why this error pops up. You need to debug the $_GET['idsub'] variable to check if any values exist. you can use var_dump() on all the variables like e.g:(var_dump($_GET['idsub'])) to check if values are passed.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: dompdf image not found or type unknown
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.