半角でしたら送信、全角でしたらとめて、警告文を出すという思考方法なんですが、今は半角全角関係なくメールが送信されます。elseでexit入れてみましたが、ダメでした。何かいい方法ありますでしょうか
回答よろしくお願いいたします。
csv.php
php
1<?php 2session_start(); 3$_SESSION['ticket'] = SHA1(uniqid().mt_rand()); 4 5 6 7$csv = fopen('text.csv', 'a'); 8fputcsv($csv, $_POST); 9fclose($csv); 10 11 12if (isset($_POST['moji'])){ 13 $moji=$_POST['moji']; 14}else{ 15 $moji=""; 16} 17 18 19 ?> 20 21 22<!DOCTYPE html> 23<html> 24<head> 25 26 27 28 <meta charset="utf-8"> 29 <title>php</title> 30</head> 31<body> 32<form action="send.php" method="post" name="form"> 33 34<?php 35 36 if (preg_match('/^[a-zA-Z0-9]+$/', $moji)) { 37 38 echo "送信完了"; 39 }else{ 40 echo "半角を入れてください"; 41 } 42 43?> 44 45<input type="text" name="moji"> 46 47 48 <input type="hidden" name="ticket" value="<?php echo htmlspecialchars($_SESSION["ticket"], ENT_QUOTES);?>"> 49 50 51<input type="submit" name="submit" value="送信する"> 52 53</form> 54</body> 55 </html>
send.php
php
1<?php 2session_start(); 3 4 5if(isset($_POST['moji'])){ 6$moji=$_POST['moji']; 7} 8 9 10 11if(isset($_POST["submit"], $_SESSION["ticket"]) && $_SESSION["ticket"] == $_POST["ticket"]){ 12 unset($_SESSION["ticket"]); 13 }else{ 14 header('Location: csv.php'); 15 exit(); 16 17} 18 19 20 21 mb_language("Japanese"); 22 mb_internal_encoding("UTF-8"); 23 $to = "xxxxxxxx"; 24 $title = "xxxxxxxxxx"; 25 $content = "$moji\n"; 26 $from = "From:xxxxxxxxxx\r\n"; 27 $from .= "Return-Path: xxxxxxxxx"; 28 $send_mail = mb_send_mail($to, $title, $content, $from); 29 30?>
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。