我一直在试图创建一个基本上是移动短代码消息的php文件。由于页面上的任何输出都会自动显示在手机短信中,因此我无法在页面上使用任何html。但是我在执行一些谷歌分析JavaScript代码之前,文本输出在页面上有问题。我创建一个外部文件,并在那里写入JavaScript,并试图通过curl执行该文件,但curl不执行JavaScript。所以,我的主文件SMSapi.php代码是这样的:通过php脚本在外部文件中执行Javascript
<?php
if(isset($_GET['mobile'])){
$number = $_GET['mobile'];
}
if(isset($_GET['text'])){
$data = $_GET['text'];
}
$brand = "mybrand";
$event = "MyEvent";
$deal = "MyDeal";
$url = "http://myurl.com/sms.php";
$post_string = "brand={$brand}&event={$event}&deal={$deal}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$success = curl_exec($ch);
curl_close($ch);
echo "Your discount code is XYZ123";
?>
的sms.php代码如下:
<?php
if(isset($_POST) && !empty($_POST['event']) && !empty($_POST['brand']) && !empty($_POST['deal'])):
$event = urldecode($_POST['event']);
$brand = urldecode($_POST['brand']);
$deal = urldecode($_POST['deal']);
?>
<html>
<head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-MyNum']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
_gaq.push(['_trackEvent', '<?php echo $event; ?>', '<?php echo $brand; ?>', '<?php echo $deal; ?>']);
</script>
</head>
</html>
<?php endif ?>
主要SMS API文件,使卷曲请求短信.php文件,当文件被执行时,html和javascript会以文本形式返回,而不会在那里发生任何执行。因此,JavaScript显示在SMS中。
有没有一种方法来实现一个外部URL和所有的JavaScript在那里和那里通过PHP?
你知道[ob_start()](http://php.net/manual/ru/function.ob-start.php)和其他输出缓冲功能吗?他们可能会帮助你。 – J0HN
输出缓冲区可以隐藏html,这是有用的,但也没有实现html和javascript这是问题,因为我需要的javascript在谷歌分析中输入条目 – Shiva