CSS 背景未显示


CSS background is not showing

我有 2 个脚本,第二个脚本链接到第一个脚本,所以请同时查看这两个脚本。我的第一个脚本:主题.php

<?php
function ceklogin(){
    session_start();
    if ($_SESSION['loggedin'] != 1) {
        header("Location: login.php");
        exit;
    }}
function bgchange(){
        $bg = array('images/angel-beats-bg1.jpg', 'images/angel-beats-bg2.jpg', 'images/angel-beats-bg3.jpg'); // array of filenames
        $i = rand(0, count($bg)-1); // generate random number size of the array
        $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
        return $selectedBg;
                    } 
$bgUrl = bgchange(); 
function css(){
echo '
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" type="image/png" href="favicon.png">
<title>OpenWrt Angel Beats! Edition</title>
<style type="text/css">
body {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-image: url('.$bgUrl.');
    background-repeat: no-repeat;
    margin: auto;
    width: auto;
    height: auto;
    display: table;
    text-align:center;
}
.TextBox {
    -moz-border-radius:30px;
    -webkit-border-radius:30px;
    border-radius:30px;
    border: #solid 10px #000;
    background-color: rgba(255,255,255,0.5);
    width:auto;
    height:auto;
    margin-left: auto ;
    margin-right: auto ;
    display: inline-block
}
.TextBox:after {
    content:"'a '00a0 ";
}
.TextBox:before {
    content:"'a '00a0 ";
}
</style>
<body>
<img src="images/header.png" alt="OpenWrt Gratisan"><br>
<strong> 
<p>
<a href="status.php" title=""><font color="red">Status</font></a> | 
<a href="wget.php" title=""><font color="red">Wget WebUI</font></a> | 
<a href="terminal.php" title=""><font color="red">Terminal</font></a> | 
<a href="wifi.php" title=""><font color="red">WIFI</font></a> | 
<a href="ch_pass.php" title=""><font color="red">Password</font></a> | 
<a href="profile.php" title=""><font color="red">Profile</font></a> | 
<a href="vpn.php" title=""><font color="red">Accounts</font></a> | 
<a href="ussd.php" title=""><font color="red">USSD</font></a> | 
<a href="sms_in.php" title=""><font color="red">Inbox SMS</font></a> | 
<a href="sms_send.php" title=""><font color="red">Send SMS</font></a> | 
</p>
<p>
<a href="vpn_log.php" title=""><font color="red">VPN log</font></a> | 
<a href="restart_log.php" title=""><font color="red">Restart Log</font></a> | 
<a href="wget_log.php" title=""><font color="red">Wget Log</font></a> | 
<a href="dial_log.php" title=""><font color="red">Dial Log</font></a> | 
<a href="about.php" title=""><font color="red">About</font></a>
</p>
</font></strong>
<br><br><br>
<div class="TextBox">';
}
function foot() {
echo '<br><br><br><strong>Copyright</strong>';
}
?>

这个theme.php就像其他页面的css一样,这是真正的网页:状态.php

<?php
include 'theme.php';
ceklogin();
    $event=0;
    $st=0;
if($_POST['start']){
    $pf=$_POST['profile'];
    exec('profile start '.$pf.' > /dev/null 2>&1 &');
   $list="Profile Started .. OK";
    $event=1;    
    $st=2;
    header( "refresh:1;url=status.php" );
}
if($_POST['stop']){
    exec('killall restart-internet.sh');
    exec('profile stop');
    $list="Profile Stoped .. OK";
    $event=1;
    $st=2;    
    header( "refresh:1;url=status.php" );
}
if($_POST['restart']){
    exec('profile start > /dev/null 2>&1 &');
    $event=1;    
    $st=2;
    $list="Profile restarted .. OK";
    header( "refresh:1;url=status.php" );
}
if($_POST['info']){
    $pf=$_POST['profile'];
    $st=3;
}
if($_POST['reg']){
    $param=$_POST['network'];
    exec('gsm set network '.$param);
    sleep(3);
    $st=1;
}

css();
if ( $event == 1 )
{
echo $list;
echo '
    <br>
    Harap Menunggu.... 
    <br>
    </div>';
foot();
echo '
</div>
</body>
</html>';
exit;
}
if ( $event == 0 )
{
exec('cat /tmp/prf',$o);
if ( $o[0] == 'started' ) {
echo "<form action='"".$PHP_SELF."'" method='"post'">";
echo '
<input type="submit" name="refresh" value="Refresh Status" />
<input type="submit" name="restart" value="Restart Profile" />
<input type="submit" name="stop" value="Stop Profile" />
</form>';
}
else
{
exec('ls /root/profiles',$list);
echo "<form action='"".$PHP_SELF."'" method='"post'">";
echo '
profile :
<select name="profile">';
$x=0;
while($x<count($list))
  {
   echo "
   <option value='"$list[$x]'">$list[$x]</option>";
   $x++;
  }
echo '
</select>
<input type="submit" name="start" value="Start Profile" />
<input type="submit" name="info" value="Info Profile" />
</form>';
}
echo "<br>";
if($_POST['all-status']){
$st=1;
}
if($_POST['edge-only']){
$st=1;
exec('gsm jump edge',$ot);
exec('uci set network.3g.service=gprs_only',$ot);
sleep(10);
}
if($_POST['tigag-only']){
$st=1;
exec('gsm jump 3g',$ot);
exec('uci set network.3g.service=umts_only',$ot);
sleep(10);
}

if ( $st == 3 ){
   exec('profile info '.$pf,$out);
   $st=0;
}else{
if ( $st == 1){ 
exec('gsm status',$out);
}else{
$st=0;
exec('profile status-koneksi',$out);
}}
if ($st <> 2){
echo '
<div align="center" >
<div style="left:10px;width:380px;height:212px;border:1px solid #000;text-align:center;">';
}
$arrlength=count($out);
for($x=0;$x<$arrlength;$x++)
  {
  echo $out[$x]. "<br>";
  }
}
if ($st <> 2){
echo '</div></div>';
}
if ($st == 0){
echo "<br><form action='"".$PHP_SELF."'" method='"post'">";
echo '
<input type="submit" name="all-status" value="Status Modem" />
</form>';
}else{
if ($st == 1){
echo "<br><form action='"".$PHP_SELF."'" method='"post'">";
echo '
<input type="submit" name="edge-only" value="Edge Only" />
<input type="submit" name="tigag-only" value="3G Only" />
Network:
<select name="network">
<option value='"auto'">Auto</option>'"
<option value='"51001'">Indosat</option>'"
<option value='"51011'">XL</option>'"
<option value='"51089'">3</option>'"
<option value='"51010'">Telkomsel</option>'"
</select>
<input type="submit" name="reg" value="Register" />
</form>';
}}
echo '
</div>';
foot();
echo '
</body>
</html>';
?>

当我运行status.php时,一切看起来都不错,但唯一的问题是背景没有显示,它只显示一个白页和内容本身。背景应该是来自天使节拍图片(每次刷新随机bg)。我的猜测是我在这一部分犯了一个错误:

body {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-image: url('.$bgUrl.');
    background-repeat: no-repeat;
    margin: auto;
    width: auto;
    height: auto;
    display: table;
    text-align:center;
}

但我就是想不通我的错误。如何在status.php中显示背景?我真的很抱歉剧本太长了,我现在真的到了极限。

更新正如一些人建议的那样,我在浏览器中查看了status.php的源代码,得到了这个:

body {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-image: url();
    background-repeat: no-repeat;
    margin: auto;
    width: auto;
    height: auto;
    display: table;
    text-align:center;
}

background-image: url();什么都没显示,救命!

函数 css() 的开头添加global $bgUrl;

在第一段代码中,你有background-image: url('.$bgUrl.');,在第三段代码中,你有background-image: url('.$selectedBg.'); - 是哪一个?

此外,您可能应该将变量传递到函数中,以便您的代码如下所示:

编辑:

function css($bgUrl){
  /* CSS code here*/
  echo $bgUrl;
}

然后,当您调用该函数时,将变量传递给它:

css($bgUrl);