dbaccess.php ( No.1 ) |
|
日時: 2011/04/26 13:19
名前: lightbox
|
日時: 2011/04/26 13:19 名前: lightbox
拡張子:
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
foreach( $_GET as $Key => $Value ) {
$_GET[$Key] = str_replace("\\\\", "\\", $Value );
$_GET[$Key] = str_replace("\\'", "'", $_GET[$Key] );
$_GET[$Key] = str_replace("\\\"", "\"", $_GET[$Key] );
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQL実行結果</title>
</head>
<body style='white-space:pre;'>
<?
print $_GET['text'];
$Server = 'localhost';
$DbName = 'データーベース名';
$User = 'ユーザー';
$Password = 'パスワード';
// 接続
$Connect = @mysql_connect( $Server, $User, $Password );
if ( !$Connect ) {
print "接続エラーです";
exit();
}
// DB選択
mysql_select_db( $DbName, $Connect );
//mysql_set_charset("utf8", $Connect);
mysql_query("set names 'utf8'", $Connect);
// クエリ
$result = mysql_query($_GET['text'], $Connect);
if ( !$result ) {
print "\n";
print "<span style='color:#f00'>" . mysql_error() . "</span>";
}
// 列数
$nField = @mysql_num_fields( $result );
if ( $nField ) {
$nCount = 0;
print "<table style='border:solid 1px #000;border-collapse:collapse;'>\n";
while ($row = mysql_fetch_row($result)) {
print "<tr>\n";
print "\t<td style='border:solid 1px #000;padding:5px;'>" . ($nCount + 1) . "</TD>\n";
for( $i = 0; $i < $nField; $i++ ) {
print "\t<td style='border:solid 1px #000;padding:5px;'>{$row[$i]}</TD>\n";
}
print "</tr>\n";
$nCount++;
}
print "</table>";
}
// 接続解除
mysql_close($Connect);
?>
</body>
</html>
|
mail.php ( No.2 ) |
日時: 2011/04/23 23:14 名前: lightbox
拡張子:
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
foreach( $_POST as $Key => $Value ) {
$_POST[$Key] = str_replace("\\\\", "\\", $Value );
$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}
$subject = "件名";
$from_name = "送信元";
$from_address = "<name1@domain1>";
$to_name = "宛先";
$to_address = "<name2@domain2>";
$body = $_GET['text'];
// Windows 用
// ini_set("SMTP", "IPアドレスまたはHOST名" );
// unix では、sendmail を使用します。
// 通常、この URL から信頼されているメールアドレス前提にしているので、
// セキュリティ情報は送る事ができません
// window 環境でもそれは同様なので、同一サーバーにメールサーバー
// を用意するか、COM+basp21でセキュリティ情報を使って送信する必要があります
// mb_send_mail() は、e-mail をエンコードする際にこの設定を使用します
// ※ subject と body のみ
mb_language( "ja" );
// ↓PHP で動作しないと思われる文字エンコーディング
// JIS, SJIS, ISO-2022-JP, BIG-5
// http://www.php.net/manual/ja/mbstring.php4.req.php
// 内部エンコーディングの設定
mb_internal_encoding("EUC-JP");
$subject = mb_convert_encoding( $subject, mb_internal_encoding(), "utf-8" );
$body = mb_convert_encoding( $body, mb_internal_encoding(), "utf-8" );
$body = mb_convert_kana($body,'K',mb_internal_encoding());
// 宛先と差出人は自分でエンコードする必要があります
$to = mb_convert_encoding( $to_name, "JIS", "utf-8" );
$to = "=?ISO-2022-JP?B?" . base64_encode($to) . "?= $to_address";
$from = mb_convert_encoding( $from_name, "JIS", "utf-8" );
$from = "From: =?ISO-2022-JP?B?" . base64_encode($from) . "?= $from_address";
mb_send_mail($to, $subject, $body, $from );
?>
メール送信が終了しました。
|
twitter.php ( No.3 ) |
日時: 2011/04/23 23:15 名前: lightbox
拡張子:
<?
// **********************************************************
// Twitter への投稿 : バージョン1
// **********************************************************
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
// **********************************************************
// AOuth 用の urlencode 関数
// **********************************************************
function urle( $str ) {
// php 5.3.x 〜 ではこの変換は必要無い
return str_replace('%7E', '~', rawurlencode($str));
}
// **********************************************************
// 投稿データ
// **********************************************************
$text = $_GET['text'];
// **********************************************************
// API
// **********************************************************
$twitter_url = 'http://api.twitter.com/1/statuses/update.json';
// **********************************************************
// 認証データ
// **********************************************************
$oauth_consumer_key = "アプリケーションページより取得";
$oauth_consumer_secret = "アプリケーションページより取得";
$oauth_token = "My Access Token ページより取得";
$oauth_secret = "My Access Token ページより取得";
// 毎回変化するランダムな文字列
$mt = microtime();
$rand = mt_rand();
$oauth_nonce = md5($mt . $rand);
$oauth_signature_method = "HMAC-SHA1";
$oauth_timestamp = mktime();
$oauth_version = "1.0";
// *********************************************************
// シグネチャ用ベース文字列作成
/*
httpMethod + "&" +
url_encode( base_uri ) + "&" +
sorted_query_params.each { | k, v |
url_encode ( k ) + "%3D" +
url_encode ( v )
}.join("%26")
*/
// *********************************************************
$base_string = "POST";
$base_string .= "&" . urle($twitter_url);
$base_string .= "&";
$base_string .= urle("oauth_consumer_key")."%3D".urle($oauth_consumer_key)."%26";
$base_string .= urle("oauth_nonce")."%3D".urle($oauth_nonce)."%26";
$base_string .= urle("oauth_signature_method")."%3D".urle($oauth_signature_method)."%26";
$base_string .= urle("oauth_timestamp")."%3D".urle($oauth_timestamp)."%26";
$base_string .= urle("oauth_token")."%3D".urle($oauth_token)."%26";
$base_string .= urle("oauth_version")."%3D".urle($oauth_version);
$base_string .= "%26status" . "%3D" . urle(urle($text));
// *********************************************************
// シグネチャ作成
/*
url_encode( consumer_secret ) + "&" +
url_encode( oauth_token_secret || nil )
*/
// *********************************************************
$oauth_signature =
base64_encode( hash_hmac(
"sha1",
$base_string,
$oauth_consumer_secret . "&" . $oauth_secret,
true
));
// *********************************************************
// curl 処理
// *********************************************************
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $twitter_url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=" . urle($text));
// *********************************************************
// http ヘッダ作成
// *********************************************************
$header = array();
$header[] = 'Expect:';
$header[] = "Authorization: OAuth ".
urle("oauth_consumer_key")."=\"".urle($oauth_consumer_key)."\",".
urle("oauth_token")."=\"".urle($oauth_token)."\",".
urle("oauth_nonce")."=\"".urle($oauth_nonce)."\",".
urle("oauth_timestamp")."=\"".urle($oauth_timestamp)."\",".
urle("oauth_signature_method")."=\"".urle($oauth_signature_method)."\",".
urle("oauth_version")."=\"".urle($oauth_version)."\",".
urle("oauth_signature")."=\"".urle($oauth_signature)."\"";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// *********************************************************
// https 用 ( https://api.twitter.co 利用時に必要 )
// *********************************************************
//curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
// *********************************************************
// 戻された http ヘッダの出力
// *********************************************************
$handle = fopen("./header.txt", "w");
curl_setopt($curl, CURLOPT_WRITEHEADER, $handle);
// *********************************************************
// 送信
// *********************************************************
$result = curl_exec($curl);
// *********************************************************
// 結果
// *********************************************************
print "<br>";
if($result === false) {
print '送信処理にエラーが発生しました: ' . curl_error($curl);
}
else {
print '送信処理は正常に終了しました';
}
curl_close($curl);
// *********************************************************
// 結果表示
// *********************************************************
print "<br>";
if ( function_exists("json_decode") ) {
$result = json_decode( $result );
}
print "<pre>";
print_r( $result );
print "</pre>";
?>
|
|
|
|