ホーム > ブログ > カテゴリー テクメモ

PHPでクッキーに複数の値を一括登録する方法を2つ紹介します。

1. 連想配列形式でクッキーに登録

setcookie("status[height]", 167);
setcookie("status[weight]", 50);
setcookie("status[sight]", 1.2);

クッキーの内容を確認
print_r($_COOKIE['status']);

出力結果
Array
(
    [height] => 167
    [weight] => 50
    [sight] => 1.2
)

2. シリアル化してクッキーに登録

$status = array(
	"height" => 167,
	"weight" => 50,
	"sight" => 1.2
);
setcookie("status", serialize($status));

クッキーの内容を確認するときは、シリアル化された文字列を復元します。
print_r(unserialize($_COOKIE['status']));

出力結果
Array
(
    [height] => 167
    [weight] => 50
    [sight] => 1.2
)

jQuery popin solution - prettyPopin - by Stephane Caron
URL:jQuery popin solution – prettyPopin – by Stephane Caron

jQueryプラグイン「prettyPopin」を使うと簡単にポップアップが実装できます。

サンプルはこちら(別ウィンドウで開きます)。

使い方を紹介します。

1. 「jquery.js」と「prettyPoint.js」の読み込み

<script type="text/javascript" src="js/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.prettyPopin.js" charset="utf-8"></script>
<link rel="stylesheet" href="css/prettyPopin.css" type="text/css" media="screen" charset="utf-8" />
※例では、「prettyPoint」に添付されているCSSファイルも読み込んでいます。

prettyPoint.jsのダウンロードはこちら
prettyPoint.js

jquery.jsのダウンロードはこちら
jquery.js


2. ポップアップする識別名を設定

例では、aタグのrel属性の値に「prettyPopin」と設定しました。
<a href="ajax/regular.html" rel="prettyPopin">ポップアップ!</a>


3. prettyPopin()の呼び出し

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
  $("a[rel^='prettyPopin']").prettyPopin({width: 550,followScroll:false});
});
</script>

完了です。

設定等の詳細は「jQuery popin solution – prettyPopin – by Stephane Caron」を
ご覧下さい。

Net::HTTPライブラリを使用してSSL下のWEBページを取得した際に、
以下のような警告文がでます。

warning: peer certificate won't be verified in this SSL session

これを停めるには、
Net::HTTPのインスタンスメソッドverify_modeに下記の定数を指定します。

サンプルコード:
require 'net/https'
https = Net::HTTP.new("secure.example.com", 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
https.start { |w|
  response = w.get('/')
  puts response.body
}

※この場合、https.use_ssl = trueの指定は必須です。

参考URL:
net/https – Rubyリファレンスマニュアル

実行環境
Ruby 1.8.7
CentOS 5.3