Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts

    Angry $tring inside HTML inside PHP

    I've a php page that I want to add a $tring to an HTML link:

    PHP Code:
    <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 Code:
    <?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=50align=left />
    ");
    fclose($fp);}



    if (strstr($_SERVER["
    HTTP_REFERER"], "codingforums"))  {header("locationhttp://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");}
     
    ?>
    <div> - putting your mind in a box since 1997

  • #2
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts
    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.
    Last edited by ArcticFox; 02-22-2007 at 11:38 AM.
    <div> - putting your mind in a box since 1997

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Yes....

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

    PHP Code:
    <?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");} 
      
    ?>
    Last edited by StupidRalph; 02-22-2007 at 11:46 AM.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •