php - Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\test -
in website using infobip 2-factor authentication security purpose. got code in website showing error
fatal error: class 'httprequest' not found in c:\xampp\htdocs\test\otp\send.php on line 2
code following:
send.php
<?php $request = new httprequest(); $request->seturl('https://oneapi.infobip.com/2fa/1/pin'); $request->setmethod(http_meth_post); $request->setheaders(array ('accept' => 'application/json' ,'content-type' => 'application/json' ,'authorization' => 'app secret_key')); $request->setbody('{ "applicationid": "your_application_id", "messageid": "your_message_id", "to": "phone_number" }'); try { $response = $request->send(); echo $response->getbody(); } catch (httpexception $ex) { echo $ex; } ?>
this following code request , showing
fatal error: class 'httprequest' not found in c:\xampp\htdocs\test\otp\request.php on line 3
request.php
<?php $request = new httprequest(); $request->seturl('https://oneapi.infobip.com/2fa/1/pin/{pin_id}/verify'); $request->setmethod(http_meth_post); $request->setheaders(array('accept' => 'application/json', 'content-type' => 'application/json','authorization' => 'app your_api_key' )); $request->setbody('{"pin": "pin_code"}'); try { $response = $request->send(); echo $response->getbody(); } catch (httpexception $ex) { echo $ex; } ?>
ok have file httprequest.php in same folder , in file
class httprequest { ... }
then somewhere before calling it, need tell php it. done using 1 of 4 ways, way
require_once __dir__.'/httprequest.php'; //assuming it's in same folder.
remember isn't magic, it's computer code. knows tell it. hope place got code have kind of basic instructions on how install set up, , read that.
now not confuse choices
include include_once require require_once
i put these here illustrate that, things ( ) mean in programing. include, includes it, adding *_once, once, , require throw error if it's not found in location specified, making required. whereas include doesn't care if included or not.
good luck! happy coding.
Comments
Post a Comment