【发布时间】:2011-12-19 11:44:36
【问题描述】:
我有一个 PHP 数组:
$params = array(
"name" => "$name",
"description" => "not applicable",
"location" => "Orem Utah",
"start_time" => "07/25/2013",
"end_time" => "07/26/2013",
"privacy_type" => "OPEN"
);
让$name 数组工作的唯一方法是,如果我使用诸如“名称”之类的字符串
$name = $_GET['name']; 不起作用。
如何正确地将$_GET 放入这个数组中?
这是我的全部代码...
<?php
session_start();
$app_id = "xxxxxxx";
$app_secret = "xxxxxxxx";
$my_url = "http://www.xxxxxxxx.xxxx/xxxxxxxxxevent.php?name=".urlencode($_SESSION['name'])."";
$code = $_REQUEST["code"];
if (empty($code)) {
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=create_event";
echo("<script>top.location.href='" . $auth_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$test = "$_GET[name]";
$url = "https://graph.facebook.com/me/events?" . $access_token;
$params = array(
"name" => "$name",
"description" => "not applicable",
"location" => "Orem Utah",
"start_time" => "07/25/2013",
"end_time" => "07/26/2013",
"privacy_type" => "OPEN"
);
// Check if we have an image
// Start the Graph API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
$decoded = json_decode($result, 1);
curl_close($ch);
if (is_array($decoded) && isset($decoded['id'])) {
$msg = "success";
}
$event_url = "https://graph.facebook.com/me/".$_SESSION['fid']."?" . $access_token;
if (isset($msg)) {
$_SESSION['fid'] = $decoded['id']; header("location:xxxxxx2.php");
}
?>
<!-- irrelevant HTML BELOW HERE -->
【问题讨论】:
-
我不确定是什么原因造成的,但您是否尝试过:array("name" => $name... just $name without the quotes?虽然没关系
-
编辑是的,未引用的变量确实有效。 $params = array("name" => $_GET['name'], "description" => "not applicable", "location" => "Orem Utah", "start_time" => "07/25/2013" , "end_time" => "07/26/2013", "privacy_type" => "OPEN");不起作用...我将如何实现这一目标?
-
@DavidEugenePeterson
$params = array("name" => $_GET['name']...在什么方面不起作用?错误信息等...? -
我正在使用:$params = array(name => $_GET['name'], "description" => "not applicable", "location" => "Orem Utah", " start_time" => "07/25/2013", "end_time" => "07/26/2013", "privacy_type" => "OPEN");但我只能提交包含 1. 一个单词 2. 没有符号的事件...................... ...................为什么@DaveRandom 背后有什么想法?
标签: php arrays get global params