<?php
$takenUsernames = array ('bill', 'ted');
sleep(2);
if (!in_array( $_REQUEST['username'], $takenUsernames )) {
echo
'okay';
} else {
echo 'denied';
}
?>
같은 소스
<%
String[] usernames = { "bill", "tes" };
Thread.sleep(2000);
String input_name = null;
if(request.getParameter("username")!=null) {
input_name = request.getParameter("username");
}
for(int i=0; i<usernames.length; i++) {
if(input_name!=null) {
if(usernames[i].equals(input_name)) {
out.println("okay");
break;
}
}
out.println("denied");
}
%>
==================================================================
PHP소스
$i++;
$str .= "no". $i . "=" . $no . "&";
$str .= "name" . $i . "="
. $name . "&";
$str .= "title" . $i . "=" . $title . "&";
$str
.= "message" . $i . "=" . $message . "&";
$str .= "email" . $i . "=" .
$email . "&";
$str .= "ip" . $i . "=" . $ip . "&";
$str .= "hit"
. $i . "=" . $hit . "&";
$str .= "w_date" . $i . "=" . $w_date .
"&";
}
JSP소스
i++;
str += "no"+ i + "=" + no + "&";
str += "name" + i + "=" +
name + "&";
str += "title" + i + "=" + title + "&";
str +=
"message" + i + "=" + message + "&";
str += "email" + i + "=" + email +
"&";
str += "ip" + i + "=" + ip + "&";
str += "hit" + i + "=" +
hit + "&";
str += "w_date" + i + "=" + w_date + "&";
}
==================================================================
<?php
$hostname_localhost
="localhost";
$database_localhost ="mydatabase";
$username_localhost
="root";
$password_localhost ="";
$localhost =
mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost,
$localhost);
$username = $_POST['username'];
$password =
$_POST['password'];
$query_search = "select * from tbl_user where username =
'".$username."' AND password = '".$password. "'";
$query_exec =
mysql_query($query_search) or die(mysql_error());
$rows =
mysql_num_rows($query_exec);
//echo $rows;
if($rows == 0) {
echo "No
Such User Found";
}
else {
echo "User Found";
}
?>
같은소스
<%@ page language="java" import="java.sql.*"session="true"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String
driverName="com.mysql.jdbc.Driver"; String url =
"jdbc:mysql://localhost:3306/디비명"; String id = "아이디"; String pwd ="비번"; String
userName = request.getParameter("username"); String userPass =
request.getParameter("password"); if(userName == null ||
userName.trim().equals("")) { out.println("userName Error!"); return; }
if(userPass == null || userPass.trim().equals("")) { out.println("userPass
Error!"); return; } try { Class.forName(driverName); }
catch(ClassNotFoundException e) { out.println("MySQL JDBC Driver Loading
Error!"); out.println(e.toStirng()); return; } try { Connection conn =
DriverManager.getConnection(url, id, pwd); } catch(Exception e) {
out.println("MySQL Connection Error!"); out.println(e.toStirng()); return;
} try { String sql = "select count(*) from tbl_user where username = ? AND
password = ?"; PreparedStatement ps = conn.prepareStatement(sql);
ps.seetString(1, userName); ps.seetString(2, userPass); ResultSet rs =
ps.executeQuery(); rs.next(); int count = rs.getInt(1); if(count >
0) { out.println("User Found"); } else { out.println("No Such
User Found"); } } catch(Exception e) { out.println("rs.next()
Error!"); out.println(e.toStirng()); return; } if(rs != null) rs.close();
if(ps != null) ps.close(); if(conn != null) conn.close(); %>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
오늘은 여기까지....정말 엉망진창이다.
<!--
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040201&docId=101211391&qb=cGhw66W8IGpzcOuhnA==&enc=utf8§ion=kin&rank=39&search_sort=0&spq=0&sp=4
http://mirwebma.tistory.com/66
http://comcs.tistory.com/18
http://habony.tistory.com/70#.U3My6Pl_vf0
-->
'차근차근 > PHP' 카테고리의 다른 글
foreach (0) | 2014.08.28 |
---|---|
무작정 자료수집2 (0) | 2014.07.30 |
무작정 자료수집4 (0) | 2014.07.30 |
CXEC(); PHP에서 외부프로그램 실행 (0) | 2014.07.30 |
디렉토리 함수 목록 (0) | 2014.07.30 |