나는 매우 깐깐한 코더로 평범하지 않은 것을 알아 차렸다.PHP 코드 정리하기
내 코드를 살펴보고 코드를보다 효율적으로 작성하는 방법에 대한 정보를 얻을 수 있습니까? 개선하기 위해 무엇을 할 수 있습니까?
session_start();
/*check if the token is correct*/
if ($_SESSION['token'] == $_GET['custom1']){
/*connect to db*/
mysql_connect('localhost','x','x') or die(mysql_error());
mysql_select_db('x');
/*get data*/
$orderid = mysql_real_escape_string($_GET['order_id']);
$amount = mysql_real_escape_string($_GET['amount']);
$product = mysql_real_escape_string($_GET['product1Name']);
$cc = mysql_real_escape_string($_GET['Credit_Card_Number']);
$length = strlen($cc);
$last = 4;
$start = $length - $last;
$last4 = substr($cc, $start, $last);
$ipaddress = mysql_real_escape_string($_GET['ipAddress']);
$accountid = $_SESSION['user_id'];
$credits = mysql_real_escape_string($_GET['custom3']);
/*insert history into db*/
mysql_query("INSERT into billinghistory (orderid, price, description, credits, last4, orderip, accountid) VALUES ('$orderid', '$amount', '$product', '$credits', '$last4', '$ipaddress', '$accountid')");
/*add the credits to the users account*/
mysql_query("UPDATE accounts SET credits = credits + $credits WHERE user_id = '$accountid'");
/*redirect is successful*/
header("location: index.php?x=1");
}else{
/*something messed up*/
header("location: error.php");
}
전에 Codeigniter를 사용했지만 실제로 사용하지 않았습니다. –
그런데 어느 프레임 워크를 사용하고 있습니까? –
OR 매핑을 위해 PDO :: fetchObject()를 찾으십시오. – Danten