2015-02-08 145 views
0

这个php代码是使用ajax执行的。执行头语句后,Ajax请求不会返回。从php转到url并执行其余的代码

if(is_numeric($phone) && strlen($phone)==10){ 
     $text = "Hi $name, your account created at hhhhh. Check your email to get updates. Thank you"; 
     $sms = "http://domain.com/msg.php?user=******&pass=*****&sender=***&phone=$phone&text=$text&priority=****&stype=***"; 
header("Location: $sms"); 
    } 

    $url = "done"; 
    echo $url; 

我需要的是什么,只是去$sms网址在PHP,并呼吁通过Ajax这个代码执行时的剩余部分。是否有任何其他方法比标题去链接和执行PHP中的其余代码。

+0

做一些关于[curl]的研究(https://www.google.com/search?q=php%20curl) – 2015-02-08 17:39:03

+0

你为什么通过GET请求发送密码? – ntzm 2015-02-08 17:41:09

+0

短信网关API是这样的。 – user3209025 2015-02-08 17:46:09

回答

0

更换

header("Location: $sms"); 

@file_get_contents($sms); 
+0

试过这个,代码完全执行,但没有得到短信。 – user3209025 2015-02-08 17:45:12

0

你不能告诉它应该从不同的URL ,并从当前的URL同时显示内容的显示内容的浏览器。

这听起来像你应该从你的服务器向domain.com网址发出HTTP请求,在这种情况下,你应该查看cURL而不是header()

+0

尝试此代码 '$ curl = curl_init(); curl_setopt_array($卷曲,阵列( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $ SMS, CURLOPT_USERAGENT => 'SMS' )); $ resp = curl_exec($ curl); curl_close($ curl);' 代码执行没有错误,但没有得到短信。 – user3209025 2015-02-09 00:44:23

+0

与curl一起工作,需要urlencode $文本 – user3209025 2015-02-09 17:32:41