Hi all,

How can i avoid same php page from being opened in two windows? If the page is opened in one window, then if the user tries to open the same page in another window, he/she should be given a message that the page is already open.
Can anyone tell me how to do that?

While there is no browser integration that determines whether a specified window is open or not you could set a session bit once someone has visited the page then display the 'error' message if they visit it again with the bit set.

what i have done is that i have set sessions, so that the user can't directly go into the next page without logging in. once he/she logs in the session variable is set. but with this i cant forbide the user from opening two window of the same page, once he/she logs in. how can i avoid that?

Whenever a user opens a page, add page's name to the session variable. Since you are adding it to the session, If he opens another window for the same page, redirect him to error page.

//This is main.php which has link to page1.php
<a href="page1.php">Page 1</a>

This is page1.php

 header("location: error.php");
} else {
echo "Hi";

Now, right click on the page1.php and open it in a new page. It displays "Hi". Do the same again and you will be redirected to error.php.


Great mind always at work

thanks naveen my problem is solved. only thing i added is to make the session variable 'page' equal to 0 in subsequent pages

This question has already been answered. Start a new discussion instead.