本文整理汇总了PHP中Response::addHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::addHeader方法的具体用法?PHP Response::addHeader怎么用?PHP Response::addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::addHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
function get($request)
{
$response = new Response($request);
if (isset($this->webcode)) {
$tour = $this->em->fetchTour($this->webcode);
echo $format = $request->mostAcceptable(array('json', 'html'));
switch ($format) {
case 'json':
$response->addHeader('Content-type', 'application/json');
$response->body = $tour->__toJSON();
break;
case 'html':
$this->tm->smarty->assign('title', 'Tour Query');
if (get_class($tour) === "JSONMessage") {
$this->tm->smarty->assign('notour', "Tour '" . $this->webcode . "' does not exists!");
} elseif (get_class($tour) === "OldTour") {
$this->tm->smarty->assign('oldtour', $tour);
} elseif (get_class($tour) === "Tour") {
$this->tm->smarty->assign('tour', $tour);
$this->tm->smarty->assign('markers', $tour->merge());
}
// if()
$response->code = Response::OK;
$response->addHeader('Content-type', 'text/html');
$response->body = $this->tm->render('tour');
}
} else {
$this->tm->smarty->assign('title', 'Tour Query');
$response->code = Response::OK;
$response->addHeader('Content-type', 'text/html');
$response->body = $this->tm->render('tour');
}
return $response;
}
示例2: redirect
function redirect($url)
{
$response = new Response();
$completeURL = url($url);
$response->addHeader('HTTP/1.1 302 Found');
$response->addHeader("Location: " . $completeURL);
$response->setStatusCode(302);
return $response;
}
示例3: get
/**
* Handle a GET request for this resource
* @param Request request
* @return Response
*/
function get($request)
{
$response = new Response($request);
$response->code = Response::OK;
// select the most acceptable format of the given types from the request
$format = $request->mostAcceptable(array('json', 'html', 'txt'));
switch ($format) {
// obviously it might make more sense to put the HTML in another file
// and use some kind of templating system
case 'html':
$response->addHeader('Content-type', 'text/html');
$response->body = '<!DOCTYPE html>';
$response->body .= '<html>';
$response->body .= '<head>';
$response->body .= '<title>HTML Representation</title>';
$response->body .= '</head>';
$response->body .= '<body>';
$response->body .= '<h1>HTML Representation</h1>';
$response->body .= '<table border="1">';
foreach ($this->data as $field => $value) {
$response->body .= '<tr>';
$response->body .= '<th>' . htmlspecialchars($field) . '</th>';
$response->body .= '<td>' . htmlspecialchars($value) . '</td>';
$response->body .= '</tr>';
}
$response->body .= '</table>';
$response->body .= '<h2>Explicit links to available formats</h2>';
$response->body .= '<a href="/multirep.txt">Plain text</a> ';
$response->body .= '<a href="/multirep.json">JSON</a> ';
$response->body .= '<a href="/multirep.html">HTML</a>';
$response->body .= '</body>';
$response->body .= '</html>';
break;
case 'json':
$response->addHeader('Content-type', 'application/json');
$response->body = json_encode($this->data);
break;
case 'txt':
$response->addHeader('Content-type', 'text/plain');
$response->body = "Plain Text Representation\n";
$response->body .= "\n";
ob_start();
var_dump($this->data);
$response->body .= ob_get_contents();
ob_end_clean();
break;
// we don't have a suitable format, so do a 406 response instead
// we don't have a suitable format, so do a 406 response instead
default:
$response->code = Response::NOTACCEPTABLE;
$response->addHeader('Content-type', 'text/plain');
$response->body = "406 Not Acceptable\n";
break;
}
return $response;
}
示例4: get
function get($request, $debut, $limit)
{
$response = new Response($request);
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
$data = array();
ouverture();
if ($debut == null) {
$debut = 0;
}
if ($limit == null) {
$limit = 10;
}
// requete pour récupérer tous les gazouillis
$requete = "SELECT id_membre, pseudo, contenu, date_creation \n\t\t\tFROM phpl_gazouillis, phpl_membres \n\t\t\tWHERE phpl_gazouillis.id_membre=phpl_membres.id\n\t\t\tORDER BY date_creation DESC\n\t\t\tLIMIT " . $debut . "," . $limit . "";
$resultat = mysql_query($requete);
while ($row = mysql_fetch_array($resultat)) {
$url_avatar = "http://" . $_SERVER['SERVER_NAME'] . "/suopronos/prono/images/avatars/" . $row["id_membre"] . ".gif";
if (!remote_file_exists($url_avatar)) {
$url_avatar = "http://" . $_SERVER['SERVER_NAME'] . "/suopronos/prono/images/avatars/no_avatar.png";
}
array_push($data, array("id_membre" => $row["id_membre"], "pseudo" => $row["pseudo"], "url_avatar" => $url_avatar, "contenu" => utf8_encode($row["contenu"]), "date" => $row["date_creation"]));
}
$response->body = json_encode(array("gazouillis" => $data));
return $response;
}
示例5: post
function post($request)
{
$response = new Response($request);
if (isset($_POST['tour'])) {
// Remove those slashes
if (get_magic_quotes_gpc()) {
$tour = stripslashes($_POST['tour']);
} else {
$tour = $_POST['tour'];
}
$tour_obj = json_decode($tour);
$entitymanager = GeocacheManager::getInstance();
//~ print_r($tour_obj);
$data = array();
$data['name'] = $tour_obj->name;
$data['webcode'] = isset($tour_obj->webcode) ? $tour_obj->webcode : $this->get_new_webcode();
$data['geocaches'] = $entitymanager->parseGeocaches($tour_obj->geocaches);
$data['ownWaypoints'] = $entitymanager->parseOwnWaypoints($tour_obj->costumMarkers);
$tour = new Tour($data);
$tour->save();
$response->code = Response::OK;
$response->addHeader('Content-type', 'text/plain');
$response->body = $tour->__toJSON();
} else {
$response->code = Response::BADREQUEST;
}
return $response;
}
示例6: post
/**
* Handle a POST request for this map save ressource
* @param Request request
* @return Response
*/
function post($request)
{
$response = new Response($request);
if (isset($_POST['map'])) {
// Remove those slashes
if (get_magic_quotes_gpc()) {
$map = stripslashes($_POST['map']);
} else {
$map = $_POST['map'];
}
$map_obj = json_decode($map);
$geocacheManager = GeocacheManager::getInstance();
$geocaches = $geocacheManager->parseGeocaches($map_obj->{"geocaches"});
foreach ($geocaches as $geocache) {
$geocache->save();
}
$ownWaypoints = $geocacheManager->parseOwnWaypoints($map_obj->{"costumMarkers"});
foreach ($ownWaypoints as $ownWaypoint) {
$ownWaypoint->save();
}
$response->code = Response::OK;
$response->addHeader('Content-type', 'text/plain');
$response->body = print_r($map, true);
} else {
$response->code = Response::BADREQUEST;
}
return $response;
}
示例7: testGetReasonPhraseReturnsTheReasonPhrase
public function testGetReasonPhraseReturnsTheReasonPhrase()
{
$response = new Response();
$this->assertEquals($response->getReasonPhrase(), null);
$response->addHeader('1.0 200 OK');
$this->assertEquals($response->getReasonPhrase(), 'OK');
}
示例8: get
function get($request, $user)
{
$response = new Response($request);
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
$data = array();
ouverture();
// recherche de l'id de l'utilisateur
$queryUser = "SELECT id_prono FROM phpl_membres WHERE pseudo='{$user}'";
$resultat = mysql_query($queryUser);
$row = mysql_fetch_array($resultat);
$idUser = $row[0];
// Saison en cours de l'utilisateur + palmarès de l'utilisateur
$queryPalmares = "SELECT classement.id_champ, classement.place, classement.type, \r\n\t\t\t\t\t\t\t\tcase when groupes.activ_prono = '0' then groupes.nom else 'Saison en cours' end as nom\r\n\t\t\t\t\t\t\tFROM phpl_clmnt_pronos classement\r\n\t\t\t\t\t\t\tJOIN phpl_gr_championnats groupes ON groupes.id = classement.id_champ\r\n\t\t\t\t\t\t\tWHERE classement.id_membre = {$idUser}\r\n\t\t\t\t\t\t\t\tAND classement.type IN ('general', 'hourra', 'mixte')\r\n\t\t\t\t\t\t\tORDER BY classement.id_champ DESC, classement.type ASC";
$resultat = mysql_query($queryPalmares) or die("probleme " . mysql_error());
// Remplissage du tableau avec le palmarès de l'utilisateur
while ($row = mysql_fetch_array($resultat)) {
$numPlace = $row["place"];
$typeChamp = $row["type"];
$nomSaison = $row["nom"];
array_push($data, array("nomSaison" => $nomSaison, "typeChamp" => $typeChamp, "numPlace" => $numPlace));
}
// Retour du tableau au format JSON
$response->body = json_encode(array("palmares" => $data));
return $response;
}
示例9: serve
public function serve($app)
{
if (!is_callable($app)) {
throw new InvalidArgumentException('not a valid app');
}
$this->log('Serving ' . (is_object($app) ? get_class($app) : $app) . ' app…');
try {
$this->log("got request");
$context = array('env' => $_SERVER, 'stdin' => fopen("php://input", "r"), 'logger' => function ($message) {
trigger_error($message, E_USER_NOTICE);
}, '_GET' => $_GET, '_POST' => $_POST, '_FILES' => $_FILES, '_COOKIE' => new Cookies());
$result = call_user_func($app, $context);
$response = new Response();
$response->setStatus($result[0]);
for ($i = 0, $cnt = count($result[1]); $i < $cnt; $i++) {
$response->addHeader($result[1][$i], $result[1][++$i]);
}
unset($response);
echo $result[2];
unset($result);
$this->log("-> done with request");
} catch (\Exception $e) {
$this->log('[Exception] ' . get_class($e) . ': ' . $e->getMessage());
}
}
示例10: post
function post($request)
{
$response = new Response($request);
if (isset($_POST['exception'])) {
$db = Database::obtain();
$exception = $_POST['exception'];
$query_obj = array();
$sql = "SELECT * FROM `" . TABLE_ERRORS . "` WHERE `exception`='" . $exception . "'";
$row = $db->query_first($sql);
if (empty($row['id'])) {
$query_obj['exception'] = $_POST['exception'];
$query_obj['appearance'] = 0;
} else {
$query_obj['exception'] = $row['exception'];
$query_obj['first_submit'] = $row['first_submit'];
$query_obj['appearance'] = $row['appearance'];
if (!empty($row['solution'])) {
$query_obj['solution'] = $row['solution'];
}
}
$response->code = Response::OK;
$response->addHeader('Content-type', 'text/plain');
$response->body = json_encode($query_obj);
} else {
$response->code = Response::BADREQUEST;
}
return $response;
}
示例11: get
function get($request, $user)
{
$response = new Response($request);
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
$data = array();
ouverture();
// recherche du championnat en cours
$querySaisonEnCours = "SELECT phpl_gr_championnats.id\r\n\t\t\t\t\t\t\t\tFROM phpl_gr_championnats \r\n\t\t\t\t\t\t\t\tWHERE phpl_gr_championnats.activ_prono = '1' \r\n\t\t\t\t\t\t\t\tORDER by id desc";
$resultat = mysql_query($querySaisonEnCours) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$idSaisonEnCours = $row[0];
// évolution sur la dernière journée
$queryEvolution = "SELECT graph.type, graph.classement as place, graph.fin\r\n \t\t\t\t\t\t FROM phpl_membres membre\r\n\t\t\t\t JOIN phpl_pronos_graph graph ON graph.id_membre = membre.id_prono\r\n\t\t\t\t \t\t\t\t\t\t AND graph.id_gr_champ = '{$idSaisonEnCours}'\r\n\t\t\t\t \t\t\t\t\t\t AND graph.type in ('general', 'hourra', 'mixte')\r\n\t\t\t\t WHERE membre.pseudo = '{$user}'\t\t \t\t\t\t\t\t \t \r\n\t\t\t\t\t\t\t ORDER BY graph.type, graph.fin";
$resultat = mysql_query($queryEvolution) or die("probleme " . mysql_error());
while ($row = mysql_fetch_array($resultat)) {
$typeChamp = $row["type"];
$numPlace = $row['place'];
$numJournee = $row['fin'];
array_push($data, array("type" => $typeChamp, "place" => $numPlace, "jour" => $numJournee));
}
// Retour du tableau au format JSON
$response->body = json_encode(array("profilEvolution" => $data));
return $response;
}
示例12: post
function post($request)
{
ouverture();
$response = new Response($request);
if (!$this->isSecured()) {
$response->body = "401";
return $response;
}
$contenu = file_get_contents('php://input');
if (empty($contenu)) {
$response->body = "500:NO_DATA";
return $response;
} else {
if (strlen($contenu) > 140) {
$response->body = "le message fait plus de 140 caractères";
return $response;
}
}
$user_pseudo = $_SERVER['PHP_AUTH_USER'];
$requete = "SELECT pseudo, id_prono FROM phpl_membres WHERE pseudo='{$user_pseudo}'";
$result = mysql_query($requete);
$row = mysql_fetch_array($result);
$user_id = $row[1];
$contenu = addslashes($contenu);
mysql_query("INSERT INTO phpl_gazouillis (id_membre, contenu, reponse_a) VALUES ('{$user_id}','{$contenu}',null)") or die("probleme " . mysql_error());
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
return $response;
}
示例13: get
function get($request, $user)
{
$response = new Response($request);
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
$data = array();
ouverture();
// recherche du championnat en cours
$querySaisonEnCours = "SELECT phpl_gr_championnats.id\r\n\t\t\t\t\t\t\t\tFROM phpl_gr_championnats \r\n\t\t\t\t\t\t\t\tWHERE phpl_gr_championnats.activ_prono = '1' \r\n\t\t\t\t\t\t\t\tORDER by id desc";
$resultat = mysql_query($querySaisonEnCours) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$idSaisonEnCours = $row[0];
// recherche de l'id de la dernière journée
$queryDerniereJournee = "SELECT max(evolutionGraph.fin)\r\n\t\t\t\t\t\t\t\tFROM phpl_pronos_graph evolutionGraph\r\n\t\t\t\t\t\t\t\tWHERE evolutionGraph.id_gr_champ = '{$idSaisonEnCours}'";
$resultat = mysql_query($queryDerniereJournee);
$row = mysql_fetch_array($resultat);
$idDerniereJournee = $row[0];
// évolution sur la dernière journée
$queryEvolution = "SELECT P2.type, P2.classement as place, (P2.points - P1.points) as points, (P1.classement - P2.classement) as evolution\r\n \t\t\t\t\t\t FROM phpl_membres membre\r\n\t\t\t\t JOIN phpl_pronos_graph P1 ON P1.id_membre = membre.id_prono\r\n\t\t\t\t \t\t\t\t\t\t AND P1.id_gr_champ = '{$idSaisonEnCours}'\r\n\t\t\t\t \t\t\t\t\t\t AND P1.type in ('general', 'hourra', 'mixte')\r\n\t\t\t\t\t\t\t \t\t\t\t\t\t AND P1.fin = '" . ($idDerniereJournee - 1) . "'\t\t \t\t\t\t\t\t \r\n\t\t\t\t JOIN phpl_pronos_graph P2 ON P2.id_membre = P1.id_membre\r\n\t\t\t\t \t\t\t\t\t\t AND P2.id_gr_champ = P1.id_gr_champ\r\n\t\t\t\t \t\t\t\t\t\t AND P2.type = P1.type\r\n\t\t\t\t \t\t\t\t\t\t AND P2.fin = '{$idDerniereJournee}'\r\n\t\t\t\t WHERE pseudo = '{$user}'\t\t \t\t\t\t\t\t \t \r\n\t\t\t\t\t\t\t ORDER BY P2.type";
$resultat = mysql_query($queryEvolution) or die("probleme " . mysql_error());
while ($row = mysql_fetch_array($resultat)) {
$typeChamp = $row["type"];
$numPlace = $row['place'];
$nbPoints = $row['points'];
$numEvolution = $row["evolution"];
array_push($data, array("type" => $typeChamp, "place" => $numPlace, "points" => $nbPoints, "evolution" => $numEvolution));
}
// Retour du tableau au format JSON
$response->body = json_encode(array("profilStat" => $data));
return $response;
}
示例14: parse
/**
* Parses a raw response string, including headers and body, and returns a Response object.
*
* @param string $response
*
* @return \Brick\Http\Response
*
* @throws \RuntimeException
*/
public static function parse($response)
{
$responseObject = new Response();
if (preg_match('/^HTTP\\/([0-9]\\.[0-9]) ([0-9]{3}) .*\\r\\n/', $response, $matches) == 0) {
throw new \RuntimeException('Could not parse response (error 1).');
}
list($line, $protocolVersion, $statusCode) = $matches;
$responseObject->setProtocolVersion($protocolVersion);
$responseObject->setStatusCode($statusCode);
$response = substr($response, strlen($line));
for (;;) {
$pos = strpos($response, Message::CRLF);
if ($pos === false) {
throw new \RuntimeException('Could not parse response (error 2).');
}
if ($pos == 0) {
break;
}
$header = substr($response, 0, $pos);
if (preg_match('/^(\\S+):\\s*(.*)$/', $header, $matches) == 0) {
throw new \RuntimeException('Could not parse response (error 3).');
}
list($line, $name, $value) = $matches;
if (strtolower($name) == 'set-cookie') {
$responseObject->setCookie(Cookie::parse($value));
} else {
$responseObject->addHeader($name, $value);
}
$response = substr($response, strlen($line) + 2);
}
$body = substr($response, 2);
$responseObject->setContent($body);
return $responseObject;
}
示例15: get
function get($request, $idMatch)
{
$response = new Response($request);
ouverture();
$response->code = Response::OK;
$response->addHeader('content-type', 'text/plain');
$data = array();
if (isset($_GET['paramProno'])) {
$paramProno = $_GET['paramProno'];
} else {
$paramProno = "";
}
$requete = "SELECT max(id) FROM phpl_championnats";
$resultat = mysql_query($requete) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$gr_champ = $row[0];
// Recherche du nombre de points max
$requete = "SELECT pts_prono_exact FROM phpl_gr_championnats WHERE id_champ = '{$gr_champ}'";
$resultat = mysql_query($requete) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$points_prono_exact = $row[0];
// si il y des pronos automatiques à faire sur ce match, on calcule les cotes
//On compte le nombre de parieurs sur le match
$requete = "SELECT COUNT(*) FROM phpl_pronostics WHERE id_match = '{$idMatch}'";
$resultat = mysql_query($requete) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$nb_parieurs_total = $row[0];
// Retour au format JSON
for ($i = 0; $i < 3; $i++) {
switch ($i) {
case 0:
$type_prono = "1";
break;
case 1:
$type_prono = "N";
break;
case 2:
$type_prono = "2";
break;
}
if ($paramProno != "") {
$type_prono = $paramProno;
$i = 3;
}
//On compte le nombre de parieurs sur une victoire de l'equipe à l'exterieur
$requete = "SELECT COUNT(*) FROM phpl_pronostics WHERE id_match = '{$idMatch}' AND pronostic = '{$type_prono}'";
$resultat = mysql_query($requete) or die("probleme " . mysql_error());
$row = mysql_fetch_array($resultat);
$nb_parieurs = $row[0];
if ($nb_parieurs == "0") {
$points_prono = "0";
} else {
$points_prono = floor($points_prono_exact * $nb_parieurs_total / $nb_parieurs);
}
array_push($data, array("type" => $type_prono, "cote" => $points_prono));
}
$response->body = json_encode(array("coteMatch" => $data));
return $response;
}