Jump to content

Recommended Posts

Hi there,

 

Before I start let me just say I'm completely new to PHP, fairly novice at javascript, but pretty good with html.

 

I'm trying to setup a password protected area of my website. All I need is a text box, a button saying submit, and then for a popup window to display upon the correct password being entered. I'd like to stress the fact that I need a popup window and not just a forward. I may settle for a simple new window being opened if that's easier.

 

Here's what I've got so far...

 

I've got a form with a password text box and submit button. The form is attached to a PHP doc with the following code:

 

<?php

session_start();

header("Cache-control: private");// IE 6 Fix.

 

$password = $_POST['password'];

 

if ($password == "password") {

$_SESSION['UserLoggedIn'] = TRUE;

header("Location: ../directory/webpage.php");

exit;

}

else {

$_SESSION['UserLoggedIn'] = FALSE;

header("Location: webpage.html");

exit;

}

?>

 

 

This works and forwards the user to the right page. But I need the secured page to open in a popup window, or to simply open in a new window. Ive been trying to search for some code but cant find anything. I know how to make a html page appear in a popup windows using java, but dont know if that can be used with php and how.

 

Any help will be much appreciated.

 

Regards,

 

Russ Gillespie

Link to comment
https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/
Share on other sites

You cannot do this with PHP. You will need to use a client side language for this, which would be javascript. You will have to echo out the javascript that will popup the new window in place of your header redirection code.

ok I've made some progress... But I need a little more help.

 

The following code creates a popup after the correct password has been entered. But the browser then gets gets stuck on the PHP page, which appears blank to the user.

 

<?php

session_start();

header("Cache-control: private");// IE 6 Fix.

 

$password = $_POST['password'];

 

if ($password == "password") {

$_SESSION['UserLoggedIn'] = TRUE;

echo '<script type="text/javascript">

<!--

if ( 1 ) {

    window.open(\'../directory/index.php\', \'_WELCOME\',

    \'HEIGHT=450, resizable=yes, WIDTH=600\');

}

//-->

</script>';

exit;

}

else {

$_SESSION['UserLoggedIn'] = FALSE;

header("Location: webpage.html");

exit;

}

?>

 

In other words, the browser sticks on the php page that contains the above code, and the user has to click Back to get back to my website. How can I make this page forward them back instantly after the popup appears?

 

 

Regards,

 

Russ

I finally figured it out!

 

Here is the code for anyone who may want to know....

 

<?php

session_start();

header("Cache-control: private");// IE 6 Fix.

 

$password = $_POST['password'];

 

if ($password == "password") {

$_SESSION['UserLoggedIn'] = TRUE;

echo '<script type="text/javascript">

<!--

if ( 1 ) {

    window.open(\'../directory/index.php\', \'_WELCOME\',

    \'HEIGHT=400, resizable=yes, WIDTH=550\');

}

//-->

</script>';

echo '<script language="javascript">

<!--

location.replace("webpage.html")

//-->

</script>';

exit;

}

else {

$_SESSION['UserLoggedIn'] = FALSE;

header("Location: webpage.html");

exit;

}

?>

 

 

Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.