Check status, if offline move to next

You seem to be mixing JS and PHP here. Is that really the code you’re running?