Rất nhiều bên sử dụng cho website php thuần, nay mình chia sẻ cho bạn code form tìm kiếm nguồn hàng order trung quốc tại các trang như: taobao, 1688, tmall
Đầu tiên bạn tạo một file php timkiem.php với đoạn code như sau ngang hàng với Root:
$apiKey = '< Điền API của bạn vào đây >'; $urlget = $_POST['urlweb']; echo $urlget; $text = $_POST['textpost']; $url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($text) . '&source=vi&target=zh-CN'; $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($handle); $responseDecoded = json_decode($response, true); $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); //Here we fetch the HTTP response code curl_close($handle); switch ($urlget) { case 'tmall': $url = 'https://list.tmall.com/search_product.htm?q='; break; case '1688': $url = 'https://s.1688.com/selloffer/offer_search.htm?_input_charset=utf-8&button_click=top&earseDirect=false&n=y&keywords='; break; default: $url = 'https://s.taobao.com/search?q='; break; } header($url .''. $responseDecoded['data']['translations'][0]['translatedText']);
Sau đó bạn tạo một đoạn code HTML form tìm kiếm như sau ở trang chủ hoặc để bất cứ đâu:
<div class="box-search"> <div class="form-group" id="search-translate-box"> <form action="/timkiem.php" target="_blank" method="POST"> <select class="box-se1" name="urlweb"><option value="taobao">TAOBAO</option><option value="tmall">TMALL</option><option value="1688">1688</option></select> </div> <div class="form-group" id="search-translate-box"><input type="text" class="box-se2" id="q" placeholder="VD: Quần áo trẻ em cho bé gái..." formtarget="_blank" name="textpost"><p></p> </div> <div class="form-group" id="search-translate-box"><button class="box-se btns" type="submit" style="background: rgb(246, 130, 31); width: 100%; "><i class="fa fa-search" aria-hidden="true"></i> TÌM KIẾM</button></form ></div> </div>
Cuối cùng là test thử đoạn code để test xem có chuyển hướng và dịch đúng nghĩa không ?
Với code này ai biết biến tấu sẽ chuyển sang dùng qua thằng WordPress.