I try to remake the dhl-courier for my courier www.opek.com.pl. The tracking webside are here:
http://opek.top100.net.pl/
Everyone can use this form, but must write username/passord. For all, you can use:
username (Nazwa uzytkownika): opek
password (haslo): opek
True list id are (Podaj numer(y) przesylek): 30627320
My source of catalog/op_tracking.php are like here:
--------------------------------------
<?php
/*
$Id: dp_tracking.php, v1.0 2008/09/29 web-engel - osC forum id - chris23
This script will be called via ajax from account_history_info.php and admin/orders.php
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright © 2003 osCommerce
Released under the GNU General Public License
*/
// prevent direct calls to this page
if (!isset($_GET['tracking_id'])) {
die('Direct call to script. Exiting.');
}
error_reporting(E_ALL);
require("includes/application_top.php");
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_TRACKING_MODULE);
// cookie file for cURL
$cookie_name = "opcookie.txt";
$tracking_number = $_GET['tracking_id'];
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"; // dummy UA
$opek_id = "opek"; // Set your DHL ID
$opek_user_password = "opek"; // Set your DHL password
// Note: the tidying code below has been done on language=de only. Haven't tested tidying code on en page
$initial_loginurl = "http://opek.top100.net.pl/";
// Login
$ch= curl_init(); // initialise curl
curl_setopt($ch, CURLOPT_URL, 'http://opek.top100.net.pl/Status.aspx');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
// set cookie jar / file
curl_setopt($ch, CURLOPT_COOKIEJAR, DIR_FS_CATALOG . 'tmp/' . $cookie_name);
curl_setopt($ch, CURLOPT_COOKIEFILE, DIR_FS_CATALOG . 'tmp/' . $cookie_name);
curl_setopt($ch, CURLOPT_REFERER, $initial_loginurl);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserName=" . $opek_id . "&Password=" . $opek_user_password );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
if ($error = curl_errno($ch)) {
if ($error == 7) {
die(TRACKING_CURL_SERVER_ERROR);
}
if ($error == 6) {
die(TRACKING_CURL_NO_ACTIVE_INTERNET);
}
}
// Logged in. Post tracking ID & params and see where we get sent:
curl_setopt($ch, CURLOPT_URL, 'http://opek.top100.net.pl/Status.aspx');
curl_setopt($ch, CURLOPT_HEADER, 1); // we need headers returned so we can extact 302 "location"
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEJAR, DIR_FS_CATALOG . 'tmp/' . $cookie_name);
curl_setopt($ch, CURLOPT_COOKIEFILE, DIR_FS_CATALOG . 'tmp/' . $cookie_name);
curl_setopt($ch, CURLOPT_REFERER, $initial_loginurl);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'TextBoxNrListu=' . $tracking_number);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if ($error = curl_errno($ch)) {
if ($error == 7) {
die(TRACKING_CURL_SERVER_ERROR);
}
if ($error == 6) {
die(TRACKING_CURL_NO_ACTIVE_INTERNET);
}
}
/*
we cannot rely on CURLOPT_FOLLOWLOCATION on shared servers (having openbase_dir / safe_mode enabled) because
since PHP 4.4.4 / PHP 5.2.0 this option is disabled
dl use a single 302 temporary redirect - get the url
*/
list($header, $data) = explode("\n\n", $data, 2);
preg_match('/Location:(.*?)\n/', $header, $matches);
$nurl = trim(str_replace("Location:", "", $matches[0]));
// now have redirected url
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLHEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, DIR_FS_CATALOG . 'tmp/' . $cookie_name);
curl_setopt($ch, CURLOPT_URL, $nurl);
curl_setopt($ch, CURLOPT_REFERER, $initial_loginurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$grab_data = curl_exec($ch);
curl_close ($ch);
// tidy extraneous whitespace - use on all grabs
$grab_data = str_replace("\n", "", $grab_data);
$grab_data = str_replace("\r", "", $grab_data);
$grab_data = str_replace("\t", "", $grab_data);
$grab_data = str_replace(" ", "", $grab_data);
$pat[0] = "/^\s+/";
$pat[1] = "/\s{2,}/";
$pat[2] = "/\s+\$/";
$rep[0] = "";
$rep[1] = " ";
$rep[2] = "";
$grab_data = preg_replace($pat, $rep, $grab_data);
// set html start and end grab
$StartGrab = '<table border="0" cellpadding="3" cellspacing="0" style="width: 720px;" >';
$EndGrab = '</table>';
// Grab delivery status information
$text = eregi("$StartGrab(.*)$EndGrab", $grab_data, $content);
// start custom tidying
// strip tags - keep tracking tables but tidy afterwards
$content = strip_tags($content[1], '<table><tr><th></th><td></td></tr></table>');
// remove all html attributes
function strip_attributes($msg, $tag, $attr) {
$lengthfirst = 0;
while (strstr(substr($msg, $lengthfirst), "<$tag ") != "") {
$imgstart = $lengthfirst + strpos(substr($msg, $lengthfirst), "<$tag ");
$partafterwith = substr($msg, $imgstart);
$img = substr($partafterwith, 0, strpos($partafterwith, ">")+1);
$img = str_replace(" =", "=", $msg);
$out = "<$tag";
for($i = 0; $i <= (count($attr) - 1 );
$i++) {
$long_val = strpos($img, " ", strpos($img, $attr[$i]."=")) - (strpos($img, $attr[$i]."=") + strlen($attr[$i]) + 1) ;
$val = substr($img, strpos($img, $attr[$i]."=") + strlen($attr[$i]) + 1, $long_val);
if (strlen($val) > 0) $attr[$i] = " ".$attr[$i]."=".$val;
else $attr[$i] = "";
$out .= $attr[$i];
}
$out .= ">";
$partafter = substr($partafterwith, strpos($partafterwith, ">")+1);
$msg = substr($msg, 0, $imgstart).$out.$partafter;
$lengthfirst = $imgstart+3;
}
return $msg;
}
$content = strip_attributes($content, "TR", array());
$content = strip_attributes($content, "tr", array());
$content = strip_attributes($content, "TD", array());
$content = strip_attributes($content, "td", array());
$content = strip_attributes($content, "table", array());
// strip empty cells , rows and tables:
$content = preg_replace('/<td>\s*<\/td>/i','', $content); // cells
$content = preg_replace('/<tr>\s*<\/tr>/i','', $content); // rows
$content = preg_replace('/<table>\s*<\/table>/i','', $content); // rows
// size table:
$content = str_replace('<table>', '<table style="font-size: 11px">' , $content);
// the following functions will prevent 'UTF garbled' returned data. We try to use iconv (may be missing on Win32) or mb_convert_encoding (may not be compiled in to PHP)
if(function_exists(mb_convert_encoding)){
echo mb_convert_encoding($content, "ISO-8859-1", "UTF-8");
} elseif(function_exists(iconv)){
echo iconv("UTF-8", "ISO-8859-1", $content);
} else {
echo $content;
}
?>
--------------------------------------
& not working. I see info from const: INVALID_TK_ID_OP (the XX = OP in my contributions)
Can somebody help me?
--
MG