Php Link won't execute
Posted: Sun Aug 31, 2008 2:22 am
The problem is highlighted in red
after my if statement executes and the draw function is called, php doesn't execute the link
header('Location: http://www.example.com/');
am not sure why.
please help me and
thanks in advance.
.
<?php
session_start();
require_once 'Image/Barcode.php';
$file = 'afiles.txt' or die('Could not read file!');
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
$numLines=count($data);
natcasesort($data);
$colCtr = 0;
$cols = 8; # Number of columns to display
$items=$_GET['items'];
$items=40;
$imageCount=0;
$pos =0;
$pos=$_GET['pos'];
if(!$pos){
$pos= 0;
}
$position = $pos * $items;
$data = array_unique($data);
$data1 = array_slice($data, $position, $items);
$numLines=count($data1);
$index=1;
setcookie("index", $index, time()+3600);
$index=$_COOKIE["index"];
$temp = explode(",", $data1[$index]);
$images=trim($temp[0]);
$descriptions=trim($temp[1]);
$value=trim($temp[2]);
if(isValid($value)==true){
Image_Barcode::draw($value, 'upca', 'png');
header('Location: http://www.example.com/');
}
else
{
echo "NO UPC";
}
function isValid($value)
{
$valueString = (string) $value;
//$this->_setValue($valueString);
if ('' === $valueString) {
$error='STRING_EMPTY';
return false;
}
if (strlen($valueString) !== 12) {
$error='INVALID_LENGTH';
return false;
}
$barcode = substr($valueString, 0, -1);
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 11; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10-$calculation;
if ($valueString[11] != $checksum) {
$error='INVALID';
return false;
}
return true;
}
?>
after my if statement executes and the draw function is called, php doesn't execute the link
header('Location: http://www.example.com/');
am not sure why.
please help me and
thanks in advance.
.
<?php
session_start();
require_once 'Image/Barcode.php';
$file = 'afiles.txt' or die('Could not read file!');
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
$numLines=count($data);
natcasesort($data);
$colCtr = 0;
$cols = 8; # Number of columns to display
$items=$_GET['items'];
$items=40;
$imageCount=0;
$pos =0;
$pos=$_GET['pos'];
if(!$pos){
$pos= 0;
}
$position = $pos * $items;
$data = array_unique($data);
$data1 = array_slice($data, $position, $items);
$numLines=count($data1);
$index=1;
setcookie("index", $index, time()+3600);
$index=$_COOKIE["index"];
$temp = explode(",", $data1[$index]);
$images=trim($temp[0]);
$descriptions=trim($temp[1]);
$value=trim($temp[2]);
if(isValid($value)==true){
Image_Barcode::draw($value, 'upca', 'png');
header('Location: http://www.example.com/');
}
else
{
echo "NO UPC";
}
function isValid($value)
{
$valueString = (string) $value;
//$this->_setValue($valueString);
if ('' === $valueString) {
$error='STRING_EMPTY';
return false;
}
if (strlen($valueString) !== 12) {
$error='INVALID_LENGTH';
return false;
}
$barcode = substr($valueString, 0, -1);
$oddSum = 0;
$evenSum = 0;
for ($i = 0; $i < 11; $i++) {
if ($i % 2 === 0) {
$oddSum += $barcode[$i] * 3;
} elseif ($i % 2 === 1) {
$evenSum += $barcode[$i];
}
}
$calculation = ($oddSum + $evenSum) % 10;
$checksum = ($calculation === 0) ? 0 : 10-$calculation;
if ($valueString[11] != $checksum) {
$error='INVALID';
return false;
}
return true;
}
?>