|
|
|
อยากทราบวิธีการ Login โดยใช้ CURL ต่อเชื่อมต่อ server 2 ตัวครับ |
|
|
|
|
|
|
|
การใช้ curl เรียกโปรแกรม
คุณต้องเก็บ cookie เองครับ ทำ header ส่ง cookie เอง
Code (PHP)
curl_setopt($ch, CURLOPT_COOKIE, 'key=value;anotherkey=anothervalue');
แล้วจะใช้ cookie ทำไม ในเมื่อคุณสามารถกำหนดตัวแปรได้เองภายในโปรแกรม
เพื่อใช้ในการอ้างอิงได้นะครับ
ก็เรียก curl ธรรมดาๆ ก็พอแล้วมั้งครับ จะส่งแบบ post แบบ get ก็ว่ากันไป
http://php.net/manual/en/book.curl.php
|
ประวัติการแก้ไข 2015-04-11 07:59:52
|
|
|
|
Date :
2015-04-11 07:57:46 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะเพิ่ม trustee database ให้สามารถ connect จาก ip ที่กำหนดน่าจะดีกว่าไหมครับ
ไม่ต้องเรียกใช้ php จากเครื่อง 2 แต่เรียก database ตรงๆ เลย
|
|
|
|
|
Date :
2015-04-11 09:49:10 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<form name="login" action="http://www.gm4th.com/testlogin.php" method="post">
<table width="500" align="center">
<tr>
<td width="97">username :</td>
<td width="391"><label for="username"></label>
<input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td>password :</td>
<td><label for="password"></label>
<input type="text" name="password" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
if($_POST['submit'])
{
login_form($_POST['username'],$_POST['password']);
}
Code (PHP)
function login_form($username,$password)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.ชื่อเว็บ.com/testlogin.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."&password=".$password."");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
$ret = curl_exec($ch);
// Close handle
curl_close($ch);
return $ret;
}
โค้ดผมเป็นแบบนี้ครับ แต่ก็ไม่ได้ผม ส่วนตัวรับค่าจะเป็นแบบนี้ครับ
Code (PHP)
// Check GET
$username = check($_POST['username']);
$password = check($_POST['password']);
$hash = check($_POST['hash_code']);
$sys_id = check($_POST['system_id']);
$dt = check($_POST['dates']);
$tm = date("Y-m-d");
// GET RENT INFORMATION
$rent_sql = mysql_query("SELECT * FROM account_tbl WHERE username = '$username' AND password = '$password'");
$rent = mysql_fetch_array($rent_sql);
if(!$rent)
{
echo "<script langquage='javascript'>
alert('ข้อมูลเว็บตั้งค่าไม่ถูกต้องค่ะ');
window.location='http://www.เว็บ.com/';
</script>";
exit();
}
else
{
if($tm > $rent['dt_stop'])
{
echo "<script langquage='javascript'>
alert('ระบบเว็บหมดอายุแล้วค่ะ กรุณาต่ออายุด้วยค่ะ');
window.location='http://www.เว็บ.com/';
</script>";
exit();
}
else
{
setcookie('ifs_account', $_POST['user_id']);
echo "<script langquage='javascript'>
alert('เข้าสู่ระบบสำเร็จ');
window.location='http://127.0.0.1/index.php';
</script>";
exit();
}
}
|
|
|
|
|
Date :
2015-04-11 10:21:59 |
By :
banktakung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เป็นผมๆ จะไม่สนใจ cookie ครับ เพราะ run บน server
ทางฝั่ง client ไม่มีทางรู้ว่าเรา เรียกโปรแกรมอะไรจากไหน ใช้ database อะไรครับ
หรือใช้ โปรแกรมอะไรในการดึงข้อมูลมาแสดง
|
|
|
|
|
Date :
2015-04-11 14:20:19 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|