由于某种原因,file_get_contents()
没有返回任何结果。
$result = file_get_contents('http://localhost/service/service.php?action=register&name='.$name.'&lname='.$lname.'&email='.$email.'&username='.$username.'&password='.$password.'&gender='.$gender.'&mobile='.$mobile.'&address='.$address);
有什么建议吗?
为了创建一个有效的URL,必须对变量进行编码。
使用函数urlencode()
$name = urlencode($name);
$lname = urlencode($lname);
$email = urlencode($email);
$username = urlencode($username);
$password = urlencode($password);
$gender = urlencode($gender);
$mobile = urlencode($mobile);
$address = urlencode($address);
$result = file_get_contents('http://localhost/service/service.php?action=register&name='.$name.'&lname='.$lname.'&email='.$email.'&username='.$username.'&password='.$password.'&gender='.$gender.'&mobile='.$mobile.'&address='.$address);