apache - PHP echo $config inside array -


alright i've got config file looks this:

<?php # epicmc cms config file   return array(     'sitename' => 'epicmc',     'color' => '00aa00',     'url' => 'stats.epicmc.us',     'protocol' => 'https://', ); 

and here's webpage.

<head>        <link rel="icon"            type="image/png"            href="avatar/<?php                                   $statsjson = file_get_contents($configs['url']/api.php?task=stats&player='.$_get['player'].'');               $stats = json_decode($statsjson);               if(empty($stats)){               echo $_get['player'];               echo '/16';               } else {                            echo strtoupper($stats->skin);                             echo '/16';              }              ?>">        <link rel="apple-touch-icon"            type="image/png"            href="avatar/<?php                                   if(empty($stats)){              echo $_get['player'];              echo '/250';              } else {                           echo strtoupper($stats->skin);                            echo '/250';              }              ?>">        <title><?php echo "$configs['sitename']' - "; if(empty($_get['player'])){ echo "stats";} else { echo strtoupper($_get['player']); }?></title>        <meta name="apple-mobile-web-app-title" content="<?php echo ""; if(empty($_get['player'])){ echo "stats";} else { echo strtoupper($_get['player']); }?>">        <meta name=viewport content="width=device-width, user-scalable=no">        <meta name="description" content="view <?php echo $_get['player'];?>'s <?php echo $configs['sitename']?> stats!">        <style>#profile::before{display:block;height:144px;border-radius:0;background:#0a0;-webkit-box-shadow:0 4px 0 rgba(0,0,0,.02);box-shadow:0 4px 0 rgba(0,0,0,.02);content:''}#profile{background:#fafafa;box-shadow:rgba(0,0,0,.14902) 0 1px 1px 0,rgba(0,0,0,.09804) 0 1px 2px 0;padding-bottom:38px;text-align:center;max-width:80%}#profile>img{position:relative;top:-52px;display:block;margin:auto;width:96px;height:96px;border:4px solid #fff;border-radius:0;-webkit-box-shadow:0 4px 0 rgba(0,0,0,.02);box-shadow:0 4px 0 rgba(0,0,0,.02)}#profile h2,#profile h3{font-weight:400;color:#77767e;margin-bottom:30px}#profile h2{margin-top:-30px;padding:0 16px 38px;font-size:21px}#profile h3{margin-top:-60px;padding:0 38px 16px;font-size:11px}#profile h4{font-weight:400}#locked{margin-bottom:-80px}table,td,th{border:1px solid #000;border-collapse:collapse;width:80%}td,th{padding:5px;text-align:left}</style>     </head>     <body>        <?php include("layout/header.php"); ?>        <br>        <br>        <center>           <aside id="profile">              <?php                 function mcus_timeagostring($dateinterval) {                 $daysago = $dateinterval->days;                 //echo $difference;                 if ($daysago == 0){                 if ($dateinterval->h == 0){                   $diffstr = $dateinterval->i . " minutes ago";                 } else {                    $diffstr = $dateinterval->h . " hours ago";                 }                 } else {                 if($daysago === 1) {                   $diffstr = "1 day ago";                 } else if($daysago === 7) {                   $diffstr = "1 week ago";                 } else if($daysago === 14) {                   $diffstr = "2 weeks ago";                 } else {                   $diffstr = "$daysago days ago";                 }                 }                 return $diffstr;                 }                        $get_player = $_get['player'];                        $infojson = file_get_contents('$url/api.php?task=info&player='.$_get['player'].'');                       $info = json_decode($infojson);                       $statsjson = file_get_contents('$url/api.php?task=stats&player='.$_get['player'].'');                      $stats = json_decode($statsjson);                       // $now = time(); // or date well`enter code here`                 ?>              <img src="avatar/<?php                                      if(empty($stats)){                 echo $_get['player'];                 echo '/96';                 } else {                              echo strtoupper($stats->skin);                               echo '/96';                 }                 ?>">              <?php                  echo '<style>';                 echo '#verified {';                 echo 'fill:';                 echo '#';                     if(empty($info->theme)){                 echo "$color";                  } else {                 echo substr($info->theme, 0, 50);                  }                 echo '}';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '.toggle {';                 echo 'background-color:';                 echo '#';                     if(empty($info->theme)){                 echo "$color";                  } else {                 echo substr($info->theme, 0, 50);                  }                 echo '}';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '#profile::before {';                 echo 'background:';                 echo '#';                     if(empty($info->theme)){                 echo "$color";                  } else {                 echo substr($info->theme, 0, 50);                  }                 echo ' !important }';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '#profile::before {';                 echo 'background-image:';                 echo 'url(';                 echo substr($info->cover, 0, 50);                  echo ' ) !important;';                 echo '</style>';                 ?>              <h2>                 <?php                    if($info->locked == 1){                              echo '<div id="locked"><h5>this username locked.</h5></div>';                        }else {                        echo strip_tags($_get['player']);                        }                        ?>                 <?php                    if(substr($info->verified,0,2) == 1) {                          echo '<?xml version="1.0" encoding="utf-8"?><!doctype svg public "-//w3c//dtd svg 1.1//en" "http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd">                 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="verified" width="24" height="24" viewbox="0 0 24 24">                    <path d="m10,17l5,12l6.41,10.58l10,14.17l17.59,6.58l19,8m19,3h5c3.89,3 3,3.89 3,5v19a2,2 0 0,0 5,21h19a2,2 0 0,0 21,19v5c21,3.89 20.1,3 19,3z" />                 </svg>                 '                 ;                 }                 //print_r ($stats);                 if(substr($info->locked,0,2) == 0) {                 echo '                 <h3>                 ';                 echo 'logged in ';                 if(empty($info)){                 echo "not registered";                 } else {                  //echo substr($playeraccountinfo->lastlogin,0,50);                  $dtnow = new datetime('now');                        $dtlastlogin = new datetime($info->lastlogin);                 $dilastlogintonow = $dtnow->diff($dtlastlogin);                 echo mcus_timeagostring($dilastlogintonow);                 }                 echo '';                 ;                 }                 ?>              </h2>              <center>                 <table>                    <tr>                       <th>kills</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->kills, 0, 50); ?></td>                    </tr>                    <tr>                       <th>deaths</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->deaths, 0, 50); ?></td>                    </tr>                    <tr>                       <th>ratio</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->ratio, 0, 50); ?></td>                    </tr>                 </table>                 <br>                 <table>                    <tr>                       <th>joins</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->joins, 0, 50); ?></td>                    </tr>                    <tr>                       <th>quits</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->quits, 0, 50); ?></td>                    </tr>                    <tr>                       <th>kicked</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->kicked, 0, 50); ?></td>                    </tr>                 </table>                 <br>                     <table>                    <tr>                       <th>places</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->places, 0, 50); ?></td>                    </tr>                    <tr>                       <th>breaks</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->breaks, 0, 50); ?></td>                    </tr>                    <tr>                       <th>chats</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->chats, 0, 50); ?></td>                    </tr>                 </table>                 </div>              </center>              <br>        </center>        </aside>        </center>        <center>           <form class="search" action ="stats.php" method="get"><input type="text" name="player" autocomplete="off" placeholder="player name"><br><input type="submit" value="search stats"></form>        </center>        <br>        <br>        <?php include("layout/footer.php"); ?>     </body>     </html> 

it let's me echo them in header.php included config using

 <?php $configs = include('config.php'); ?> 

and in header.php let me echo things sitename using:

 <?php echo $configs['sitename']?> 

, webpage isn't working. keep in mind header.php included (which has config.php included in it). i'm php newbie, , i'm pretty sure echoed them wrong or something. i'm trying $sitename, $url, , $color dynamic.

a working version:

<?php $configs = include('config.php'); if($_get['player'] === 0) header("location: http://" + $configs['url']);  ?> <head>        <link rel="icon"            type="image/png"            href="face.php?u=<?php                                   $statsjson = file_get_contents('http://'.$configs['url'].'/api.php?task=stats&player='.$_get['player']);               $stats = json_decode($statsjson);               if(empty($stats)){               echo $_get['player'];               echo '&s=16';               } else {                            echo strtoupper($stats->skin);                             echo '&s=16';              }              ?>">        <link rel="apple-touch-icon"            type="image/png"            href="face.php?u=<?php                                   if(empty($stats)){              echo $_get['player'];              echo '&s=250';              } else {                           echo strtoupper($stats->skin);                            echo '&s=250';              }              ?>">        <title><?php echo $configs['sitename'] . " - "; if(empty($_get['player'])){ echo "stats";} else { echo strtoupper($_get['player']); }?></title>        <meta name="apple-mobile-web-app-title" content="<?php echo ""; if(empty($_get['player'])){ echo "stats";} else { echo strtoupper($_get['player']); }?>">        <meta name=viewport content="width=device-width, user-scalable=no">        <meta name="description" content="view <?php echo $_get['player'];?>'s <?php echo $configs['sitename']?> stats!">        <style>#profile::before{display:block;height:144px;border-radius:0;background:#0a0;-webkit-box-shadow:0 4px 0 rgba(0,0,0,.02);box-shadow:0 4px 0 rgba(0,0,0,.02);content:''}#profile{background:#fafafa;box-shadow:rgba(0,0,0,.14902) 0 1px 1px 0,rgba(0,0,0,.09804) 0 1px 2px 0;padding-bottom:38px;text-align:center;max-width:80%}#profile>img{position:relative;top:-52px;display:block;margin:auto;width:96px;height:96px;border:4px solid #fff;border-radius:0;-webkit-box-shadow:0 4px 0 rgba(0,0,0,.02);box-shadow:0 4px 0 rgba(0,0,0,.02)}#profile h2,#profile h3{font-weight:400;color:#77767e;margin-bottom:30px}#profile h2{margin-top:-30px;padding:0 16px 38px;font-size:21px}#profile h3{margin-top:-60px;padding:0 38px 16px;font-size:11px}#profile h4{font-weight:400}#locked{margin-bottom:-80px}table,td,th{border:1px solid #000;border-collapse:collapse;width:80%}td,th{padding:5px;text-align:left}</style>     </head>     <body>        <?php include("layout/header.php"); ?>        <br>        <br>        <center>           <aside id="profile">              <?php                 function mcus_timeagostring($dateinterval) {                 $daysago = $dateinterval->days;                 //echo $difference;                 if ($daysago == 0){                 if ($dateinterval->h == 0){                   $diffstr = $dateinterval->i . " minutes ago";                 } else {                    $diffstr = $dateinterval->h . " hours ago";                 }                 } else {                 if($daysago === 1) {                   $diffstr = "1 day ago";                 } else if($daysago === 7) {                   $diffstr = "1 week ago";                 } else if($daysago === 14) {                   $diffstr = "2 weeks ago";                 } else {                   $diffstr = "$daysago days ago";                 }                 }                 return $diffstr;                 }                        $get_player = $_get['player'];                       $infojson = file_get_contents('http://'.$configs['url'].'/api.php?task=info&player='.$_get['player']);                       $info = json_decode($infojson);                       $statsjson = file_get_contents('http://'.$configs['url'].'/api.php?task=stats&player='.$_get['player']);                      $stats = json_decode($statsjson);                       // $now = time(); // or date well`enter code here`                 ?>              <img src="face.php?u=<?php                                      if(empty($stats)){                 echo $_get['player'];                 echo '&s=96';                 } else {                              echo strtoupper($stats->skin);                               echo '&s=96';                 }                 ?>">              <?php                  echo '<style>';                 echo '#verified {';                 echo 'fill:';                 echo '#';                     if(empty($info->theme)){                 echo $configs['color'] . ";";                 } else {                 echo substr($info->theme, 0, 50);                  }                 echo '}';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '.toggle {';                 echo 'background-color:';                 echo '#';                     if(empty($info->theme)){                 echo $configs['color'] . ";";                  } else {                 echo substr($info->theme, 0, 50);                  }                 echo '}';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '#profile::before {';                 echo 'background:';                 echo '#';                     if(empty($info->theme)){                 echo $configs['color'] . ";";                  } else {                 echo substr($info->theme, 0, 50);                  }                 echo ' !important }';                 echo '</style>';                 ?>              <?php                  echo '<style>';                 echo '#profile::before {';                 echo 'background-image:';                 echo 'url(';                 echo substr($info->cover, 0, 50);                  echo ' ) !important;';                 echo '</style>';                 ?>              <h2>                 <?php                    if($info->locked == 1){                              echo '<div id="locked"><h5>this username locked.</h5></div>';                        }else {                        echo strip_tags($_get['player']);                        }                        ?>                 <?php                    if(substr($info->verified,0,2) == 1) {                          echo '<?xml version="1.0" encoding="utf-8"?><!doctype svg public "-//w3c//dtd svg 1.1//en" "http://www.w3.org/graphics/svg/1.1/dtd/svg11.dtd">                 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="verified" width="24" height="24" viewbox="0 0 24 24">                    <path d="m10,17l5,12l6.41,10.58l10,14.17l17.59,6.58l19,8m19,3h5c3.89,3 3,3.89 3,5v19a2,2 0 0,0 5,21h19a2,2 0 0,0 21,19v5c21,3.89 20.1,3 19,3z" />                 </svg>                 '                 ;                 }                 //print_r ($stats);                 if(substr($info->locked,0,2) == 0) {                 echo '                 <h3>                 ';                 echo 'logged in ';                 if(empty($info)){                 echo "not registered";                 } else {                  //echo substr($playeraccountinfo->lastlogin,0,50);                  $dtnow = new datetime('now');                        $dtlastlogin = new datetime($info->lastlogin);                 $dilastlogintonow = $dtnow->diff($dtlastlogin);                 echo mcus_timeagostring($dilastlogintonow);                 }                 echo '';                 ;                 }                 ?>              </h2>              <center>                 <table>                    <tr>                       <th>kills</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->kills, 0, 50); ?></td>                    </tr>                    <tr>                       <th>deaths</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->deaths, 0, 50); ?></td>                    </tr>                    <tr>                       <th>ratio</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->ratio, 0, 50); ?></td>                    </tr>                 </table>                 <br>                 <table>                    <tr>                       <th>joins</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->joins, 0, 50); ?></td>                    </tr>                    <tr>                       <th>quits</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->quits, 0, 50); ?></td>                    </tr>                    <tr>                       <th>kicked</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->kicked, 0, 50); ?></td>                    </tr>                 </table>                 <br>                     <table>                    <tr>                       <th>places</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->places, 0, 50); ?></td>                    </tr>                    <tr>                       <th>breaks</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->breaks, 0, 50); ?></td>                    </tr>                    <tr>                       <th>chats</th>                       <td><?php echo empty($stats) ? "--" : substr($stats->chats, 0, 50); ?></td>                    </tr>                 </table>                 </div>              </center>              <br>        </center>        </aside>        </center>        <center>           <form class="search" action ="stats.php" method="get"><input type="text" name="player" autocomplete="off" placeholder="player name"><br><input type="submit" value="search stats"></form>        </center>        <br>        <br>        <?php include("layout/footer.php"); ?>     </body>     </html> 

you need use curly braces around array when using quoted (or concatenate it).

http://sandbox.onlinephpfunctions.com/code/28fb84721d5c91b0c48279163c967489923f150b

so

echo "$configs['sitename']' - "; 

should be

echo "{$configs['sitename']}' - "; 

or be

echo $configs['sitename'] . "' - "; 

documentation (for curly (complex) usage): http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

a separate issue earlier in code is

$statsjson = file_get_contents($configs['url']/api.php?task=stats&player='.$_get['player'].''); 

you need concatenate arrays value query string

$statsjson = file_get_contents($configs['url'] . '/api.php?task=stats&player='.$_get['player']); 

you should turn on error reporting errors script running into.

how useful error messages in php?

to enable , display errors add

error_reporting(-1); // enable errors ini_set('display_errors', 1); ini_set('display_startup_errors', 1); 

don't on production machine though, don't want users encountering errors.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -