forcing a user off

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: forcing a user off

Post by jackpf »

You'd have to use ajax or something similiar to constantly check if the admin is logged on.

This sounds a bit odd though....
I personally wouldn't use a website that kicked me off when someone else went offline :|
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: forcing a user off

Post by McInfo »

Store the fact that the admin is logged in or not in a central location like a database or a file. When someone sends a request, check whether the admin is logged in based on the stored value. If not, use a control structure to display something different or call header() to send a Location header to redirect the user.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 6:10 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: forcing a user off

Post by McInfo »

You can't edit it. == You can't make changes. == You can't change its behavior.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 6:12 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: forcing a user off

Post by McInfo »

The admin's logged-in status is probably stored in the board's database. You can access the database from your own PHP script without modifying the board's code. You can use AJAX, as jackpf said, to poll the PHP script from the HTML page that contains the <iframe>. If the admin is logged out (or a certain amount of time has passed since the admin's last action), use Javascript to change the browser location or refresh the page.

Javascript to redirect to page2.php:

Code: Select all

window.location.href = './page2.php';
Also check the logged-in status each time the page with the <iframe> loads.

You can't really prevent anyone from accessing the board without modifying the board's code. Someone can just look at the <iframe>'s src attribute to find the real URL.

Another solution that would be immune to the <iframe> problems is to create a PHP script to act as a proxy for the board. All requests and responses would be filtered through the proxy script.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 6:13 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: forcing a user off

Post by McInfo »

Do you at least know the admin's username and password?

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 6:14 pm, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: forcing a user off

Post by McInfo »

You need to think of your page as a man-in-the-middle. You need to know who the admin users are and keep track of whether they are currently using the page. If no admin has accessed the page for a given period of time, don't show the <iframe> to anyone.

An alternative to AJAX is to use a hidden <iframe> whose source is a PHP script on your server. The <iframe> is updated periodically using Javascript's setInterval() method. The PHP script would be used to keep track of the admin's logged-in status and notify other users when the admin is no longer connected.

Edit: This post was recovered from search engine cache.
Post Reply