Solved

popup window

Posted on 2009-04-08
33
307 Views
Last Modified: 2012-05-06
I need my login.php page to pop-up into a small window as apposed to a whole page. I am assuming I need to add a simple JS command to make this happen. Please let me know if you can find a solution. Thanks
here is the simple code that automatically opens the login.php page and once validated loads supportmain.php page
 
 
 
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
	$url = "login.php";
	header ("Location:".$url);
	exit();
}
?>
<?PHP
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>
 
 
 
 
here is the actual login page that loads from index.php
 
 
 
 
 
<?
session_start();
session_destroy();
$_SESSION = array();
?>
<html>
<body>
<form action="validate.php" method="post" name="Auth" enctype="multipart/form-data"> 
<table cellspacing=3 cellpadding=3 class=ContentBodyTable> 
   <tr> 
      <td>Username: </td> 
      <td><input type="text" name="username" size=11 maxlength=20 class=textInput></td> 
   </tr> 
   <tr> 
      <td>Password: </td> 
      <td><input type="password" name="password" size=16 maxlength=15 class=textInput></td> 
   </tr>
   <tr> 
      <td colspan=2><input type=submit value=Authenticate class=SubmitInput style='width:100'></td> 
   </tr> 
</table> 
<p>&nbsp;  </p>
<p>
  <input type="hidden" name="target" value="index.php"/>
</p>
</form> 
 
 
</body>
</html>

Open in new window

0
Comment
Question by:jareddraper
  • 18
  • 11
  • 4
33 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 24099663
Here's how to code a JS popup (attached).
<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
	newwindow=window.open(url,'name','height=200,width=150');
	if (window.focus) {newwindow.focus()}
	return false;
}
 
// -->
</script>

Open in new window

0
 

Author Comment

by:jareddraper
ID: 24099699
Thanks but how do you append it to the index page correctly?

<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        $url = "login.php";
        header ("Location:".$url);
        exit();
}
?>
<?PHP
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24099898
You should just be able to echo the javascript in PHP like so:
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type="text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "	newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "	if (window.focus) {newwindow.focus()}\n";
        echo "	return false;\n";
        echo "}\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jareddraper
ID: 24100675
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/htdocs/website_09/support/index.php on line 8
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24100744
Sorry, you'll need to escape all quotation marks. I missed one... The attached version is fixed.
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "	newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "	if (window.focus) {newwindow.focus()}\n";
        echo "	return false;\n";
        echo "}\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
 

Author Comment

by:jareddraper
ID: 24100768
this just brings up a blank page and doesnt go to the login.php page?

http://www.arkona.com/website_09/support/
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24100839
Be sure that for line 10 you replace it with your actual URL.
        echo "function popitup(\'http://www.emarketbuilders.com\') {\n";

Open in new window

0
 
LVL 14

Expert Comment

by:EMB01
ID: 24100850
Sorry, you shouldn't need to replace line 10... just call the function by adding a line (see updated code).

That should work.
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "	newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "	if (window.focus) {newwindow.focus()}\n";
        echo "	return false;\n";
        echo "}\n";
        echo "popitup(\'http://www.emarketbuilders.com\') {\n";"
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
 

Author Comment

by:jareddraper
ID: 24101004
Parse error: syntax error, unexpected T_ECHO in /var/www/htdocs/website_09/support/index.php on line 17
0
 

Author Comment

by:jareddraper
ID: 24101045
I just want to be sure we are on the same page. This index page just sends you to the login.php page. The login.php page is the page I want to pop-up not a different page.
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24101048
! Sorry, again... I try this code and tell me what happens (there was an extra "{" in the equation):
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "	newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "	if (window.focus) {newwindow.focus()}\n";
        echo "	return false;\n";
        echo "}\n";
        echo "popitup(\'http://www.emarketbuilders.com\')\n";"
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
 
LVL 14

Expert Comment

by:EMB01
ID: 24101091
You'll want to replace http://www.emarketbuilders.com on line 15 with your own, as you say, "login.php." Let me know if you have any questions.
0
 

Author Comment

by:jareddraper
ID: 24101985
Parse error: syntax error, unexpected T_ECHO in /var/www/htdocs/website_09/support/index.php on line 17
0
 

Author Comment

by:jareddraper
ID: 24102000
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "  newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "  if (window.focus) {newwindow.focus()}\n";
        echo "  return false;\n";
        echo "}\n";
        echo "popitup(\'login.php')\n";"
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24102077
Sorry, yet another syntax error on my part:
<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "  newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "  if (window.focus) {newwindow.focus()}\n";
        echo "  return false;\n";
        echo "}\n";
        echo "popitup(\'login.php')\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
 

Author Comment

by:jareddraper
ID: 24102141
again, now I just get a blank screen?

http://www.arkona.com/website_09/support/
0
 

Author Comment

by:jareddraper
ID: 24102164
again this original script just checks to see if I'm logged in and if not passes me to the login.php page, if I am logged in it reroutes me to the supportmain.php page


<?php
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
      $url = "login.php";
      header ("Location:".$url);
      exit();
}
?>
<?PHP
require("siteconfig.php");

$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>
0
 

Author Comment

by:jareddraper
ID: 24102177
maybe somehow the popup JS should be on the login.php page insted? as apposed to the index page?
0
 
LVL 14

Accepted Solution

by:
EMB01 earned 500 total points
ID: 24102210
Let's fix the error on this PHP page, first. Use this:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "  newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "  if (window.focus) {newwindow.focus()}\n";
        echo "  return false;\n";
        echo "}\n";
        echo "popitup(\'login.php')\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0
 

Author Comment

by:jareddraper
ID: 24102242
still a blank page
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24104214
Glad I was not the only one...
0
 

Author Comment

by:jareddraper
ID: 24107425
Ok, so I guess we hit a wall here then?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24107498
I see it happen as follows

1. user hits index - if a valid session, he is greeted, welcome back, if not there is a link or an automatic popup with the login (or better, like most sites, instead of welcome back, the login form)
2. user logs in using the login form and the page is reloaded with the now valid session - if a popup was used, the popup redirects the opener to the index or next page and closes itself
0
 

Author Comment

by:jareddraper
ID: 24107703
Maybe this is the confusion. I want the login.php page to be the popup page. No need for any welcome back or anything. Just an index page that checks session and if not valid we get the popup login page and once validated returns you to the index page and which points to the correct files to be loaded.
0
 

Author Comment

by:jareddraper
ID: 24107716
All of this is fully functioning only when not valid it just opens the login page (not as a small popup)
0
 

Author Comment

by:jareddraper
ID: 24107729
here is the link to this index page, where you can see this happen

http://www.arkona.com/website_09/support/
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24108160
Since we get immediately redirected I do not see that page

It should be how I suggested earlier (simplified)

<? if (not valid) { ?>
<script>
popup()
</script>
<? }
  else {
 redirect to ok page
} ?>



0
 

Author Comment

by:jareddraper
ID: 24108298
Yes I agree, I dont know why that didnt work
0
 

Author Comment

by:jareddraper
ID: 24109357
Is there anyway we can just force the popup on the login page side so whenever its called it pops?
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24109609
If you want a popup to occur on the login page; you should put this code on your login page:
<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
      newwindow=window.open(url,'name','height=200,width=150');
      if (window.focus) {newwindow.focus()}
      return false;
}
 
// -->
</script>

However, most browsers do not support Javascript popups (other than alert boxes - which you can put options inside of; i.e. yes or no confirmation). I recommend using a div popup, like this:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21978031.html
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24110415
Most browsers do not support popups?

You mean most NEW browsers actively disallow them unless the user allows?
0
 

Author Comment

by:jareddraper
ID: 24169091
This code is throwing this error? Please help
line 8
char 9
error invalid character
code 0


<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "  newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "  if (window.focus) {newwindow.focus()}\n";
        echo "  return false;\n";
        echo "}\n";
        echo "popitup(\'login.php')\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>
0
 
LVL 14

Expert Comment

by:EMB01
ID: 24170795
Yeah, mplungjan; that's what I mean. Thanks for clarifying.

I noticed an un-escaped character on one of the lines (doesn't seem to be line 8). Give the attached script a try and let me know what's up.

I'm not sure what the invalid character would be... If it doesn't work I'll keep looking.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
session_start();
$valid = isset($_SESSION["valid"])?$_SESSION["valid"]:FALSE;
if ($valid != TRUE)
{
        //$url = "login.php";
        //header ("Location:".$url);
        echo "<script language=\"javascript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "function popitup(url) {\n";
        echo "  newwindow=window.open(url,'name','height=200,width=150');\n";
        echo "  if (window.focus) {newwindow.focus()}\n";
        echo "  return false;\n";
        echo "}\n";
        echo "popitup(\'login.php\')\n";
        echo "// -->\n";
        echo "</script>\n";
        exit();
}
?>
<?php
require("siteconfig.php");
 
$nav_var='';
$nav_column='nav_main.html';
$body='supportmain.php';
include($template);
?>

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now