อยากจะทราบวิธีการดึง url ที่user กดส่งข้อมูลมา และนำเก็บลงฐานข้อมูล
Code (PHP)
$_SERVER['HTTP_REFERER']
Date :
2011-03-02 10:39:44
By :
PlaKriM
แล้วคุณรับข้อมูลที่ user ส่งมายังไงละครับ ไปใช้ ตัวที่ผมบอกตรงนั้นแหละ แล้วลอง echo ออกมาดู
Date :
2011-03-02 13:57:14
By :
PlaKriM
เอาไปบันทึกลงฐานข้อมูลอะไรก็ว่าไปครับ
Date :
2011-03-03 10:26:40
By :
PlaKriM
<?php
/* config start */
$emailAddress = '';
/* config end */
require "phpmailer/class.phpmailer.php";
session_name("fancyform");
session_start();
foreach($_POST as $k=>$v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k]=stripslashes($_POST[$k]);
$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}
$err = array();
if(!checkLen('name'))
$err[]='The name field is too short or empty!';
if(!checkLen('email'))
$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
$err[]='Your email is not valid!';
if(!checkLen('phone'))
$err[]='The phone field is too short or empty!';
if(!checkLen('subject'))
$err[]='You have not selected a subject!';
if(!checkLen('message'))
$err[]='The message field is too short or empty!';
if((int)$_POST['captcha'] != $_SESSION['expect'])
$err[]='The captcha code is wrong!';
if(count($err))
{
if($_POST['ajax'])
{
echo '-1';
}
else if($_SERVER['HTTP_REFERER'])
{
$_SESSION['errStr'] = implode('<br />',$err);
$_SESSION['post']=$_POST;
header('Location: '.$_SERVER['HTTP_REFERER']);
}
exit;
}
$msg=
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />
Message:<br /><br />
'.nl2br($_POST['message']).'
';
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";
$mail->MsgHTML($msg);
$mail->Send();
unset($_SESSION['post']);
if($_POST['ajax'])
{
echo '1';
}
else
{
$_SESSION['sent']=1;
if($_SERVER['HTTP_REFERER'])
header('Location: '.$_SERVER['HTTP_REFERER']);
echo "come from " . $_SERVER;
exit;
}
function checkLen($str,$len=2)
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
mysql_connect("localhost","root","2565");
mysql_select_db("contact");
$strSQL = "INSERT INTO contact (name,email,phone,subject,message) VALUES ('".$_POST["name"]."',
'".$_POST["email"]."','".$_POST["phone"]."','".$_POST["subject"]."','".$_POST["message"]."')";
$objQuery = mysql_query($strSQL);
mysql_close();
?>
Date :
2011-03-03 10:29:57
By :
crazy_boy
ติดแง๊กอยู่คับ
Date :
2011-03-03 10:53:10
By :
crazy_boy
Code (PHP)
<?php
session_name("fancyform");
session_start();
$_SESSION['n1'] = rand(1,20);
$_SESSION['n2'] = rand(1,20);
$_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2'];
$str='';
if($_SESSION['errStr'])
{
$str='<div class="error">'.$_SESSION['errStr'].'</div>';
unset($_SESSION['errStr']);
}
$success='';
if($_SESSION['sent'])
{
$success='<h1>Thank you!</h1>';
$css='<style type="text/css">#contact-form{display:none;}</style>';
unset($_SESSION['sent']);
}
$objConnect = mysql_connect("localhost","root","2565");
if($objConnect)
{
echo "Database Connected.";
$from = "";
}
else
{
echo "Database Connect Failed.";
}
mysql_close($objConnect);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact form</title>
<link rel="stylesheet" type="text/css" href="jqtransformplugin/jqtransform.css" />
<link rel="stylesheet" type="text/css" href="formValidator/validationEngine.jquery.css" />
<link rel="stylesheet" type="text/css" href="demo.css" />
<?=$css?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jqtransformplugin/jquery.jqtransform.js"></script>
<script type="text/javascript" src="formValidator/jquery.validationEngine.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="main-container">
<div id="form-container">
<h1><img src="../web3/img/logo_web_innovation.png" width="92" height="79" /></h1>
<h1>Contact Us</h1>
<h2>www.webinnovation.</h2>
<form id="contact-form" name="contact-form" method="post" action="submit.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="15%"><label for="name">Name</label></td>
<td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td><label for="email">Email</label></td>
<td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>
<td> </td>
</tr>
<tr>
<td><label for="email">Phone</label></td>
<td><input type="text" name="phone" id="phone" value="<?=$_SESSION['post']['phone']?>" /></td>
<td> </td>
</tr>
<tr>
<td><label for="subject">Subject</label></td>
<td><select name="subject" id="subject" value="<?=$_SESSION['post']['subject']?>">
<option value="" selected="selected"> - Choose -</option>
<option value="Question">Question</option>
<option value="Business proposal">Business proposal</option>
<option value="Advertisement">Advertising</option>
<option value="Complaint">Complaint</option>
</select></td>
<td> </td>
</tr>
<tr>
<td valign="top"><label for="message">Message</label></td>
<td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td>
<td valign="top"> </td>
</tr>
<tr>
<td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>
<td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>
<td><input name="ref" type="hidden" value="<?php echo "$from"; ?>" /></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"></td>
<td colspan="2"><input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
<?=$str?> <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td>
</tr>
</table>
</form>
<?=$success?>
</div>
<div class="tutorial-info"><?php
echo "Referer: " .
$_SERVER["HTTP_REFERER"] . "<br />";
echo "Browser: " .
$_SERVER["HTTP_USER_AGENT"] . "<br />";
echo "User's IP address: " .
$_SERVER["REMOTE_ADDR"];
?></div>
</div>
</body>
</html>
Date :
2011-03-04 10:17:49
By :
crazy_boy
Code (PHP)
<td><input name="ref" type="hidden" value="<?php echo $_SERVER["HTTP_REFERER"]; ?>" /></td>
Date :
2011-03-04 10:53:52
By :
PlaKriM
Load balance : Server 01