473,671 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open a popup window if login successful

Slaxer13
106 New Member
Hi guys, i am currently doing a php app for school and the question is this, how can i make a popup window appear if the login is successful and redirect to another page (for example index.php) automatically in, lets say, 5 secs?

My login page as the following code (i am portuguese so some things are in PT but just say and i will translate),

Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/Info_Registos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_Info_Registos, $Info_Registos);
  35. $query_Login = "SELECT * FROM utilizador";
  36. $Login = mysql_query($query_Login, $Info_Registos) or die(mysql_error());
  37. $row_Login = mysql_fetch_assoc($Login);
  38. $totalRows_Login = mysql_num_rows($Login);
  39. ?>
  40. <?php
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43.   session_start();
  44. }
  45.  
  46. $loginFormAction = $_SERVER['PHP_SELF'];
  47. if (isset($_GET['accesscheck'])) {
  48.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  49. }
  50.  
  51. if (isset($_POST['utilizador'])) {
  52.   $loginUsername=$_POST['utilizador'];
  53.   $password=$_POST['password'];
  54.   $MM_fldUserAuthorization = "";
  55.   $MM_redirectLoginSuccess = "index.php";
  56.   $MM_redirectLoginFailed = "login_incorreto.php";
  57.   $MM_redirecttoReferrer = false;
  58.   mysql_select_db($database_Info_Registos, $Info_Registos);
  59.  
  60.   $LoginRS__query=sprintf("SELECT utilizador, password FROM utilizador WHERE utilizador=%s AND password=%s",
  61.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
  62.  
  63.   $LoginRS = mysql_query($LoginRS__query, $Info_Registos) or die(mysql_error());
  64.   $loginFoundUser = mysql_num_rows($LoginRS);
  65.   if ($loginFoundUser) {
  66.      $loginStrGroup = "";
  67.  
  68.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  69.     //declare two session variables and assign them
  70.     $_SESSION['MM_Username'] = $loginUsername;
  71.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  72.  
  73.     if (isset($_SESSION['PrevUrl']) && false) {
  74.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  75.     }
  76.     header("Location: " . $MM_redirectLoginSuccess );
  77.   }
  78.   else {
  79.     header("Location: ". $MM_redirectLoginFailed );
  80.   }
  81. }
  82. ?>
  83. <!doctype html>
  84. <html>
  85. <head>
  86. <meta charset="utf-8">
  87. <title>Login</title>
  88. <style type="text/css">
  89. @import url("style.css");
  90. </style>
  91. </head>
  92.  
  93. <body>
  94.     <h1><img src="images/Logo PAP 2.png" alt="" width="327" height="242" align="right">Login</h1>
  95. <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="Login">
  96.   <label>Utilizador:<br/></label>
  97.     <input type="text" name="utilizador"><br/>
  98.     <label>Password:<br/></label>
  99.     <input type="password" name="password"><br/><br/>
  100.     <input type="submit" value="Login"><br/><br/>
  101.     </form>
  102.     <a href="registo.php">Registar</a>
  103. </body>
  104. </html>
  105. <?php
  106. mysql_free_result($Login);
  107. ?>
  108.  
  109.  
I'm thankful for any help.

Peace and love,

Slaxer13
May 20 '15 #1
16 2817
computerfox
276 Contributor
Hi Slaxer,

In the code block
Expand|Select|Wrap|Line Numbers
  1. if ($loginFoundUser) {
  2.      $loginStrGroup = "";
  3.  
You can add:
Expand|Select|Wrap|Line Numbers
  1. ?><script>alert("Login successful!")</script><?php
  2.  
Hope that helps!
May 20 '15 #2
Dormilich
8,658 Recognized Expert Moderator Expert
how can i make a popup window appear if the login is successful and redirect to another page (for example index.php) automatically
hm, what is the point of a popup if you redirect anyways?

PS. Don’t let DreamWeaver make your PHP code, that’s always a sore sight. better use Prepared Statements if you want to be protected from SQL Injection.
May 21 '15 #3
Slaxer13
106 New Member
Dormilich

Hi mate,

The code i have has been retrieved from the web. This is just a school work and i'm still a newbie at this. Any tips will be much appreciated.

Hi computerfox,

Could you write how the code should be? i tried but it hasn't been working.

Thanks to both ;)

Peace,
Slaxer13
May 21 '15 #4
Dormilich
8,658 Recognized Expert Moderator Expert
since you’re new, don’t start to learn the outdated and deprecated mysql extension. better use mysqli or PDO (personally I recommend PDO over MySQLi, because it’s more straightforward to use).
May 21 '15 #5
Slaxer13
106 New Member
Any suggestion on any site or article i can look in?
May 21 '15 #6
Dormilich
8,658 Recognized Expert Moderator Expert
the linked manual pages should get you started.
May 21 '15 #7
Slaxer13
106 New Member
Thanks for the help i will look into it.
As for the topic do you know how i can do that popup? I tried computerfox way but either i am doing wrong or something else 'cause its not working :/
May 21 '15 #8
computerfox
276 Contributor
Can I see your updated code?
May 21 '15 #9
computerfox
276 Contributor
Try this:
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/Info_Registos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_Info_Registos, $Info_Registos);
  35. $query_Login = "SELECT * FROM utilizador";
  36. $Login = mysql_query($query_Login, $Info_Registos) or die(mysql_error());
  37. $row_Login = mysql_fetch_assoc($Login);
  38. $totalRows_Login = mysql_num_rows($Login);
  39. ?>
  40. <?php
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43.   session_start();
  44. }
  45.  
  46. $loginFormAction = $_SERVER['PHP_SELF'];
  47. if (isset($_GET['accesscheck'])) {
  48.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  49. }
  50.  
  51. if (isset($_POST['utilizador'])) {
  52.   $loginUsername=$_POST['utilizador'];
  53.   $password=$_POST['password'];
  54.   $MM_fldUserAuthorization = "";
  55.   $MM_redirectLoginSuccess = "index.php";
  56.   $MM_redirectLoginFailed = "login_incorreto.php";
  57.   $MM_redirecttoReferrer = false;
  58.   mysql_select_db($database_Info_Registos, $Info_Registos);
  59.  
  60.   $LoginRS__query=sprintf("SELECT utilizador, password FROM utilizador WHERE utilizador=%s AND password=%s",
  61.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
  62.  
  63.   $LoginRS = mysql_query($LoginRS__query, $Info_Registos) or die(mysql_error());
  64.   $loginFoundUser = mysql_num_rows($LoginRS);
  65.   if ($loginFoundUser) {
  66.      $loginStrGroup = "";
  67.  
  68.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  69.     //declare two session variables and assign them
  70.     $_SESSION['MM_Username'] = $loginUsername;
  71.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  72.  
  73.     if (isset($_SESSION['PrevUrl']) && false) {
  74.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  75.     }
  76.     ?><script>alert("Login successful!");</script><?php
  77.     header("Location: " . $MM_redirectLoginSuccess );
  78.   }
  79.   else {
  80.    ?><script>alert("Login failed!");</script><?php
  81.     header("Location: ". $MM_redirectLoginFailed );
  82.   }
  83. }
  84. ?>
  85. <!doctype html>
  86. <html>
  87. <head>
  88. <meta charset="utf-8">
  89. <title>Login</title>
  90. <style type="text/css">
  91. @import url("style.css");
  92. </style>
  93. </head>
  94.  
  95. <body>
  96.     <h1><img src="http://bytes.com/images/Logo PAP 2.png" alt="" width="327" height="242" align="right">Login</h1>
  97. <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="Login">
  98.   <label>Utilizador:<br/></label>
  99.     <input type="text" name="utilizador"><br/>
  100.     <label>Password:<br/></label>
  101.     <input type="password" name="password"><br/><br/>
  102.     <input type="submit" value="Login"><br/><br/>
  103.     </form>
  104.     <a href="registo.php">Registar</a>
  105. </body>
  106. </html>
  107. <?php
  108. mysql_free_result($Login);
  109. ?>
  110.  
  111.  
Also, as Dorm mentioned, why do you want to add a popup for the confirmation and then redirect to another confirmation? Seems un-needed. And yeah, don't use Dreamweaver, Notepad or Notepad++ work better. Or if you're on a Unix/Linux based machine, use vim.
May 21 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
19600
by: Olav Tollefsen | last post by:
I have an <asp:Hyperlink> in my .aspx file. How can I configure it to open the URL (NavigateURL) in a popup window instead of a new normal browser window. I use Target="_blank", but didn't find other values to specify a popup window. Olav
2
2076
by: David Hearn | last post by:
I have a need to open a popup window from one of my forms if a particular session variable is empty. What is the best way to do this? Once the popup opens, the user will make a selection from the window, the session variable gets filled, the window closes, then no more popup window because the session variable is not empty anymore. Thanks in advance!
2
1440
by: Houston Lucifer | last post by:
Hi all, I have a gridview which in the edit mode has a column which has two radio buttons (Approve and Deny). When the user selects deny i have to popup a window with the description textbox where the user can enter a description on why he denied. Is there a way i can do it? If i am using the Javascript window.open how would i go about storing the value when the user clicks the close button on the popup window. Thanks for the help.
2
1762
by: Lou Civitella | last post by:
Using VB 2005 and ASP.Net 2.0. I have a Image control on my page that gets updated when you click on an item in a list box. This works without any problems. Now I want to be able to use the same value that is in the list box and have the user click on the image control and open a new window with the image. Thanks, Lou
2
5708
by: Lou Civitella | last post by:
I have an asp:Button on my page. The buttons OnClick event runs some code. I would like to have it also open a popup window. Is this possible and how do I go about doing this? Thanks, Lou
3
1364
by: siva07 | last post by:
<SCRIPT language=JavaScript type=text/javascript> <!-- function open1(URL) { popupWin = window.open(URL, 'popup', 'dependent=0, height=400,width=480,screenX=200,left=200,screenY=200,top=10,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0', 'launcher'); } //--> </SCRIPT>
12
6580
by: bnashenas1984 | last post by:
I have a page which opens a little popup to show recieved messages but when ever the page tries to open the popup the user should click on the yellow message on top of internet explorer and click on ( allow popup ) otherwise the popup will not be showed Is there any way to open this window without getting permission? <script type="text/javascript" >...
1
2258
by: vinodkus | last post by:
dear sir/madam I want when an website opens then a popup window made in flash should be open automatically in a new window. How it is possible Please help me Thanks in Advance
4
2657
by: onlymukti4u | last post by:
Hi, I need to call another page as a popup without any titlebar,scrollbar and menubar. I had used window.open method but by defult titlebar is coming. Can anyone help me out. Regards, Prasad
2
2397
by: kank999 | last post by:
I am new to popwindow concept in asp.net. So i need code for help. Simply I have to open pop window for showing text in large area.when user will click on textbox he should read properly .That's my purpose. I have never did it before. Thanks in advance. Regards
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8669
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.