Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

popup window

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
jareddraper
Asked:
jareddraper
  • 18
  • 11
  • 4
1 Solution
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
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
 
EMB01Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jareddraperAuthor Commented:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/htdocs/website_09/support/index.php on line 8
0
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
this just brings up a blank page and doesnt go to the login.php page?

http://www.arkona.com/website_09/support/
0
 
EMB01Commented:
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
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
Parse error: syntax error, unexpected T_ECHO in /var/www/htdocs/website_09/support/index.php on line 17
0
 
jareddraperAuthor Commented:
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
 
EMB01Commented:
! 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
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
Parse error: syntax error, unexpected T_ECHO in /var/www/htdocs/website_09/support/index.php on line 17
0
 
jareddraperAuthor Commented:
<?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
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
again, now I just get a blank screen?

http://www.arkona.com/website_09/support/
0
 
jareddraperAuthor Commented:
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
 
jareddraperAuthor Commented:
maybe somehow the popup JS should be on the login.php page insted? as apposed to the index page?
0
 
EMB01Commented:
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
 
jareddraperAuthor Commented:
still a blank page
0
 
Michel PlungjanIT ExpertCommented:
Glad I was not the only one...
0
 
jareddraperAuthor Commented:
Ok, so I guess we hit a wall here then?
0
 
Michel PlungjanIT ExpertCommented:
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
 
jareddraperAuthor Commented:
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
 
jareddraperAuthor Commented:
All of this is fully functioning only when not valid it just opens the login page (not as a small popup)
0
 
jareddraperAuthor Commented:
here is the link to this index page, where you can see this happen

http://www.arkona.com/website_09/support/
0
 
Michel PlungjanIT ExpertCommented:
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
 
jareddraperAuthor Commented:
Yes I agree, I dont know why that didnt work
0
 
jareddraperAuthor Commented:
Is there anyway we can just force the popup on the login page side so whenever its called it pops?
0
 
EMB01Commented:
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
 
Michel PlungjanIT ExpertCommented:
Most browsers do not support popups?

You mean most NEW browsers actively disallow them unless the user allows?
0
 
jareddraperAuthor Commented:
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
 
EMB01Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 18
  • 11
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now