在PHP数组()中使用$\u GET
我有一个PHP数组:在PHP数组()中使用$\u GET,php,arrays,get,global,params,Php,Arrays,Get,Global,Params,我有一个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数组工作的唯一方法是使用诸如“n
$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”之类的字符串
$name=$\u GET['name']代码>不起作用
如何正确地将$\u 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 -->
$params=array(“名称”=>$name,“说明”=>“不适用”、“位置”=>“奥勒姆犹他州”、“开始时间”=>“2013年7月25日”、“结束时间”=>“2013年7月26日”、“隐私类型”=>“开放”);
$params=array(“名称”=>$name,“说明”=>“不适用”、“位置”=>“奥勒姆犹他州”、“开始时间”=>“2013年7月25日”、“结束时间”=>“2013年7月26日”、“隐私类型”=>“开放”);
问题是,您试图在变量中串联,就像您在构建SQL字符串或其他东西一样
$params = array("name" => '".$name.'",...
//-----------------------^^^^^^^^^^^^^
您只需在此处使用一个简单的变量:
$params = array("name" => $_GET['name'],...
问题是,您试图在变量中串联,就像您在构建SQL字符串或其他东西一样
$params = array("name" => '".$name.'",...
//-----------------------^^^^^^^^^^^^^
您只需在此处使用一个简单的变量:
$params = array("name" => $_GET['name'],...
您需要从数组中获取字符串值
首先,GET设置好了吗
如果它位于URL中,则如下所示:
url.com/mypage.php?id=1
您可以通过这种方式从URL中获取它
$id = strval( $_GET['id'] );
echo 'ID: '.$id; // check if it worked
如果它来自表单,请尝试:
echo '<pre>'; print_r( $_GET ); echo '</pre>';
$name = $_GET['name']; // If you can see it in the print_r, then this should work
array("name"=>'"'.$name.'"'...)
您不需要使用引号 您需要从数组中获取字符串值
首先,GET设置好了吗
如果它位于URL中,则如下所示:
url.com/mypage.php?id=1
您可以通过这种方式从URL中获取它
$id = strval( $_GET['id'] );
echo 'ID: '.$id; // check if it worked
如果它来自表单,请尝试:
echo '<pre>'; print_r( $_GET ); echo '</pre>';
$name = $_GET['name']; // If you can see it in the print_r, then this should work
array("name"=>'"'.$name.'"'...)
您不需要使用引号 您是否检查过$\u GET实际上正在传递一个名为“name”的变量?在“开发”框中,添加一行,如:
或
最后,如果要在数据库中使用传递的变量,请不要忘记转义它们:
希望这有帮助您是否检查过$\u GET实际上正在传递一个名为“name”的变量?在“开发”框中,添加一行,如:
或
最后,如果要在数据库中使用传递的变量,请不要忘记转义它们:
希望这能有所帮助我不确定是什么原因导致了这种情况,但是你试过了吗:数组(“name”=>$name…只是没有引号的$name?虽然没关系。是的,没有引号的变量可以工作。$params=array(“name”=>$\u GET['name'],“description”=>“not application”,“location”=>“Orem犹他州”,“start\u time”=>“07/25/2013”,“end\u time”=>“2013年7月26日”,“隐私类型”=>“开放”);不起作用…我该如何实现这一点?@DavidueGeneperson,$params=array(“name”=>$获取['name'])…
不起作用?错误消息等。我正在使用:$params=array(name=>$获取['name'],“description”=>“不适用”,“位置”=>“Orem Utah”,“开始时间”=>“2013年7月25日“,“end_time”=>“07/26/2013”,“privacy_type”=>“OPEN”);但我只能提交包含1的事件。一个单词2。没有符号…………为什么@DaveRandom背后有什么想法?我不确定是什么原因导致了这一点,但您尝试过:数组(“名称”)=>$name…只有$name没有引号吗?虽然这不重要。是的,没有引号的变量可以工作。$params=array(“name”=>$\u GET['name'],“description”=>“not application”,“location”=>“Orem犹他”,“start\u time”=>“07/25/2013”,“end\u time”=>“07/26/2013”,“privacy\u type”=>“OPEN”);不起作用…我该如何实现这一点?@davideugeneperson使用的是:$params=array(“name”=>$\u GET['name']…
不起作用?错误消息等…?我使用的是:$params=array(name=>$\u GET['name'],“description”=>“not application”,“location”=>“Orem犹他州”,“开始时间”=>“07/25/2013”,“结束时间”=>“07/26/2013”,“privacy_type”=>“OPEN”);但我只能提交包含1的事件。一个单词2。没有符号…………为什么@DaveRandom背后有什么想法?我尝试了你的方法,但收到了[function.file get contents]:无法打开流:HTTP请求失败!HTTP/1.0 400错误请求…..删除文件获取内容显示(id)aka(名称)已正确注册到其相应变量。但是,仍然没有发布到Fbook。您欺骗了我们好先生:P您让我们认为您是新手,但您的类型表明并非如此。我打赌您获得了400,因为您没有获取文件内容的权限(又名read)在该文件上。我打赌该文件不存在。我将这一行作为问题行引用。$access\u token=file\u get\u contents($token\u url);我知道$token\u url是一个url,但这并不意味着他可以读取那里的内容。我尝试了你的方法,但收到了[function.file get contents]:无法打开流:HTTP请求失败!HTTP/1.0 400错误请求…..删除文件获取内容显示(id)aka(名称)已正确注册到其相应变量。但是,仍然没有发布到Fbook。您欺骗了我们好先生:P您让我们认为您是新手,但您的类型表明并非如此。我打赌您获得了400,因为您没有获取文件内容的权限(又名read)在该文件上。我打赌该文件不存在。我将这一行作为问题行引用。$access\u token=file\u get\u contents($token\u url);我知道$token\u url是一个url,但这并不意味着他可以读取那里的内容。