CodeIgniter - UserAgent - codeigniter

I have the below code to check if the user is coming from a mobile, if they are I want to load a different page but it doesn't seem to be working...
Can anyone shed any light on the below:
if($xmlRefresh==1) {
$viewData['content'] = $this->load->view('newquote/policy_xml', $viewData);
$this->load->view('layout', $viewData);
} elseif ($this->agent->is_mobile()) {
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData);
} else {
$this->_showPage("newquote/policy", 'Customise', $viewData);
}
I keep getting an internal server error, can anyone spot the problem...

Look at your system/core/Loader.php, function view() that will be $this->load->view returns void unless you add third parameter. try with:
$viewData2['content'] = $this->load->view('newquote/policy_xml', $viewData1, TRUE);
and
'''
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData2);
Note: $viewData2 is different with $viewData1

are you calling this in controller?
What is the 500 (internal server) error??
Did you load the library user_agent??
$this->load->library('user_agent');
if($xmlRefresh==1) {
$viewData['content'] = $this->load->view('newquote/policy_xml', $viewData);
$this->load->view('layout', $viewData);
} elseif ($this->agent->is_mobile()) {
$this->_showPage("newquote/policy_mobile", 'Customise', $viewData);
} else {
$this->_showPage("newquote/policy", 'Customise', $viewData);
}
Finally if you want serve the mobile pages, use post post or pre hooks to determine the user agent before view is executed (if you want to play around)

i have one idea, may be help u
you can replace redirect()/$this->load->view() to $this->_showPage("newquote/policy_mobile", 'Customise', $viewData);

Related

How To Check If Notification Is Sent Successfully In Laravel

I am unable to find in the documentation of how to handle the notification (what to do if notification is sent successfully or not)
NotificationController
public function AskForLevelUp()
{
$admin = User::where('is_admin', 1)->first();
$sendNotification = Notification::send($admin, new LevelUpNotification(Auth::user()->id));
if ($sendNotification->success()) // **HOW TO DO THIS CORRECTLY**
{
return back()->with('success', 'Your request has been submitted, please wait for admin confirmation.');
}
else
{
return back()->with('failure', 'Something went wrong, your request is not submitted. Please try again later.');
}
}
I've also read that send() has void return value here. Does anyone know how to handle this?

how to solve 419 PAGE EXPIRED, using laravel8 mongodb

Im using laravel 8 with jetstream authentication and bongodb before changing database from mysql to mongodb (using jenssegers/laravel-mongodb) it was everything work fine but when i use mongodb every post methode doesn't work it give me this erreur ('419 PAGE EXPIRED')
i know where is the probleme exactlty is in this function
namespace Illuminate\Foundation\Http\Middleware;
protected function inExceptArray($request)
{
foreach ($this->except as $except) {
if ($except !== '/') {
$except = trim($except, '/');
}
if ($request->fullUrlIs($except) || $request->is($except)) {
return true;
}
}
return false;
}
i dont know what i miss why it always return false
I changed to SESSION_DRIVER=fil and it worked for me

In Swiftui, how to check the content from a URLsession?

I am using SwiftUI in Xcode 11, trying to check the content of a .txt file from the internet.
The problem is that the URLSession.shared.downloadTask takes time to finish. The code to check the content is always performed before the download is finished. Can anyone help me please? Thanks very much.
Sorry, forgot to add some codes.
let url = URL(string: "https://www.myweb.com/myfile.txt”)!
var myweb = “test”
URLSession.shared.downloadTask(with: url) { localURL, response, error in
if let localURL = localURL {
do { try myweb = String(contentsOf: localURL)}
catch { print (“test”) }
}
}.resume()
if myweb != “test” { Call some function here}
I assume that you need to create ViewModel with Published property and change it flag on true statement if downloadTask has finished. Use this property inside View

Webhook function does not execute

I have this code to add user credit to a user when a payment is made
class Webhook extends Controller
{
public function rave(Request $request){
if(Request::input('pay.type') == "credits" and Request::get('price') == 500 ){
$credit = Credit::firstOrCreate(['user_id' => Auth::getUser()->id]);
$credit->increment('amount', 600);
$credit->refresh();
}
}
}
The code works well when i try it as an ajax call attached to a button but it does not execute with a returned webhook response even tho it is returned with a 200 ok when inspected with ngrok.
What might be the reason?
You're not actually returning anything. I'm not sure what kind of response you expect, but try returning something inside if block and see if that nudges you in the right direction.
if ($request->input('pay.type') == 'credits' && $request->input('price') == 500) {
$credit = Credit::firstOrCreate(['user_id' => Auth::user()->id]);
$credit->increment('amount', 600);
$credit->refresh();
return $credit->amount;
}

Why the else statement not working here?

The following code can't get correct response under the else statment:
function ajax_response(){
if(is_user_logged_in() && check_key() ){
$result = $do_something;
if($result){
ajax_response_string(1,'success!');
}else{
ajax_response_string(-1,'there is a problem, please try again!');
}
}else{
ajax_response_string(-1,'you must login first.');
}
}
When I log-out and try to click the link that trigger this ajax function, I got a response of "undefined", it is supposed to be "you must login first". Where I've gone wrong?
I just figured it out-- it's not the else statement, it's the ajax response url not working for logged out users. So, my question is not valid anymore. Please close it if necessary.
You have a syntax error at line $result= //do something because this line is not terminated. Try this:
function ajax_response()
{
if(is_user_logged_in() && check_key() )
{
$result = doSomething; //error was here as there was no line terminator (;) present.
if($result)
{
ajax_response_string(1,'success!');
}
else
{
ajax_response_string(-1,'there is a problem, please try again!');
}
}
else
{
ajax_response_string(-1,'you must login first.');
}
}

Resources