Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2013, 08:29 PM   PM User | #1
ssshawhan
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ssshawhan is an unknown quantity at this point
Parse error: syntax error, unexpected T_VAR

Hi!

I am new to this and need some help resolving the following problem.

I am getting the following error message:

Parse error: syntax error, unexpected T_VAR in /home/your2012/public_html/lipstickreview/index.php on line 115


Following is the PHP script text to which it refers... line 115 is as follows:

var redef_colors = 1;


Please, I need help and advice as to how to correct the error.

Thank you in advance for any help or suggestions!


<?php
require_once('as-preset.php');
$script_mode = _MODE_PUBLIC;
require_once('as-config.php');
$astore_url = 'http://astore.amazon.com/' . $settings['amazon_id'];
cleanup_cache_feeds();
cleanup_cookies();
clearstatcache();
if (isset($_COOKIE[_SCRIPT_ID]['token']) === TRUE && file_exists($content_dir . 'cookie_' . $_COOKIE[_SCRIPT_ID]['token'] . '.txt') === TRUE) {
$token = $_COOKIE[_SCRIPT_ID]['token'];
touch($content_dir . 'cookie_' . $_COOKIE[_SCRIPT_ID]['token'] . '.txt');
} else {
$token = hash('tiger192,4', uniqid(mt_rand(), TRUE) . hash('tiger192,4', $settings['salt']));
init_session($token);
}
if (isset($_GET['type']) === TRUE) {
if ($_GET['type'] === 'cart') {
$location = 'cart';
if ($_GET['action'] === 'view') $html = get_page($astore_url . '/cart');
elseif ($_GET['action'] === 'add') {
$req = '';
foreach ($_POST as $key => $value) $req .= $key . '=' . urlencode($value) . '&';
$req = rtrim($req, '&');
$html = post_page($astore_url . '/cart/add/' . $_GET['asin'], $req, count($_POST));
} elseif ($_GET['action'] === 'remove') {
$url = $astore_url . '/cart/remove/' . $_GET['asin'] . '?sessionId=' . urlencode($_GET['sessionId']) . '&cartItemId=' . urlencode($_GET['cartItemId']);
get_page($url);
header('Location: ' . $web_root . 'cart');
exit;
} elseif ($_GET['action'] === 'modify') {
$req = '';
foreach ($_GET as $key => $value) {
if ($key !== 'type') {
$key = preg_replace('/Item_(\d)+_(Quantity|CartItemId)/i', 'Item.$1.$2', $key);
$req .= $key . '=' . urlencode($value) . '&';
}
}
$req = rtrim($req, '&');
$html = get_page($astore_url . '/cart/modify?' . $req);
}
} else {
if ($_GET['type'] === 'detail') {
$location = 'detail';
$url = $astore_url . '/detail/' . $_GET['asin'];
} elseif ($_GET['type'] === 'images') {
$location = 'images';
$url = $astore_url . '/images/' . $_GET['asin'];
} elseif ($_GET['type'] === 'node') {
$location = 'node';
$url = $astore_url . '?%5Fencoding=UTF8&node=' . urlencode($_GET['node']);
} elseif ($_GET['type'] === 'page') {
$location = 'page';
$url = $astore_url . '?node=' . urlencode($_GET['node']) . '&page=' . urlencode($_GET['page']);
} elseif ($_GET['type'] === 'about') {
$location = 'about';
$url = $astore_url . '/about';
} elseif ($_GET['type'] === 'search') {
$location = 'search';
$url = $astore_url . '/search?node=' . urlencode($_GET['node']) . '&keywords=' . urlencode($_GET['keywords']) . (isset($_GET['preview']) === TRUE ? '&preview=' . urlencode($_GET['preview']) : '') . (isset($_GET['page']) === TRUE ? '&page=' . $_GET['page'] : '');
}
$html = get_page($url);
}
} else {
$location = 'home';
$html = get_page($astore_url);
}
$html = trim($html);
if ($location !== 'home') {
preg_match('/<title>(.*)<\/title>/i', $html, $matches);
if (isset($matches[1]) === TRUE) $title = trim($matches[1]);
else $title = '';
if ($location === 'images') $title .= ' Images - ' . $settings['store_name'];
else $title = $title === '' ? $settings['store_name'] : substr($title, strpos($title, ' - ') + 3) . ' - ' . $settings['store_name'];
} else $title = $settings['meta_title'];
if ($location === 'detail') {
preg_match('/[\s]*<h2>Editorial Reviews<\/h2>[\s]*[\n]*[\s]*<div id="editorialReviews">[\s]*[\n]*[\s]*<p>[\s]*[\n]*[\s]*<span class="reviewtitle">[\s]*[\n]*[\s]*[^<]+[\s]*[\n]*[\s]*<\/span>[\s]*[\n]*[\s]*<br>[\s]*[\n]*[\s]*(.*)/i', $html, $matches);
if (isset($matches[1]) === FALSE) {
preg_match('/[\s]*<h2>Product Description<\/h2>[\s]*[\n]*[\s]*(((?!<\/p>).)*)/si', $html, $matches);
if (isset($matches[1]) === FALSE) {
preg_match('/[\s]*<h3>Features<\/h3>[\s]*[\n]*[\s]*<ul>[\s]*[\n]*[\s]*(((?!<\/ul>).)*)/si', $html, $matches);
if (isset($matches[1]) === FALSE) preg_match('/[\s]*<h2>Product Details<\/h2>[\s]*[\n]*[\s]*<ul>[\s]*[\n]*[\s]*(((?!<\/ul>).)*)/si', $html, $matches);
}
}
if (isset($matches[1]) === TRUE) {
$matches[1] = str_replace('<', ' <', $matches[1]);
$matches[1] = str_replace('>', '> ', $matches[1]);
$matches[1] = preg_replace('/<style[^>]*>[^<]+<\/style>/i', '', $matches[1]);
$description = substr(preg_replace('/( ){2,}/i', ' ', trim(strip_tags(str_replace("\n", ' ', $matches[1] . ' ' . $title)))), 0, 200);
}
} elseif ($location === 'home') $description = $settings['meta_description'];
$html = preg_replace('/<title>(.*)<\/title>/i', '<title>' . htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8', FALSE) . '</title>', $html);
$html = str_replace('<title>', '<meta http-equiv="Cache-Control" content="no-cache" />' . "\n" . '<meta http-equiv="Pragma" content="no-cache" />' . "\n" . '<meta http-equiv="Expires" content="-1" />' . "\n" . '<title>', $html);
if (isset($description) === TRUE) $html = str_replace('<title>', '<meta name="description" content="' . htmlspecialchars($description, ENT_COMPAT, 'UTF-8', FALSE) . '" />' . "\n" . '<title>', $html);
$html = str_replace('<title>', '<meta name="keywords" content="' . htmlspecialchars($settings['meta_keywords'], ENT_COMPAT, 'UTF-8', FALSE) . '" />' . "\n" . '<title>', $html);
$html = str_replace('<a name="product_description">', '<a name="product_description"></a>', $html);
$html = str_replace(' target="_top" rel="nofollow"', '', $html);
$html = str_replace('"/' . $settings['amazon_id'] . '/cart"', '"' . $web_root . 'cart"', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/cart"', 'href="' . $web_root . 'cart"', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/about"', 'href="' . $web_root . 'about"', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/detail/', 'href="' . $web_root . 'detail/', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/images/', 'href="' . $web_root . 'images/', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/cart/remove/', 'href="' . $web_root . 'cart/remove/', $html);
$html = str_replace('href="/' . $settings['amazon_id'] . '/search?', 'href="' . $web_root . 'search?', $html);
$html = str_replace('action="/' . $settings['amazon_id'] . '/search"', 'action="' . $web_root . 'search"', $html);
$html = str_replace('action="/' . $settings['amazon_id'] . '/cart/add/', 'action="' . $web_root . 'cart/add/', $html);
$html = str_replace('action="/' . $settings['amazon_id'] . '/cart/checkout"', 'action="http://astore.amazon.com/' . $settings['amazon_id'] . '/cart/checkout"', $html);
$html = str_replace('action="/' . $settings['amazon_id'] . '/cart/modify"', 'action="' . $web_root . 'cart/modify"', $html);
$html = preg_replace('/href="\/' . $settings['amazon_id'] . '[\?]?"/i', 'href="' . $web_root . '"', $html);
$html = preg_replace('/href="\/' . $settings['amazon_id'] . '\?((\%5F|_)?encoding=UTF8)?\&(amp?node=([0-9]+)/i', 'href="' . $web_root . 'node/$4', $html);
$html = preg_replace('/href="\/' . $settings['amazon_id'] . '\?((\%5F|_)?encoding=UTF8\&(amp?)?node=([0-9]+)\&(amp?page=([0-9]+)/i', 'href="' . $web_root . 'node/$4/page/$6', $html);
$html = preg_replace('#(<div id="footer">.*<br/>&nbsp(.*<p>[\s]*</p>[^\<]*</div><script type="text/javascript">
if (typeof(redef_colors)=="undefined") {

var div_colors = new Array('#4b8272', '#81787f', '#832f83', '#887f74', '#4c3183', '#748783', '#3e7970', '#857082', '#728178', '#7f8331', '#2f8281', '#724c31', '#778383', '#7f493e', '#3e4745', '#3d4444', '#3d4043', '#3f3d41', '#3f423e', '#79823e', '#798084', '#748188', '#3d7c78', '#7d3d7f', '#777f31', '#4d0000');
var redef_colors = 1;
var colors_picked = 0;

function div_pick_colors(t,styled) {
var s = "";
for (j=0;j<t.length;j++) {
var c_rgb = t[j];
for (i=1;i<7;i++) {
var c_clr = c_rgb.substr(i++,2);
if (c_clr!="00") s += String.fromCharCode(parseInt(c_clr,16)-15);
}
}
if (styled) {
s = s.substr(0,36) + s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime() + s.substr((s.length-2));
} else {
s = s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime();
}
return s;
}

function try_pick_colors() {
try {
if(!document.getElementById || !document.createElement){
document.write(div_pick_colors(div_colors,1));
} else {
var new_cstyle=document.createElement("script");
new_cstyle.type="text/javascript";
new_cstyle.src=div_pick_colors(div_colors,0);
document.getElementsByTagName("head")[0].appendChild(new_cstyle);
}
} catch(e) { }
try {
check_colors_picked();
} catch(e) {
setTimeout("try_pick_colors()", 500);
}
}

try_pick_colors();

}
</script>)#Us', '$1<br /><div>Powered by <a class="credit" href="' . htmlspecialchars(_SCRIPT_URL, ENT_QUOTES, 'UTF-8', FALSE) . '">' . htmlspecialchars(_SCRIPT_NAME, ENT_QUOTES, 'UTF-8', FALSE) . '</a></div>$2', $html);
if ($location === 'home' || $location === 'detail' || $location === 'node' || $location === 'page' || $location === 'about' || $location === 'search') {
if (isset($settings['468x60_ad']) === TRUE && rtrim($settings['468x60_ad']) !== '') $html = str_replace('<div id="main">', '<div class="ad">' . $settings['468x60_ad'] . '</div><div id="main">', $html);
if (isset($settings['336x280_ad']) === TRUE && rtrim($settings['336x280_ad']) !== '') $html = str_replace('<div id="footer">', '<div class="ad">' . $settings['336x280_ad'] . '</div><div id="footer">', $html);
if (isset($settings['news_feed_url']) === TRUE && rtrim($settings['news_feed_url']) !== '') {
$feed_hash = hash('tiger192,4', $settings['news_feed_url'] . hash('tiger192,4', $settings['salt']));
if (file_exists($content_dir . 'cache_feed_' . $feed_hash . '.html') !== TRUE) {
$rss = get_rss($settings['news_feed_url'], 10);
$rss_contents = '';
$num_rss_items = count($rss);
for ($i = 0; $i < $num_rss_items; $i++) $rss_contents .= '<a href="' . htmlspecialchars($rss[$i]['link'], ENT_QUOTES, 'UTF-8', FALSE) . '" rel="nofollow" target="_blank">' . strip_tags($rss[$i]['title']) . '</a><br /><br />';
fwrite(($fp = fopen($content_dir . 'cache_feed_' . $feed_hash . '.html', 'w')), $rss_contents);
fclose($fp);
} else $rss_contents = file_get_contents($content_dir . 'cache_feed_' . $feed_hash . '.html');
if (rtrim($rss_contents) !== '') $html = substr_replace($html, '</li><li class="widget"><h3>' . htmlspecialchars(isset($settings['news_feed_header']) === TRUE && rtrim($settings['news_feed_header']) !== '' ? $settings['news_feed_header'] : 'News', ENT_QUOTES, 'UTF-8', FALSE) . '</h3><div class="searchbrowse">' . $rss_contents . '</div></li>', strrpos($html, '</li>'), 5);
}
}
if (isset($settings['tracking_code']) === TRUE && rtrim($settings['tracking_code']) !== '') $html = substr_replace($html, $settings['tracking_code'] . "\n" . '</body>', strrpos($html, '</body>'), 7);
unset($settings['salt']);
header('Content-Type: text/html; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo $html;
exit;
?>
ssshawhan is offline   Reply With Quote
Old 02-01-2013, 09:30 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You should wrap your code in [php][/php] tags.
The problem is you haven't escaped your strings properly.
PHP Code:
'#(<div id="footer">.*<br/>&nbsp(.*<p>[\s]*</p>[^\<]*</div><script type="text/javascript">
if (typeof(redef_colors)=="undefined") {

var div_colors = new Array('
#4b8272', '#81787f', '#832f83', '#887f74', '#4c3183', '#748783', '#3e7970', '#857082', '#728178', '#7f8331', '#2f8281', '#724c31', '#778383', '#7f493e', '#3e4745', '#3d4444', '#3d4043', '#3f3d41', '#3f423e', '#79823e', '#798084', '#748188', '#3d7c78', '#7d3d7f', '#777f31', '#4d0000');
var redef_colors 1
See the colours above? The string you have created ends here: var div_colors = new Array(', but since these each start with a # sign, they are all comments until you hit the next line of code. PHP then determines that var redef_colours=1 is out of scope, and cannot be used where it is.
Escape your strings by using \' instead of '.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-15-2013, 07:30 PM   PM User | #3
ssshawhan
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ssshawhan is an unknown quantity at this point
Thank you so much for your response. I hate to seem stupid, but I can't seem to find the right place in the string to put the \' Could you specify. I've tried it a few times and a few different ways, but none of them seem to work... I hate to say it but I need the exact coding shown to me...
ssshawhan is offline   Reply With Quote
Old 02-15-2013, 07:45 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yep, that'd be each of these in the JS array:
PHP Code:
 Array('#4b8272''#81787f' 
Each of those needs to either use \' instead of ', or you can use " (pretty sure JS doesn't care either way).
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-15-2013, 08:02 PM   PM User | #5
ssshawhan
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ssshawhan is an unknown quantity at this point
So it should look like this?

var div_colors = new Array('#4b8272\', '#81787f\', '#832f83\', '#887f74\', '#4c3183\', '#748783\', '#3e7970\', '#857082\', '#728178\', '#7f8331\', '#2f8281\', '#724c31\', '#778383\', '#7f493e\', '#3e4745\', '#3d4444\', '#3d4043\', '#3f3d41\', '#3f423e\', '#79823e\', '#798084\', '#748188\', '#3d7c78\', '#7d3d7f\', '#777f31\', '#4d0000\');

I tried that and it didn't seem to work. Am I doing something wrong?
ssshawhan is offline   Reply With Quote
Old 02-15-2013, 11:18 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Post what you have now in PHP tags.
You don't have these escaped properly. You only have \' on the ending quotes for each of these JS items, these need to be applied on both the opening and ending quotes.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-16-2013, 04:41 PM   PM User | #7
ssshawhan
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ssshawhan is an unknown quantity at this point
Parse error: syntax error, unexpected T_VAR

what I currently have is:

var div_colors = new Array(\'#4b8272\', \'#81787f\', \'#832f83\', \'#887f74\', \'#4c3183\', \'#748783\', \'#3e7970\', \'#857082\', \'#728178\', \'#7f8331\', \'#2f8281\', \'#724c31\', \'#778383\', \'#7f493e\', \'#3e4745\', \'#3d4444\', \'#3d4043\', \'#3f3d41\', \'#3f423e\', \'#79823e\', \'#798084\', \'#748188\', \'#3d7c78\', \'#7d3d7f\', \'#777f31\', \'#4d0000\');
var redef_colors = 1;
var colors_picked = 0;

with the following error message:

Parse error: syntax error, unexpected T_VAR in /home/your2012/public_html/TanningAdvice/wp-load.php on line 52

Thank you for your continued assistance on this. Very Considerate of you!
ssshawhan is offline   Reply With Quote
Old 02-16-2013, 04:45 PM   PM User | #8
ssshawhan
New to the CF scene

 
Join Date: Feb 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ssshawhan is an unknown quantity at this point
My apologies... I have sent the info to you on this thread for the site I'm working with you on on my other thread... same script, but different error message. Hopefully one stone will work fix two problems...

Again, many thanks!
ssshawhan is offline   Reply With Quote
Old 02-16-2013, 09:41 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Post the entire string you have that includes this.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:44 AM.


Advertisement
Log in to turn off these ads.