<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>php | エス・プロ</title>
	<atom:link href="https://s-pro4.com/cat/web/php/feed" rel="self" type="application/rss+xml" />
	<link>https://s-pro4.com</link>
	<description>パソコンとシステムの活用を考えます</description>
	<lastBuildDate>Mon, 09 Dec 2024 16:28:20 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://s-pro4.com/wp-content/uploads/2021/10/bb4c6ee1587184e454cc308581390f8d-150x150.png</url>
	<title>php | エス・プロ</title>
	<link>https://s-pro4.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Securimageの3.Xから4.Xへのバージョンアップを試みる</title>
		<link>https://s-pro4.com/page-866.html</link>
		
		<dc:creator><![CDATA[stakaha]]></dc:creator>
		<pubDate>Mon, 09 Dec 2024 16:28:19 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web技術]]></category>
		<guid isPermaLink="false">https://s-pro4.com/?p=866</guid>

					<description><![CDATA[Securimage 3.2RC3を使用していて、現在の最新版4.0.2へアップグレードを試験してみた。 https://github.com/dapphp/securimage というのは、PHPのバージョンを7.4か [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Securimage 3.2RC3を使用していて、現在の最新版4.0.2へアップグレードを試験してみた。</p>



<p><a href="https://github.com/dapphp/securimage" target="_blank" rel="noreferrer noopener">https://github.com/dapphp/securimage</a><br></p>



<p>というのは、PHPのバージョンを7.4から8.Xへ上げるためである。</p>



<p>サンプルのexample_form.phpを見ると、HTML出力用の getCaptchaHtml というstatic functionができて、簡単に使うにはそれだけ記述すれば良さそうだ。</p>



<p>4.0.2での記述</p>



<pre class="wp-block-code"><code>      echo "&lt;div id='captcha_container_1'>\n";
      echo Securimage::getCaptchaHtml($options);
      echo "\n&lt;/div>\n";
</code></pre>



<figure class="wp-block-image size-full"><img decoding="async" width="328" height="150" src="https://s-pro4.com/wp-content/uploads/2024/12/securimage.jpg" alt="" class="wp-image-867" srcset="https://s-pro4.com/wp-content/uploads/2024/12/securimage.jpg 328w, https://s-pro4.com/wp-content/uploads/2024/12/securimage-300x137.jpg 300w" sizes="(max-width: 328px) 100vw, 328px" /></figure>



<p>この記述だけで、文字列、再生ボタン、再表示ボタン、文字入力テキストフィールドが生成される。<br>展開されたHTMLの中身は下記のような感じ</p>



<pre class="wp-block-code"><code>
&lt;div id='captcha_container_1'>
&lt;img style="float: left; padding-right: 5px" id="captcha_image" src="/securimage/securimage_show.php?id=5a8bbfe3b4c78c615754356f335fdea831d7f97c&amp;amp;amp;" alt="CAPTCHA Image" />&lt;div id="captcha_image_audio_div">
&lt;audio id="captcha_image_audio" preload="none" style="display: none">
&lt;source id="captcha_image_source_wav" src="/securimage/securimage_play.php?id=5a8bbfe3b4c78c615754356f335fdea831d7f97c" type="audio/wav">
&lt;/audio>
&lt;/div>
&lt;div id="captcha_image_audio_controls">
&lt;a tabindex="-1" class="captcha_play_button" href="/securimage/securimage_play.php?id=5a8bbfe3b4c78c615754356f335fdea831d7f97c" onclick="return false">
&lt;img class="captcha_play_image" height="32" width="32" src="/securimage/images/audio_icon.png" alt="Play CAPTCHA Audio" style="border: 0px">
&lt;img class="captcha_loading_image rotating" height="32" width="32" src="/securimage/images/loading.png" alt="Loading audio" style="display: none">
&lt;/a>
&lt;noscript>Enable Javascript for audio controls&lt;/noscript>
&lt;/div>
&lt;script type="text/javascript" src="/securimage/securimage.js">&lt;/script>
&lt;script type="text/javascript">captcha_image_audioObj = new SecurimageAudio({ audioElement: 'captcha_image_audio', controlsElement: 'captcha_image_audio_controls' });&lt;/script>
&lt;a tabindex="-1" style="border: 0" href="#" title="Refresh Image" onclick="securimageRefreshCaptcha('captcha_image', 'captcha_image_audioObj'); this.blur(); return false">&lt;img height="32" width="32" src="/securimage/images/refresh.png" alt="Refresh Image" onclick="this.blur()" style="border: 0px; vertical-align: bottom">&lt;/a>&lt;br />&lt;div style="clear: both">&lt;/div>&lt;label for="captcha_code">Type the text:&lt;/label> &lt;input type="text" name="captcha_code" id="captcha_code" autocomplete="off" required="1" >&lt;input type="hidden" id="captcha_image_captcha_id" name="captcha_id" value="5a8bbfe3b4c78c615754356f335fdea831d7f97c">
&lt;/div></code></pre>



<p>3.2RC3でのexample_form.php記述↓と比較してみると、</p>



<pre class="wp-block-code"><code>  &lt;p>
    &lt;img id="siimage" style="border: 1px solid #000; margin-right: 15px" src="./securimage_show.php?sid=&lt;?php echo md5(uniqid()) ?>" alt="CAPTCHA Image" align="left" />
    &lt;object type="application/x-shockwave-flash" data="./securimage_play.swf?bgcol=#ffffff&amp;amp;icon_file=./images/audio_icon.png&amp;amp;audio_file=./securimage_play.php" height="32" width="32">
    &lt;param name="movie" value="./securimage_play.swf?bgcol=#ffffff&amp;amp;icon_file=./images/audio_icon.png&amp;amp;audio_file=./securimage_play.php" />
    &lt;/object>
    &amp;nbsp;
    &lt;a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">&lt;img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0" />&lt;/a>&lt;br />
    &lt;strong>Enter Code*:&lt;/strong>&lt;br />
     &lt;?php echo @$_SESSION&#091;'ctform']&#091;'captcha_error'] ?>
    &lt;input type="text" name="ct_captcha" size="12" maxlength="8" />
  &lt;/p>
</code></pre>



<p>昔はフラッシュの利用を想定していたこと、音の再生と文字列変更がJavaScriptになったこと、securimage_show.phpのGETパラメータがsidからidになったことなどが異なる点か。</p>



<p>ということで、getCaptchaHtml が使えると楽なことはわかったが、デザイン的にHTMLを手で書きたい、特に今回は既存フォームの移行であり、getCaptchaHtmlを使わずにどうするかを考えた。<br>基本的には展開後のHTMLに相当するものを出せば良いわけだ。</p>



<p>PHP＋HTML記述例）</p>



<pre class="wp-block-code"><code>&lt;?php
	$set_captcha_id = md5(uniqid());
?>
&lt;img id="captcha_image" src="./securimage_render.php?id=&lt;?php echo $set_captcha_id; ?>" alt="CAPTCHA Image">

&lt;div id="captcha_image_audio_div">
&lt;audio id="captcha_image_audio" preload="none" style="display: none">
&lt;source id="captcha_image_source_wav" src="/securimage/securimage_play.php?id=&lt;?php echo $set_captcha_id; ?>" type="audio/wav">
&lt;/audio>
&lt;/div>

&lt;div id="captcha_image_audio_controls">
&lt;a class="captcha_play_button" href="/securimage/securimage_play.php?id=&lt;?php echo $set_captcha_id; ?>" onclick="return false">
【音を聞く】]&lt;/a>
&lt;/div>

&lt;script type="text/javascript" src="/securimage/securimage.js">&lt;/script>
&lt;script type="text/javascript">captcha_image_audioObj = new SecurimageAudio({ audioElement: 'captcha_image_audio', controlsElement: 'captcha_image_audio_controls' });&lt;/script>

&lt;div>
&lt;a href="#" onclick="securimageRefreshCaptcha('captcha_image', 'captcha_image_audioObj'); this.blur(); return false" class="link">【画像を変更】&lt;/a>
&lt;/div>

&lt;input type="text" name="captcha_code">
&lt;input type="hidden" name="captcha_id" id="captcha_image_captcha_id" value="&lt;?php echo $set_captcha_id; ?>"></code></pre>



<p>音声再生ボタンと、画像変更ボタンはテキストを想定した。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="274" height="173" src="https://s-pro4.com/wp-content/uploads/2024/12/securimage2.jpg" alt="" class="wp-image-868"/></figure>



<p>なお、PHP 8.3.10で試験をしたところ、Deprecated: が出た。</p>



<p>Deprecated: Creation of dynamic property Securimage::$code_entered is deprecated in &lt;path>/securimage/securimage.php on line 1028</p>



<p>Deprecated: Creation of dynamic property Securimage::$correct_code is deprecated in &lt;path>/securimage/securimage.php on line 1029</p>



<p>未定義プロパティへの代入として怒られた。<br>securimage.phpの適切な位置に宣言を入れておくことにした。</p>



<pre class="wp-block-code"><code>    private $code_entered;
    private $correct_code;</code></pre>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PHPバージョンアップしたらcreate_functionでエラーが出たので書き換えた</title>
		<link>https://s-pro4.com/page-783.html</link>
		
		<dc:creator><![CDATA[stakaha]]></dc:creator>
		<pubDate>Sat, 24 Aug 2024 02:57:09 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://s-pro4.com/?p=783</guid>

					<description><![CDATA[PHP 7.4からPHP 8.3へバージョンアップしたところ、WordPressが「重大なエラーが発生」的な感じで全く表示できなくなってしまった。WordPressのリカバリーモードなるものを初めて使用したところ、自作ウ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>PHP 7.4からPHP 8.3へバージョンアップしたところ、WordPressが「重大なエラーが発生」的な感じで全く表示できなくなってしまった。<br>WordPressのリカバリーモードなるものを初めて使用したところ、自作ウィジェットのcreate_functionでエラーになっているとわかった。</p>



<p>Uncaught Error: Call to undefined function create_function()</p>



<p>「create_function()はPHP 7.2で非推奨となり、PHP 8.0では完全に削除されました」とのこと。</p>



<pre class="wp-block-code"><code>class クラス名 extends WP_Widget {
	public function __construct() {
	...
	}
}

add_action('widgets_init', create_function('', 'return register_widget("クラス名");'))

書き換え後、

add_action('widgets_init', function() {
    return register_widget("クラス名");
});

</code></pre>



<p>これでエラー解消。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MAMPをインストールする</title>
		<link>https://s-pro4.com/page-680.html</link>
		
		<dc:creator><![CDATA[stakaha]]></dc:creator>
		<pubDate>Wed, 19 Jun 2024 16:23:58 +0000</pubDate>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web技術]]></category>
		<guid isPermaLink="false">https://s-pro4.com/?p=680</guid>

					<description><![CDATA[2022年3月にインストールをしたようだが、最初だけ少し使ってしばらく起動もしていなかったら、2024年の今、アプリケーションエラーが出るようになった。OSバージョンアップしているし、だめか。 もう一度最新版をインストー [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>2022年3月にインストールをしたようだが、最初だけ少し使ってしばらく起動もしていなかったら、2024年の今、アプリケーションエラーが出るようになった。<br>OSバージョンアップしているし、だめか。</p>



<p>もう一度最新版をインストールしてみる。</p>



<p>MAMP公式サイト）<br><a href="https://www.mamp.info/en/windows" target="_blank" rel="noreferrer noopener">https://www.mamp.info/en/windows</a></p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="984" height="920" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp1.jpg" alt="" class="wp-image-681" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp1.jpg 984w, https://s-pro4.com/wp-content/uploads/2024/06/mamp1-300x280.jpg 300w, https://s-pro4.com/wp-content/uploads/2024/06/mamp1-768x718.jpg 768w" sizes="(max-width: 984px) 100vw, 984px" /></figure>



<p>Free Downloadをクリックする。</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="980" height="908" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp2.jpg" alt="" class="wp-image-682" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp2.jpg 980w, https://s-pro4.com/wp-content/uploads/2024/06/mamp2-300x278.jpg 300w, https://s-pro4.com/wp-content/uploads/2024/06/mamp2-768x712.jpg 768w" sizes="(max-width: 980px) 100vw, 980px" /></figure>



<p>m1という表記はないが、ARM CPUを選択。</p>



<p>ダウンロードした、MAMP_MAMP_PRO_6.9-M1-arm.pkg を開く。</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="732" height="556" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp3.jpg" alt="" class="wp-image-683" style="width:562px;height:auto" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp3.jpg 732w, https://s-pro4.com/wp-content/uploads/2024/06/mamp3-300x228.jpg 300w" sizes="(max-width: 732px) 100vw, 732px" /></figure>



<p>「続ける」を何度か押し続けて、</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="625" height="444" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp4.jpg" alt="" class="wp-image-684" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp4.jpg 625w, https://s-pro4.com/wp-content/uploads/2024/06/mamp4-300x213.jpg 300w" sizes="(max-width: 625px) 100vw, 625px" /></figure>



<p>インストールをクリック。</p>



<p>アプリケーション下にインストールされる。</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="184" height="381" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp5.jpg" alt="" class="wp-image-685" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp5.jpg 184w, https://s-pro4.com/wp-content/uploads/2024/06/mamp5-145x300.jpg 145w" sizes="(max-width: 184px) 100vw, 184px" /></figure>



<p>MAMP PROも"勝手に"インストールされるが、それは使わず、MAMP/MAMP.appを使用する。</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="535" height="432" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp6.jpg" alt="" class="wp-image-686" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp6.jpg 535w, https://s-pro4.com/wp-content/uploads/2024/06/mamp6-300x242.jpg 300w" sizes="(max-width: 535px) 100vw, 535px" /></figure>



<p>デフォルトはWeb serverが ApacheでPHP version は7.4だった。<br></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="536" height="429" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp7.jpg" alt="" class="wp-image-687" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp7.jpg 536w, https://s-pro4.com/wp-content/uploads/2024/06/mamp7-300x240.jpg 300w" sizes="(max-width: 536px) 100vw, 536px" /></figure>



<p>PHP 8.2 へ変更。</p>



<p>とりあえず、「Start」して、localhost:8888 へアクセスすると普通にアクセスできた。</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="699" height="93" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp8.jpg" alt="" class="wp-image-688" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp8.jpg 699w, https://s-pro4.com/wp-content/uploads/2024/06/mamp8-300x40.jpg 300w" sizes="(max-width: 699px) 100vw, 699px" /></figure>



<p>OptionsのIndexesが有効になっていることもわかってしまった。これはあとでhttpd.confを編集しよう。</p>



<p>MAMPのデフォルトポートは、Apecheが8888、MySQLが8889ということで、ポート指定が若干面倒ではある。</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="521" height="339" src="https://s-pro4.com/wp-content/uploads/2024/06/mamp9.jpg" alt="" class="wp-image-689" style="width:562px;height:auto" srcset="https://s-pro4.com/wp-content/uploads/2024/06/mamp9.jpg 521w, https://s-pro4.com/wp-content/uploads/2024/06/mamp9-300x195.jpg 300w" sizes="(max-width: 521px) 100vw, 521px" /></figure>



<p>設定上はPortsで標準ポートの 80 と 3306へ変更が可能。</p>



<p>ただし、MAMPのポート設定はいじらない方が良いと言っている方を発見。<br>参考サイト）<br><a href="https://qiita.com/haruyan_hopemucci/items/0a98cac740c36c7c4bc3" target="_blank" rel="noreferrer noopener">https://qiita.com/haruyan_hopemucci/items/0a98cac740c36c7c4bc3</a></p>



<p>一応、ポート指定せず http://localhost でアクセスできるようになった。<br>エラーが出るようであればMAMPのデフォルトポートへ戻すか。様子見。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>phpによる画像リサイズをGDからImagickへ変更してみる</title>
		<link>https://s-pro4.com/page-383.html</link>
		
		<dc:creator><![CDATA[stakaha]]></dc:creator>
		<pubDate>Thu, 01 Feb 2024 17:16:30 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<guid isPermaLink="false">https://s-pro4.com/?p=383</guid>

					<description><![CDATA[画像リサイズを伴うシステムをサーバ移行したら使えなくなってしまった。Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg( [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p></p>



<p>画像リサイズを伴うシステムをサーバ移行したら使えなくなってしまった。<br>Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg()</p>



<p>imagecreatefromjpeg()が使えていなくてエラーですね。</p>



<p>参考ページ）<br><a href="https://pentan.info/php/gd_jpeg.html" data-type="link" data-id="https://pentan.info/php/gd_jpeg.html" target="_blank" rel="noreferrer noopener">https://pentan.info/php/gd_jpeg.</a><a href="https://pentan.info/php/gd_jpeg.html" data-type="link" data-id="https://pentan.info/php/gd_jpeg.html">html</a></p>



<p>phpinfo()では、GDはインストールされているようだが、JPG Supportがない</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="954" height="285" src="https://s-pro4.com/wp-content/uploads/2024/02/a554e5e3643ab77c96ff802fb7b97210.jpg" alt="" class="wp-image-379" srcset="https://s-pro4.com/wp-content/uploads/2024/02/a554e5e3643ab77c96ff802fb7b97210.jpg 954w, https://s-pro4.com/wp-content/uploads/2024/02/a554e5e3643ab77c96ff802fb7b97210-300x90.jpg 300w, https://s-pro4.com/wp-content/uploads/2024/02/a554e5e3643ab77c96ff802fb7b97210-768x229.jpg 768w" sizes="(max-width: 954px) 100vw, 954px" /></figure>



<p>libjpegを入れろということなのかな？</p>



<p>自分が触れないサーバだったため、サーバ管理者へインストールなど頼むのはちょっと申し訳ない。<br>ImageMagicを使う方法へ書き換えることにする。</p>



<p>昔作成したプログラム内で GIFの場合にはGDを使わなかったか何かトラブルがあって使えなかったかで、convertコマンドをexecから叩いて実行したことがあった。<br>exec('/usr/bin/convert '.$src.' -coalesce -resize '.$new_width.'x'.$new_height.' -deconstruct '.$dst);</p>



<p>$new_widthと$new_heightには、リサイズ後の画像幅と高さが入っている変数。<br>昔のことですっかり忘れていたが。<br>今回は、PHPでImageMagickを使えるようにする拡張モジュールImagickを使うことにする。</p>



<p>参考ページ）<br><a href="https://www.sejuku.net/blog/74338" target="_blank" rel="noreferrer noopener">https://www.sejuku.net/blog/74338</a></p>



<p> ■GD版（細かいところは省略）</p>



<pre class="wp-block-code"><code>list($cur_width, $cur_height) = getimagesize( $src );

$source = imagecreatefromjpeg( $src );
$resized = $this->getImageResizeResouce($source, $cur_width, $cur_height, $new_width, $new_height);
imagejpeg( $resized, $dst, 100 ); // 第三引数は画質、0〜100、デフォルト75

function getImageResizeResouce($source, $cur_width, $cur_height, $new_width, $new_height) {
  $resized = imagecreatetruecolor($new_width, $new_height);
  imagecopyresampled( $resized, $source, 0, 0, 0, 0, 
  $new_width, $new_height,
  $cur_width, $cur_height );
  return $resized;
} </code></pre>



<p>■Imagick版</p>



<pre class="wp-block-code"><code>$image = new Imagick($src); // コピー元の呼び出し
$image->thumbnailImage($new_width, $new_height); // リサイズ
$image->writeImage($dst); // 書き出し
$image->clear(); // 呼び出した画像情報を消す</code></pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
