russ_gillespie Posted February 7, 2007 Share Posted February 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/ Share on other sites More sharing options...
wildteen88 Posted February 7, 2007 Share Posted February 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/#findComment-179383 Share on other sites More sharing options...
russ_gillespie Posted February 7, 2007 Author Share Posted February 7, 2007 ok thanks for clearing that up. But how would I go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/#findComment-179405 Share on other sites More sharing options...
russ_gillespie Posted February 7, 2007 Author Share Posted February 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/#findComment-179492 Share on other sites More sharing options...
russ_gillespie Posted February 7, 2007 Author Share Posted February 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37512-solved-php-newbie-looking-for-some-help/#findComment-179519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.