下面是我的代码,当我将日期存储在foreach循环的会话变量中并在jquery移动页面中的标题部分打印时它打印日期但是在刷新页面后我第一次运行页面时它无法打印date.how来解决这个问题请帮我。
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<body>
<div data-role="page" id="index" data-theme="c">
<div data-theme="b" data-role="header" data-position="fixed">
<?php
print"<div>";
print"<pre style=text-align:center;>";
echo 'Last Updated On:- '.$_SESSION['causedate'];
print"</pre>";
print" </div>";
?>
</div>
<div data-role="content">
<?php
function curlUsingGet($url, $data)
{
if(empty($url) OR empty($data))
{
return 'Error: invalid Url or Data';
}
$fields_string = '';
foreach($data as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
rtrim($fields_string,'&');
$urlStringData = $url.'?'.$fields_string;
$cookie= "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_COOKIESESSION,true);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,true);
curl_setopt($ch, CURLOPT_URL,$urlStringData);
$return = curl_exec($ch);
$arrel = explode('|',$return);
foreach($arrel as $val)
{
$new_el=explode('~',$val);
echo $new_el[0];
echo $new_el[2];
echo $new_el[3];
echo $new_el[4];
echo $new_el[1];
$_SESSION['date'] = $new_el[6];
}
curl_close($ch);
}
$data = array('u' =>$_SESSION['councel']);
echo curlUsingGet('url',$data);
?>
</div>
<div data-theme="b" data-role="footer" data-position="fixed">
<div>
<pre style="text-align:center">Dan Electronics</pre>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
您需要初始化会话变量:
<?
session_start();
if (!isset($_SESSION['causedate'])) $_SESSION['causedate'] = ""; /* something */