Q - Notice: Undefined variable: response in D:\xampp\htdocs\tools_joomla\tools\convert-area\index.php on line 140

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

Parichat
PHP VIP Members
PHP VIP Members
โพสต์: 4859
ลงทะเบียนเมื่อ: 08/01/2018 10:03 am

Q - Notice: Undefined variable: response in D:\xampp\htdocs\tools_joomla\tools\convert-area\index.php on line 140

โพสต์ที่ยังไม่ได้อ่าน โดย Parichat »

Q - Notice: Undefined variable: response in D:\xampp\htdocs\tools_joomla\tools\...\index.php on line 140

Error Undefined variable: response in D:\xampp\htdocs\tools_joomla\tools\...\index.php on line 140
Error ไม่มีตัวแปร response แต่ในโค้ดประกาศตัวแปรไว้เรียบร้อยแล้วดังโค้ด

โค้ด: เลือกทั้งหมด

$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkeyrecaptcha . "&response=" . $keyrecaptcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']), true);

//เรียกใช้ตัวแปร $response
if (isset($_POST['name']) && $response['success'] == true) {
                            echo '<input type = "hidden" name = "id" value = "' . $_POST['name'] . '" />';
                            }
แก้ไขอย่างไรค่ะ
ขอบคุณค่ะ
Live Simply, Laugh Often, Love Deeply.....
Parichat
PHP VIP Members
PHP VIP Members
โพสต์: 4859
ลงทะเบียนเมื่อ: 08/01/2018 10:03 am

Re: Q - Notice: Undefined variable: response in D:\xampp\htdocs\tools_joomla\tools\convert-area\index.php on line 140

โพสต์ที่ยังไม่ได้อ่าน โดย Parichat »

ปัญหา
เกิดจากประกาศตัวแปรคนละเงื่อไขกัน

วิธีแก้ไข
ย้ายตัวแปรที่ประกาศไว้มาวางไว้ในเงือนไขที่โปรแกรมทำงาน ดังโค้ด

โค้ด: เลือกทั้งหมด

if(.,.,.){
//...
}else {

	$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkeyrecaptcha . "&response=" . $keyrecaptcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']), true);
	if (isset($_POST['name']) && $response['success'] == true) {
		echo '<input type = "hidden" name = "id" value = "' . $_POST['name'] . '" />';
	}
}
Live Simply, Laugh Often, Love Deeply.....
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: Bing [Bot] และบุคลทั่วไป 82