如何检查Joomla是否处于脱机状态

时间:2017-12-01 07:06:08

标签: php html joomla3.0

我试过在网站上搜索,但找不到答案。

我想要一个Joomla网站,该网站目前处于脱机状态(并且正在开发),在10秒后通过将以下代码放在离线页面的标题中,重定向到位于文件夹legacy中的旧网站。

<meta http-equiv="refresh" content="10; url=/legacy/" />

我需要的是if条件,以便在网站显示离线页面时放置该代码,但管理员尚未登录前端。

伪代码中的示例:

if (offline page is displayed because no privileges to view site)  
    echo '<meta http-equiv="refresh" content="10; url=/legacy/" />';

我需要知道if条件中的内容。

1 个答案:

答案 0 :(得分:0)

您可以使用curl发出请求。

如果您还正确处理了http-status-codes,我们会收到403(因为它“禁止”进入该页面)或类似的代码。

源代码看起来与此类似:

// init curl connection
$ch = curl_init('http://www.example.com/');

// execute the curl request
curl_exec($ch);

if (!curl_errno($ch)) {
  // switch by http status code
  if(url_getinfo($ch, CURLINFO_HTTP_CODE) === $desiredHttpCode){

    // Your code 

  }
}
// close the curl connection
curl_close($ch);
相关问题