1

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
1
  • Could you please format your code to a reasonable degree by adding linebreaks and indentation. Commented Jul 11, 2021 at 13:07

1 Answer 1

2

In terms of programming, an undefined index means that there is no value defined in the array specific to the index. Now to understand how this works, the $_GET 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 var_dump($_GET['idsub']) to check if values are passed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.