| PHP: RBC (Really Bad Code) Posted by: Jordan in PHP on Oct 15, 2008 |
I decided to make a quick text link addon for OpenX. OpenX is a powerful banner ad rotator that has a multitude of features for advertisement. With OpenX a website (or collection of websites) could zone, host and deliver millions of impressions per day. Needless to say, the project is used by some very large players.
In order to write my addon I needed to see the functions and variables that were at my disposal. I opened the local delivery file and was appalled by this code. I'll paste it below.
I've left all code untouched, including indention. This is from the/www/dlivery/alocal.php and is just a portion of the code but it all generally looks like this.

At first glance I see 5 problems in the code above and there is probably more. What problems do you see?
In order to write my addon I needed to see the functions and variables that were at my disposal. I opened the local delivery file and was appalled by this code. I'll paste it below.
I've left all code untouched, including indention. This is from the

- function MAX_marketplaceNeedsId()
- {
- $aConf = $GLOBALS['_MAX']['CONF'];
- if (MAX_marketplaceEnabled()) {
- $oxidOnly = $aConf['marketplace']['cacheTime'] == 0;
- $viewerId = MAX_cookieGetUniqueViewerId(false, $oxidOnly);
- return !isset($viewerId);
- }
- return false;
- }
- function MAX_marketplaceGetIdWithRedirect($scriptName = null)
- {
- $aConf = $GLOBALS['_MAX']['CONF'];
- if (MAX_marketplaceEnabled()) {
- if (MAX_marketplaceNeedsId() && !isset($_GET['openxid'])) {
- $scriptName = isset($scriptName) ? $scriptName : basename($_SERVER['SCRIPT_NAME']);
- $oxpUrl = MAX_commonGetDeliveryUrl($scriptName).'?'.$_SERVER['QUERY_STRING'].'&openxid=OPENX_ID';
- $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.
- $url .= $aConf['marketplace']['idHost'].'/redir?r='.urlencode($oxpUrl);
- $url .= '&pid=OpenXDemo';
- $url .= '&cb='.mt_rand(0, PHP_INT_MAX);
- header("Location: {$url}");
- exit;
- }
- }
- }
function MAX_marketplaceNeedsId()
{
$aConf = $GLOBALS['_MAX']['CONF'];
if (MAX_marketplaceEnabled()) {
$oxidOnly = $aConf['marketplace']['cacheTime'] == 0;
$viewerId = MAX_cookieGetUniqueViewerId(false, $oxidOnly);
return !isset($viewerId);
}
return false;
}
function MAX_marketplaceGetIdWithRedirect($scriptName = null)
{
$aConf = $GLOBALS['_MAX']['CONF'];
if (MAX_marketplaceEnabled()) {
if (MAX_marketplaceNeedsId() && !isset($_GET['openxid'])) {
$scriptName = isset($scriptName) ? $scriptName : basename($_SERVER['SCRIPT_NAME']);
$oxpUrl = MAX_commonGetDeliveryUrl($scriptName).'?'.$_SERVER['QUERY_STRING'].'&openxid=OPENX_ID';
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.
$url .= $aConf['marketplace']['idHost'].'/redir?r='.urlencode($oxpUrl);
$url .= '&pid=OpenXDemo';
$url .= '&cb='.mt_rand(0, PHP_INT_MAX);
header("Location: {$url}");
exit;
}
}
}
{
$aConf = $GLOBALS['_MAX']['CONF'];
if (MAX_marketplaceEnabled()) {
$oxidOnly = $aConf['marketplace']['cacheTime'] == 0;
$viewerId = MAX_cookieGetUniqueViewerId(false, $oxidOnly);
return !isset($viewerId);
}
return false;
}
function MAX_marketplaceGetIdWithRedirect($scriptName = null)
{
$aConf = $GLOBALS['_MAX']['CONF'];
if (MAX_marketplaceEnabled()) {
if (MAX_marketplaceNeedsId() && !isset($_GET['openxid'])) {
$scriptName = isset($scriptName) ? $scriptName : basename($_SERVER['SCRIPT_NAME']);
$oxpUrl = MAX_commonGetDeliveryUrl($scriptName).'?'.$_SERVER['QUERY_STRING'].'&openxid=OPENX_ID';
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.
$url .= $aConf['marketplace']['idHost'].'/redir?r='.urlencode($oxpUrl);
$url .= '&pid=OpenXDemo';
$url .= '&cb='.mt_rand(0, PHP_INT_MAX);
header("Location: {$url}");
exit;
}
}
}
At first glance I see 5 problems in the code above and there is probably more. What problems do you see?
Set as favorite
Bookmark
Email This
Hits: 271
Trackback(0)
Write comment