<?php try { require_once "timeline.php"; if (preg_match("/^[a-zA-Z]+(?:[\\s-][a-zA-Z]+)*\$/", $_POST["author"])) { $timeline = new TimeLine(); $author = $_POST["author"]; $contents = htmlspecialchars($_POST["contents"]); $tweets = $author . "," . $contents; $timeline->add($tweets); header("Location:index.php"); } else { header("Loaction:error.php"); } } catch (Exception $e) { header("Loaction:error.php"); }
<?php # Ex 4 : Write a tweet require_once "timeline.php"; $timeline = new TimeLine(); try { $content = htmlspecialchars($_POST['content']); $regex = "/^([a-zA-Zㄱ-ㅎ가-힣] |[a-zA-Zㄱ-ㅎ가-힣]-|[a-zA-Zㄱ-ㅎ가-힣]){0,19}[a-zA-Zㄱ-ㅎ가-힣]\$/"; if (preg_match($regex, $_POST['author'])) { $tweet = array(); array_push($tweet, $_POST['author']); array_push($tweet, $content); $timeline->add($tweet); header("Location:index.php"); // redirect to index.php } else { header("Location:error.php"); } } catch (Exception $e) { header("Location:error.php"); }
<?php # Ex 4 : Write a tweet try { $i_type = $_GET["i_type"]; $i_text = $_GET["i_text"]; if (empty($i_type) == false && empty($i_text) == false) { $remove_tag = strip_tags($i_text); $reg_ex = "/^(([a-zA-Z][\\-|\\s]?){1,20}([a-zA-Z]))\$/"; if (preg_match($reg_ex, $i_type)) { #call add function require_once 'timeline.php'; $i_class = new TimeLine(); $i_class->add($i_type . "|" . $remove_tag); #redirect (don't modify) header("Location:index.php"); } else { #redirect (don't modify) header("Loaction:error.php"); } } } catch (Exception $e) { #redirect (don't modify) header("Loaction:error.php"); }
<?php # Ex 4 : Write a tweet try { include "timeline.php"; $database = new TimeLine(); $content = $_POST["content"]; $content = htmlspecialchars($content); if (preg_match("/^([a-zA-Z]+\\-{0,1}[a-zA-Z]*)+\\s{0,1}([a-zA-Z]+\\-{0,1}[a-zA-Z]*)*\\s{0,1}([a-zA-Z]+\\-{0,1}[a-zA-Z]*)*[a-zA-Z]\$/", $_POST["author"]) && strlen($_POST["author"]) >= 1 && strlen($_POST["author"]) <= 20) { //validate author & contents $database->add(array($_POST["author"], $content)); header("Location:index.php"); //redirect to index.php } else { header("Location:error.php"); } } catch (Exception $e) { header("Loaction:error.php"); }
<?php include 'timeline.php'; # Ex 4 : Write a tweet try { if (preg_match("/^(?=.{1,20}\$)([a-zA-z]+[\\-\\s]?[a-zA-z]+)*[a-zA-Z]\$/", $_POST["author"])) { #validate author & content call add function $content = htmlspecialchars($_POST['content']); #insert into table $timeline = new TimeLine(); $timeline->add(array($_POST["author"], $content)); header("Location:index.php"); #redirect to index.php } else { header("Location:error.php"); } } catch (Exception $e) { header("Location:error.php"); }
<?php # Ex 4 : Write a tweet try { include "timeline.php"; if (!empty($_POST["author"]) && !empty($_POST["content"]) && preg_match('/^[a-zA-Z]((-|\\s)?[a-zA-Z]){0,19}$/', $_POST["author"])) { $author = $_POST["author"]; $content = htmlspecialchars($_POST["content"]); //$content = $_POST["content"]; $toadd = array($author, $content); $tl = new TimeLine(); $tl->add($toadd); header("Location:index.php"); } else { //echo "else"; header("Location:error.php"); } } catch (Exception $e) { header("Location:error.php"); } // && preg_match('/^[a-zA-Z]+(-[a-zA-Z]+)*(\s?[a-zA-Z]+(-[a-zA-Z]+)*)*$/', $_POST["author"]) //!empty($_POST["author"]) && !empty($_POST["content"]) //^[4][0-9]{15}
<?php require_once 'timeline.php'; # Ex 4 : Write a tweet try { $timeline = new TimeLine(); $timeline->add(array("author" => $_POST['author'], "contents" => $_POST['content'])); header("Location:index.php"); /* if () { validate author & content call add function header("Location:index.php"); redirect to index.php 마지막 } else { header("Loaction:error.php"); } */ } catch (Exception $e) { header("Loaction:error.php"); }
<?php include "timeline.php"; $timeline = new TimeLine(); # Ex 4 : Write a tweet try { $author = $_POST["input_author"]; $contents = htmlspecialchars($_POST["input_contents"]); if (preg_match("/^[a-zA-Z]+((\\s{1}|\\-{1}){1}[a-zA-Z]+)*\$/", $author) && 1 <= strlen($author) && strlen($author) <= 20) { //validate author & content if ($contents != "") { $input_tweet = array($author, $contents); $timeline->add($input_tweet); header("Location:index.php"); } else { header("Location:error.php"); //contents에 아무것도 입력하지 않았을 때에는 error } } else { header("Location:error.php"); } } catch (Exception $e) { header("Location:error.php"); }