Solved

popup window

Posted on 2009-04-08
33
297 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

12 Experts available now in Live!

Get 1:1 Help Now