开发者

print a variable generated from another .php file

I'm trying to display the value of $codeOut from a php file called get_rebate.php.

开发者_JAVA技巧

Currently I am using:

<?php include ("get_rebate.php"); echo substr($codeOut,7); ?>

to try and get the output of $codeOut from get_rebate.php to appear in the page but instead it returns the error message that get_rebate.php generates when it can't verify the value.

I'm probably not calling the result of get_rebate.php ($codeOut) properly but looking for guidance with this problem.

get_rebate.php:

<?
$code=$_GET['code'];
$rnum=50000-$_GET['rnum'];

if ($code=="2210" || $code==$rnum) {
    makeVerifier($code);
} else { echo "The Rebate Code you have entered (" . $code . ") does not apply to this product.\nPlease consult with your Fitness Expert and request if a Rebate Code\nis available for this product.";
}
function makeVerifier($codeIn) {
    $len=strlen($codeIn);
    for ($i=0;$i<$len;$i++) {
        $codeOut.=ord(substr($codeIn,$i));
        if (strlen($codeOut)>7) {break;}
    }
    echo "Congratulations! Your Manufacturers Rebate Verification Code is M" . substr($codeOut,0,7);
}
?>

The output on the page is: The Rebate Code you have entered () does not apply to this product. Please consult with your Fitness Expert and request if a Rebate Code is available for this product


Obviously $code is not 2210 or $rnum so you get the error message. Even if the code would be correct, it wouldn't work: $codeOut's scope is limited to the makeVerifier() function. You need to call it with $codeOut = makeVerifier( $code ) and at the end of the function add return $codeOut.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜