i want to make a pop window like in javascript, when a user enters invalid username or password, a window appears requesting valid information. how can i do that please?

Recommended Answers

All 9 Replies

You can use js code in echo statement,
Logic:

<?
if(! valid username or password)
{
	echo '<script language="javascript">alert("Please enter valid username and password");</script>';
	header("Location:currentpage.php");
	exit;
}
else
{	
	//--- continue.....
}
?>

What he said ^
|

Because of it's powerful flexibility, I prefer PHP for my popups. Well... they may not ACTUALLY be popups. But functionally they are the same if you don't really require a complete browser window.

The easiest and my preferred method is simply to hide a <div> with the popup content inside of an "if {" statement. If you format the <div> with a class in your stylesheet similar to this:

div.popup {
position: absolute;
left: 100px;
top: 100px;
width: (some width);
height: (some height);
z-index: 1;
}

The key is the z-index which places the <div> above the other content. The <div> will only appear when the 'if' condition is met. This is very powerful when used in conjuction with mysql. You can come up with all kinds of conditions. 'if the user is visiting for the first time', if the user hasn't visited your site for awhile', 'if the user just placed an order'. etc, etc. The possibilities are endless.

Another option would be to pass information through a link with $_GET. It could simply be a link to the same page the user is viewing. You can format it however you like. The important part is just to get the php info across.

a href="http://PageYouAreViewing?popup=SomePopup"

Then you could use $_GET the info to achieve the popup result:

if (isset($_GET['popup']))

You could use the $_GET info to meet an 'if' condition that opens a popup <div> or even multiple <div>'s.

Add in a switch for multiple popup options. And you have more options than you know what to do with.

$popup = ($_GET['popup']);

switch($popup){

case SomePopup:
     conditions for popups;
     break;
case AnotherPopup:
     another condition for popups;
     break;
case AnotherPopup:
     another condition for popups;
     break;
}

There are no limits.

While these aren't actual windows, they are GREAT for interaction with a web site user, you won't need to worry about a pop-up blocker and users usually prefer less windows cluttering up their desktop anyway. If you store info to mysql (logs, customers, orders, users, etc) you can come up with all sorts of conditions.

Member Avatar for diafol

Hmm. The first example gives a vanilla javascript alert - easy, but ugly (no offence). The second gives a php response hard coded into the page. This can't be closed unless by js.

IMO, you could use lightbox-type popups to hold your login form / message - e.g. facebox. This is javascript (using jquery), but looks pretty. The more modern sites tend to use these.

Member Avatar for diafol

The last example still needs js to trigger events. 2penneth. CSS-only solutions have been the holy grail for ages, but consistent triggers across all browsers have been elusive. The example provided by rajarajan07 uses minimal js, so it should avoid problems with users who partially enable js, if that makes sense.

i want to make a pop window using javascript or php, where a user enters username and password, before he or she can be allowed to view the page
. how can i do that please?

can any1 help me out pls

Member Avatar for diafol

What have you found / tried so far? There are literally hundreds (if not thousands) of these FREE scripts out there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.