Help with error 'please log in" after logged-in

The php web video script that I’m using has the capability to search for a video, select it, then select ‘proceed’ to view.

After logging-in and searching, selecting a video choice, and then ‘proceed’ is selected, this error appears “Something went wrong. Please Log-In!!”

The js looks like this:

...
function PT_MultipleBuyVideo() {
    var checked = getSelectedVideos();
    if (!checked) { return false; }

    swal({
        title: "",
        type: "info",
        html:"Proceed",
        showCancelButton: true,
        cancelButtonText: "Close",
        customClass: 'sweetalert-lg',
        confirmButtonText:'Proceed'
    }).then(function(){

        $.ajax({
            url: PT_Ajax_Requests_File() + 'aj/buy-video',
            type: 'POST',
            dataType: 'json',
            data: {id:checked},
        }).done(function(data){
            if (data.status == 200) {
                for (var i = 0; i < checked.length; i++) {
                    var button = $("button[data-action='multiple_select_button'][data-id='" + checked[i] + "']")
                    buttonMultipleSelectingStyle(button, 'purchased');
                }

                swal({
                    title: "Success",
                    type: "success",
                    html:"",
                    showCancelButton: true,
                    cancelButtonText: "Close",
                    customClass: 'sweetalert-lg',
                    confirmButtonText:'Go To Video(s)'
                }).then(function(){
                    window.location.href='/paidvid';
                });

            } else {
                if (data.error_num == 1) {
                    swal(
                        'Error!',
                        'zero balance',
                        'error'
                    );
                } else {
                    swal(
                        'Error!',
                        'Something went wrong. Please Log-In!!',
                        'error'
                    );
                }
            }
        }).fail(function() {
            swal(
                'Error!',
                'Something went wrong. Please try again later',
                'error'
            );
        })
    });
}
...

If this is at all helpful, here is the beginning php looks like this:

<?php
ob_start();

if (IS_LOGGED == false) {
    $data = array('status' => 400, 'error' => 'Not logged in');
    echo json_encode($data);
    exit();
}

...

Any ideas on what I might look into regarding why a ‘please log in’ error appears after logging-in, is welcomed.

Ajax succeeds on values other than just 200. I recommend that you output the status number so that you can learn more about what’s happening there.

Thanks for your reply.
I know very little about javascript code in this web script.
Any additional help with “output the status number” is appreciated.

What I mean is to add data.status to the error message, to help aid the investigation.

Thank you for your reply, but I don’t understand.

Does it make sense that you need to find out more information about why the problem is happening?

Yes, but don’t I need to know what is causing the error to assign a status code to it to display upon future errors?

No you don’t. You just need to output the data.status value when you show the error, letting you see precisely what the error status number is.

Thanks. I don’t know how to add data.status to the error message.
any further guidance is appreciated

Well a plus sign after the string followed with data.status seems to do the job.

Thanks again. Which string?

One of the ones that appear when the error occurs, would do.

Thanks but your replies.

I added this + data.status :

'Something went wrong. Please Log-In!!' + data.status,

and see 'Something went wrong. Please Log-In!!'400

Good, so that’s telling you that a 400 error is occurring.

There are some good details about diagnosing 400 errors at

1 Like

Thanks again for your reply/info.
I believe that the issue might have to do with a users’ session, being that if you’re not logged-in and you search for a video, select it, then select ‘proceed’ to view, this same error appears “Something went wrong. Please Log-In!!”, so whether you’re logged in or not - same outcome. And your link talked a bit about the 400 error and about log in log out.

In the js code I posted, after ‘Proceed’ the code shows either Success, Please Log In, or Not enough Money. So, you can’t Proceed to buy if you’re not logged-in. But that error is being triggered when a User is Logged-in, so maybe the code isn’t seeing a 'session" begin upon log in?

It seems from the JS code that you can’t Proceed to ‘aj/buy-video’ unless you are in 'session". Does that sound correct?

I showed the beginning lines of code in php above for the buy-video file, does that look correct to determine if a session has begun? That file has this code regarding a session key. Maybe you could suggest where I would look next, to resolve this:

// add data to paid table
$insert_buy = $db->insert('paid_vids', [
'id_user' => $user_id,
'video_play_price' => (string)$video_cost_new,
'id_video' => $video_id,
'user_id_uploaded' => $video->user_id, 
'video_title' => $video->title, 
'earned_amount' => $up_amount,
'time' => $time_start,
'short_id' => $video->short_id,
'session_key' => $_SESSION['session_key']
]);

Any additional suggestions are appreciated.

the ajax and the file aj/buy-video. You can’t buy unless you’re logged-in,

I recommend following the troubleshooting guide at https://airbrake.io/blog/http-errors/400-bad-request so that you can find out more details about why it occurred.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.