質問 > その他 > file_get_contents()を使った自動ログイン処理がうまく動きません。 |
その他
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | 下へ |
投稿者 | スレッド |
---|---|
ynuma |
投稿日時: 2015/7/8 13:56
対応状況: 確認中
|
新米 登録日: 2014/3/24 居住地: 投稿: 1 |
file_get_contents()を使った自動ログイン処理がうまく動きません。 外部システムからIDとパスワードを渡して、EC-CUBEに自動ログインさせるプログラムを考えています。
下記のようなサンプルプログラムを作って実行しましたら、次のエラーが発生しました。 ※ドメイン、メール等、一部「xxx」で伏字にしています Warning: file_get_contents(http://xxx.xxx.xxx.xxx/shop/frontparts/login_check.php): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /export/sd210/www/jp/r/e/gmoserver/6/1/sd0454461/xxx.xxx.xxx.xxx/eccube_ex1.php on line 38 試行錯誤しまして、POSTデータを設定している下記の1行をコメントにすると エラーは出なくなるのですが、未ログインの状態でトップページが表示されます。 "transactionid" => $transactionid, これを渡さない事にはログインが出来ないのでコメントにするわけにはいかず 指定すると上記のエラーが出て手詰まり状態です。 何か改善方法がないか、または、別の方法で自動ログイン出来ないか 情報をいただけると助かります。 よろしくお願いいたします。 ---サンプルプログラム--- <?php $html = file_get_contents('http://xxx.xxx.xxx.xxx/shop/'); if (preg_match("/name=\"transactionid\" value=\"(.+?)\"/", $html, $match)) { //echo $match[0]; $pos = strpos($match[0], "value=\""); //echo str_replace("\"", "", substr($match[0], $pos+7)); $transactionid = str_replace("\"", "", substr($match[0], $pos+7)); //echo $transactionid; //post date $data = array( "mode" => "login", "transactionid" => $transactionid, "url" => "/shop/", "login_email" => "xxx@xxx.xxx.xxx", "login_memory" => "1", "login_pass" => "xxxxx" ); $data = http_build_query($data, "", "&"); //header $header = array( "Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($data) ); $opts = array( "http" => array( "method" => "POST", "header" => implode("\r\n", $header), "content" => $data ) ); $context = stream_context_create($opts); echo file_get_contents('http://xxx.xxx.xxx.xxx/shop/frontparts/login_check.php', false, $context); } ?> |
tsuji |
投稿日時: 2015/7/14 9:31
対応状況: −−−
|
仙人 登録日: 2013/11/19 居住地: 投稿: 958 |
Re: file_get_contents()を使った自動ログイン処理がうまく動きません。 ynuma 様
> 何か改善方法がないか、または、別の方法で自動ログイン出来ないか > 情報をいただけると助かります。 外部システムとの連携でしたら、EC-CUBEのAPI機能をカスタマイズして 作成するという手もあります。
|
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | トップ |