本文整理匯總了PHP中Input::server方法的典型用法代碼示例。如果您正苦於以下問題:PHP Input::server方法的具體用法?PHP Input::server怎麽用?PHP Input::server使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Input
的用法示例。
在下文中一共展示了Input::server方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: serve
public function serve($content, $modified = false)
{
$cache_last_modified = $modified ? time() : filemtime($this->path);
$header_modified_since = strtotime(\Input::server('HTTP_IF_MODIFIED_SINCE', 0));
$status = 200;
// Set the response headers for cache etc
$headers = array('Cache-Control' => 'public', 'Last-Modified' => gmdate('D, d M Y H:i:s', $cache_last_modified) . ' GMT', 'Content-Type' => $this->content_type, 'X-UA-Compatible' => 'IE=edge');
// Still call the before method on the controller... is this a good idea? Perhaps not.
/* if (isset($this->request) && $controller = $this->request->controller_instance) {
if (method_exists($controller, 'before')) $controller->before($content);
} */
// Return 304 not modified if the content hasn't changed, but only if the profiler isn't enabled.
if (!\Fuel::$profiling) {
$headers['Content-Length'] = strlen($content);
if ($header_modified_since >= $cache_last_modified) {
header('HTTP/1.1 304 Not Modified');
exit;
}
}
// Send the response
\Response::forge($content, $status, $headers)->send(true);
if (\Fuel::$profiling) {
\Profiler::mark('CMF Cache Served');
}
exit;
}
示例2: respondWithArray
protected function respondWithArray(array $array, array $headers = [])
{
$mimeTypeRaw = Input::server('HTTP_ACCEPT', '*/*');
// If its empty or has */* then default to JSON
if ($mimeTypeRaw === '*/*') {
$mimeType = 'application/json';
} else {
// You'll probably want to do something intelligent with charset if provided
// This chapter just assumes UTF8 everything everywhere
$mimeParts = (array) explode(';', $mimeTypeRaw);
$mimeType = strtolower($mimeParts[0]);
}
switch ($mimeType) {
case 'application/json':
$contentType = 'application/json';
$content = json_encode($array);
break;
case 'application/x-yaml':
$contentType = 'application/x-yaml';
$dumper = new YamlDumper();
$content = $dumper->dump($array, 2);
break;
default:
$contentType = 'application/json';
$content = json_encode(['error' => ['code' => static::CODE_INVALID_MIME_TYPE, 'http_code' => 415, 'message' => sprintf('Content of type %s is not supported.', $mimeType)]]);
}
$response = Response::make($content, $this->statusCode, $headers);
$response->header('Content-Type', $contentType);
return $response;
}
示例3: before
public function before()
{
parent::before();
$flag = $this->getNotOpenidAllowed();
if ($flag) {
return;
}
if (!\Session::get('wechat', false) && !\Input::get('openid', false)) {
//獲取到openid之後跳轉的參數列表
//$params = \handler\mp\UrlTool::createLinkstring(\Input::get());
//本站域名
$baseUrl = \Config::get('base_url');
$url = $baseUrl . \Input::server('REQUEST_URI');
$toUrl = urlencode($url);
$callback = "{$baseUrl}wxapi/oauth2_callback?to_url={$toUrl}";
$account = \Session::get('WXAccount', \Model_WXAccount::find(1));
$url = \handler\mp\Tool::createOauthUrlForCode($account->app_id, $callback);
\Response::redirect($url);
} else {
if (!\Session::get('wechat', false)) {
$wxopenid = \Model_WechatOpenid::query()->where(['openid' => \Input::get('openid')])->get_one();
if (!$wxopenid) {
\Session::set_flash('msg', ['status' => 'err', 'msg' => '未找到您的微信信息,無法確認您的身份! 係統無法為您提供服務!', 'title' => '拒絕服務']);
return $this->show_mesage();
}
\Session::set('wechat', $wxopenid->wechat);
\Session::set('OpenID', $wxopenid);
\Auth::force_login($wxopenid->wechat->user_id);
} else {
if (!\Auth::check() && \Session::get('wechat')->user_id) {
\Auth::force_login(\Session::get('wechat')->user_id);
}
}
}
}
示例4: resetAction
public function resetAction()
{
$token = "?token=" . Input::get("token");
$errors = new MessageBag();
if ($old = Input::old("errors")) {
$errors = $old;
}
$data = ["token" => $token, "errors" => $errors];
if (Input::server("REQUEST_METHOD") == "POST") {
$validator = Validator::make(Input::all(), ["email" => "required|email", "password" => "required|min:6", "password_confirmation" => "required|same:password", "token" => "required|exists:token,token"]);
if ($validator->passes()) {
$credentials = ["email" => Input::get("email")];
Password::reset($credentials, function ($user, $password) {
$user->password = Hash::make($password);
$user->save();
Auth::login($user);
return Redirect::route("user/profile");
});
}
$data["email"] = Input::get("email");
$data["errors"] = $validator->errors();
return Redirect::to(URL::route("user/reset") . $token)->withInput($data);
}
return View::make("user/reset", $data);
}
示例5: string_with_query
/**
* Returns the full uri with query as a string
*
* @return string
*/
public static function string_with_query(array $query_data = array(), $is_return_full_path = false)
{
$return = $is_return_full_path ? static::base_path(static::string()) : static::string();
if ($query_data) {
$return .= '?' . http_build_query($query_data);
} elseif ($query = \Input::server('QUERY_STRING')) {
$return .= '?' . $query;
}
return $return;
}
示例6: __construct
/**
* setup the class
*
* @return void
*/
private function __construct()
{
//get the current uri
$this->uri_segments = $this->arguments = Uri::segments();
//get the current uri
$this->uri = rtrim(Uri::full(), '/');
$this->request_type = Input::server('request_method');
//get the route map from the config
$this->route_map = Config::settings('routeMap');
//add any additional routes, adding them to the route map
$this->routeMap();
}
示例7: create_url
public static function create_url()
{
$base_url = '';
if (\Input::server('http_host')) {
$base_url .= \Input::protocol() . '://' . \Input::server('http_host');
}
if (\Input::server('script_name')) {
$base_url .= str_replace('\\', '/', dirname(\Input::server('script_name')));
// Add a slash if it is missing
$base_url = rtrim($base_url, '/') . '/';
}
return $base_url;
}
示例8: action_index
/**
* Extcute Ext Direct functions
*/
public function action_index()
{
if (Input::server('HTTP_HOST') === 'localhost') {
// for local development
$url = parse_url(Input::server('HTTP_ORIGIN'));
header('Access-Control-Allow-Credentials: true');
if (isset($url['port'])) {
header('Access-Control-Allow-Origin: http://localhost:' . $url['port']);
} else {
header('Access-Control-Allow-Origin: http://localhost');
}
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD, OPTIONS');
}
$isForm = false;
$isUpload = false;
$post_data = file_get_contents("php://input");
if ($post_data) {
header('Content-Type: text/javascript');
$data = json_decode($post_data);
} else {
if (isset($_POST['extAction'])) {
// form post
$isForm = true;
$isUpload = $_POST['extUpload'] == 'true';
$data = new BogusAction();
$data->action = $_POST['extAction'];
$data->method = $_POST['extMethod'];
$data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null;
$data->data = array($_POST, $_FILES);
} else {
die('Invalid request.');
}
}
$response = null;
if (is_array($data)) {
$response = array();
foreach ($data as $d) {
$response[] = $this->doRpc($d);
}
} else {
$response = $this->doRpc($data);
}
if ($isForm && $isUpload) {
echo '<html><body><textarea>';
echo json_encode($response);
echo '</textarea></body></html>';
} else {
echo json_encode($response);
}
}
示例9: loginAction
public function loginAction()
{
if (Input::server("REQUEST_METHOD") == "POST") {
$validator = Validator::make(Input::all(), array("username" => "required|min:4", "password" => "required|min:6"));
if ($validator->passes()) {
$credentials = array("username" => Input::get("username"), "password" => Input::get("password"));
if (Auth::attempt($credentials)) {
return Redirect::route("user.home");
}
}
return Redirect::route('user.login')->withInput(Input::except('password'))->withErrors($validator)->with('message', trans('messages.invalid-login'));
}
return View::make("user.login");
}
示例10: send
public static function send()
{
// set content type
if (array_key_exists('Content-Type', static::$headers) === false) {
static::$headers['Content-Type'] = 'text/html; charset=UTF-8';
}
// send headers
if (headers_sent() === false) {
$protocol = Input::server('server_protocol', 'HTTP/1.1');
header($protocol . ' ' . static::$status . ' ' . static::$statuses[static::$status]);
foreach (static::$headers as $name => $value) {
header($name . ': ' . $value, true);
}
}
// Send it to the browser!
echo static::$content;
}
示例11: show_production_error
public static function show_production_error(\Exception $e)
{
// when we're on CLI, always show the php error
if (\Fuel::$is_cli) {
return static::show_php_error($e);
}
if (!headers_sent()) {
$protocol = \Input::server('SERVER_PROTOCOL') ? \Input::server('SERVER_PROTOCOL') : 'HTTP/1.1';
header($protocol . ' 500 Internal Server Error');
}
$response = '';
try {
$response = \CMF::getCustomErrorResponse(\Lang::get("site.errors.http.500", array('resource' => 'page'), \Lang::get("site.errors.http.default", array('resource' => 'page'), 'Please contact the website administrator')));
} catch (\Exception $e) {
$response = \View::forge('errors' . DS . 'production');
}
exit($response);
}
示例12: get_upload_path
/**
* 獲取用戶上傳文件存儲的路徑及訪問地址
*
* @param module 資源存儲的類型(請參考config/global.php文件中的folders數組)
*/
public static function get_upload_path($module = 4, $coustom = '')
{
\Config::load('global');
$folders = \Config::get('folders');
$root = \Config::get('root_directory');
$host = str_replace('.', '', \Input::server('HTTP_HOST'));
$user_id = \Auth::check() ? \Auth::get_user()->id : '0';
//資源訪問主機域名如:http://img1.evxin.com
$resUrl = \Config::get('resource_url') !== false ? \Config::get('resource_url') : '';
//資源物理路徑
$uploadPath = \Config::get('upload_path') !== false ? \Config::get('upload_path') : '';
$user_id = $module == 4 ? '' : "/{$user_id}/";
$ymd = date('/Ymd');
//完整物理路徑=服務器物理路徑+當前域名+資源存儲目錄+年月日
$path = "{$root}/{$host}/{$folders[$module]}{$user_id}{$ymd}/" . ($coustom ? "{$coustom}/" : '');
$url = "{$resUrl}/{$path}";
return array('root_directory' => $uploadPath, 'path' => $path, 'url' => $url);
}
示例13: action_wxpay
/**
* 發起微信支付(公眾號JSSDK支付)
*/
public function action_wxpay()
{
$this->account = \Session::get('WXAccount', \Model_WXAccount::find(\Input::get('account_id', 1)));
if (!\Input::get('openid', false)) {
//本站域名
$baseUrl = \Config::get('base_url');
$request_uri = \Input::server('REQUEST_URI', '');
if ($request_uri) {
$request_uri = substr($request_uri, 1);
}
$toUrl = urlencode("{$baseUrl}{$request_uri}");
$callback = "{$baseUrl}wxapi/oauth2_callback?to_url={$toUrl}";
$url = \handler\mp\Tool::createOauthUrlForCode($this->account->app_id, $callback);
\Response::redirect($url);
}
$msg = false;
if (!\Input::get('order_id', false)) {
$msg = ['status' => 'err', 'msg' => '缺少訂單ID', 'errcode' => 0, 'title' => '錯誤'];
} else {
if (!$this->account) {
$msg = ['status' => 'err', 'msg' => '缺少微信公眾號ID', 'errcode' => 0, 'title' => '錯誤'];
}
}
if ($msg) {
\Session::set_flash('msg', $msg);
return \Response::forge(\View::forge('message/moblie'));
}
//訂單openid賦值
$order = \Model_Order::find(\Input::get('order_id'));
if (!$order->buyer_openid) {
$openID = \Model_WechatOpenid::query()->where(['openid' => \Input::get('openid')])->get_one();
if ($openID->wechat->user_id == $order->buyer_id) {
$order->buyer_openid = \Input::get('openid');
$order->save();
}
}
//查詢收款帳戶
$access = \Model_AccessConfig::query()->where('access_type', 'wxpay')->where('seller_id', $order->from_id)->where('enable', 'ENABLE')->get_one();
$result = \handler\mp\Tool::wxpay_order($this->account, $order, $access, \Input::get('openid'));
$params = array('appId' => $this->account->app_id, 'timeStamp' => strval(time()), 'nonceStr' => \Str::random('alnum', 16), 'package' => "prepay_id={$result['prepay_id']}", 'signType' => "MD5");
$params['paySign'] = \handler\mp\Tool::getWxPaySign($params, $access->access_key);
$params['to_url'] = "/order/home/delivery/{$order->id}";
return \Response::forge(\View::forge('pay/wxpay', $params));
}
示例14: test_anchor
/**
* Tests Html::anchor()
*
* @test
*/
public function test_anchor()
{
// Query string tests
Config::set('url_suffix', '');
Config::set('index_file', '');
// External uri
$output = Html::anchor('http://google.com', 'Go to Google');
$expected = '<a href="http://google.com">Go to Google</a>';
$this->assertEquals($expected, $output);
$output = Html::anchor('javascript:do();', 'Do()');
$expected = '<a href="javascript:do();">Do()</a>';
$this->assertEquals($expected, $output);
$output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;'));
$expected = '<a rel="example" class="sample" style="color:red;" href="http://google.com">Go to Google</a>';
$this->assertEquals($expected, $output);
// External secure uri
$output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;'), true);
$expected = '<a rel="example" class="sample" style="color:red;" href="https://google.com">Go to Google</a>';
$this->assertEquals($expected, $output);
// Internal uri
$output = Html::anchor('controller/method', 'Method');
$expected = '<a href="controller/method">Method</a>';
$this->assertEquals($expected, $output);
// Internal secure uri
$host = \Input::server('http_host');
$_SERVER['HTTP_HOST'] = 'fuelphp.com';
$output = Html::anchor('controller/method', 'Method', array(), true);
$expected = '<a href="https://' . \Input::server('http_host') . '/controller/method">Method</a>';
$this->assertEquals($expected, $output);
$_SERVER['HTTP_HOST'] = $host;
// Get original values to reset once done
$index_file = Config::get('index_file');
$url_suffix = Config::get('url_suffix');
$output = Html::anchor('search?q=query', 'Search');
$expected = '<a href="search?q=query">Search</a>';
$this->assertEquals($expected, $output);
Config::set('url_suffix', '.html');
$output = Html::anchor('search?q=query', 'Search');
$expected = '<a href="search.html?q=query">Search</a>';
$this->assertEquals($expected, $output);
// Reset to original values
Config::set('index_file', $index_file);
Config::set('url_suffix', $url_suffix);
}
示例15: smtp_connect
/**
* Connects to the given smtp and says hello to the other server.
*/
protected function smtp_connect()
{
$this->smtp_connection = @fsockopen($this->config['smtp']['host'], $this->config['smtp']['port'], $error_number, $error_string, $this->config['smtp']['timeout']);
if (empty($this->smtp_connection)) {
throw new \SmtpConnectionException('Could not connect to SMTP: (' . $error_number . ') ' . $error_string);
}
// Clear the smtp response
$this->smtp_get_response();
// Just say hello!
if ($this->smtp_send('EHLO' . ' ' . \Input::server('SERVER_NAME', 'localhost.local'), 250, true) !== 250) {
// Didn't work? Try HELO
$this->smtp_send('HELO' . ' ' . \Input::server('SERVER_NAME', 'localhost.local'), 250);
}
try {
$this->smtp_send('HELP', 214);
} catch (\SmtpCommandFailureException $e) {
// Let this pass as some servers don't support this.
}
}