...

View Full Version : $tring inside HTML inside PHP



ArcticFox
02-22-2007, 10:27 AM
I've a php page that I want to add a $tring to an HTML link:



<a href="http://maps.google.com/?ie=UTF8&hl=en&q=$countryName2 ">$countryName2</a>


When I do that, though, I get an error:



Parse error: syntax error, unexpected T_STRING in /sites/basestationzero.com/htdocs/php/logging.php on line 81

Can someone school me on the way to do this correctly? :)



Entire page:


<?php
$server = 'localhost'; // MySQL hostname
$username = 'username'; // MySQL username
$password = 'password'; // MySQL password
$dbname = 'db name'; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName) = mysql_fetch_row(mysql_query($sql));



$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['HTTP_X_FORWARDED_FOR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName2) = mysql_fetch_row(mysql_query($sql));






$ti = date("l, F jS Y - g:ia");
$sn = getenv("SCRIPT_NAME");
$ip = getenv("REMOTE_ADDR");
$pr = getenv("HTTP_X_FORWARDED_FOR");
$ac = getenv("HTTP_ACCEPT");
$la = getenv("HTTP_ACCEPT_LANGUAGE");
$re = getenv("HTTP_REFERER");
$br = getenv("HTTP_USER_AGENT");
$se = getenv("SERVER_NAME");

$so = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$so = $_SERVER['HTTP_X_FORWARDED_FOR'];}
else
if (isset($_SERVER['HTTP_VIA'])) {$so = $_SERVER['HTTP_VIA'];}



$fp = fopen("./logs.php", "a+");

if (strstr($_SERVER["REMOTE_ADDR"], "127.0.0.0x")) {
fputs($fp, "
<font style=color:#00cc00;font-size:14px;font-weight:bold;>AF - $sn</font><br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}

else {
fputs($fp, "
<font style=color:#0099ff;font-size:14px;font-weight:bold;>$sn</font><br />
<b>Time:</b> $ti<br />
<b>IP Address:</b> $ip - <a href="http://maps.google.com/?ie=UTF8&hl=en&q= $countryName ">$countryName</a><br />
<b>Proxy:</b> <u>$pr</u> - <a href="http://maps.google.com/?ie=UTF8&hl=en&q= $countryName2 ">$countryName2</a><br />
<b>HTTP Accept:</b> $ac<br />
<b>Languages:</b> $la<br />
<b>Referer URL:</b> <a target=_blank href=$re>$re</a><br/>
<b>Browser Type:</b> $br<br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}



if (strstr($_SERVER["HTTP_REFERER"], "codingforums")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "dynamicdrive")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "sitepoint")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}

if (strstr($_SERVER["REMOTE_ADDR"], "82.172.242.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.103.132.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "69.234.44.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "204.246.129.196")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "216.70.173.10")) {header("location: http://www.parnasse.com/trap.html");}

if (strstr($_SERVER["HTTP_USER_AGENT"], "Java")) {header("location: http://www.parnasse.com/trap.html");}

?>

ArcticFox
02-22-2007, 10:34 AM
Nevermind, I found the problem - remove the quotes:



<a href="http://maps.google.com/?ie=UTF8&hl=en&q= $countryName ">



Now I have a new problem. When the $CountryName is one from the United States, the link shows up as http://maps.google.com/?ie=UTF8&hl=en&q=United instead of http://maps.google.com/?ie=UTF8&hl=en&q=United States.

Is there a way I can remove spaces from within the $CountryName content. Like turning United States into UnitedStates - google would like that better. :)

StupidRalph
02-22-2007, 10:41 AM
Yes....

Or you could be even more correct and simply escape the quotes.



<?php
$server = 'localhost'; // MySQL hostname
$username = 'username'; // MySQL username
$password = 'password'; // MySQL password
$dbname = 'db name'; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName) = mysql_fetch_row(mysql_query($sql));



$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['HTTP_X_FORWARDED_FOR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';

list($countryName2) = mysql_fetch_row(mysql_query($sql));






$ti = date("l, F jS Y - g:ia");
$sn = getenv("SCRIPT_NAME");
$ip = getenv("REMOTE_ADDR");
$pr = getenv("HTTP_X_FORWARDED_FOR");
$ac = getenv("HTTP_ACCEPT");
$la = getenv("HTTP_ACCEPT_LANGUAGE");
$re = getenv("HTTP_REFERER");
$br = getenv("HTTP_USER_AGENT");
$se = getenv("SERVER_NAME");

$so = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$so = $_SERVER['HTTP_X_FORWARDED_FOR'];}
else
if (isset($_SERVER['HTTP_VIA'])) {$so = $_SERVER['HTTP_VIA'];}



$fp = fopen("./logs.php", "a+");

if (strstr($_SERVER["REMOTE_ADDR"], "127.0.0.0x")) {
fputs($fp, "
<font style=color:#00cc00;font-size:14px;font-weight:bold;>AF - $sn</font><br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}

else {
fputs($fp, "
<font style=color:#0099ff;font-size:14px;font-weight:bold;>$sn</font><br />
<b>Time:</b> $ti<br />
<b>IP Address:</b> $ip - <a href=\"http://maps.google.com/?ie=UTF8&hl=en&q= $countryName \">$countryName</a><br />
<b>Proxy:</b> <u>$pr</u> - <a href=\"http://maps.google.com/?ie=UTF8&hl=en&q= $countryName2 \">$countryName2</a><br />
<b>HTTP Accept:</b> $ac<br />
<b>Languages:</b> $la<br />
<b>Referer URL:</b> <a target=_blank href=$re>$re</a><br/>
<b>Browser Type:</b> $br<br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}



if (strstr($_SERVER["HTTP_REFERER"], "codingforums")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "dynamicdrive")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "sitepoint")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}

if (strstr($_SERVER["REMOTE_ADDR"], "82.172.242.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.103.132.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "69.234.44.")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "204.246.129.196")) {header("location: http://www.parnasse.com/trap.html");}
if (strstr($_SERVER["REMOTE_ADDR"], "216.70.173.10")) {header("location: http://www.parnasse.com/trap.html");}

if (strstr($_SERVER["HTTP_USER_AGENT"], "Java")) {header("location: http://www.parnasse.com/trap.html");}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum