473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to open a popup window if login successful

Slaxer13
106 64KB
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 2714
computerfox
276 100+
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 Expert Mod 8TB
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 64KB
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 Expert Mod 8TB
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 64KB
Any suggestion on any site or article i can look in?
May 21 '15 #6
Dormilich
8,658 Expert Mod 8TB
the linked manual pages should get you started.
May 21 '15 #7
Slaxer13
106 64KB
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 100+
Can I see your updated code?
May 21 '15 #9
computerfox
276 100+
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
Slaxer13
106 64KB
I will try as soon as possible and post the result. I am using dreamweaver 'cause my teacher choose it :/ I want that popup only and then redirect to my main page. The confirmation window i have will be deleted. It was created because i couldn't do the popup.

Peace,
Slaxer13
May 22 '15 #11
Slaxer13
106 64KB
computerfox

I tried to do that but it does exactly the same thing
May 22 '15 #12
computerfox
276 100+
Do you have JavaScript enabled?
May 22 '15 #13
Slaxer13
106 64KB
Sorry for the delay. How can i see that?
May 25 '15 #14
computerfox
276 100+
:facepalm:
Visit this page and let me know what you see:

http://safe.abelgancsos.com/jstest.htm

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.      break;
  18.     case "int":
  19.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  20.       break;
  21.     case "double":
  22.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  23.       break;
  24.     case "date":
  25.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  26.       break;
  27.     case "defined":
  28.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  29.       break;
  30.   }
  31.   return $theValue;
  32. }
  33. }
  34.  
  35. mysql_select_db($database_Info_Registos, $Info_Registos);
  36. $query_Login = "SELECT * FROM utilizador";
  37. $Login = mysql_query($query_Login, $Info_Registos) or die(mysql_error());
  38. $row_Login = mysql_fetch_assoc($Login);
  39. $totalRows_Login = mysql_num_rows($Login);
  40. ?>
  41. <?php
  42. // *** Validate request to login to this site.
  43. if (!isset($_SESSION)) {
  44.   session_start();
  45. }
  46.  
  47. $loginFormAction = $_SERVER['PHP_SELF'];
  48. if (isset($_GET['accesscheck'])) {
  49.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  50. }
  51.  
  52. if (isset($_POST['utilizador'])) {
  53.   $loginUsername=$_POST['utilizador'];
  54.   $password=$_POST['password'];
  55.   $MM_fldUserAuthorization = "";
  56.   $MM_redirectLoginSuccess = "index.php";
  57.   $MM_redirectLoginFailed = "login_incorreto.php";
  58.   $MM_redirecttoReferrer = false;
  59.   mysql_select_db($database_Info_Registos, $Info_Registos);
  60.  
  61.   $LoginRS__query=sprintf("SELECT utilizador, password FROM utilizador WHERE utilizador=%s AND password=%s",
  62.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
  63.  
  64.   $LoginRS = mysql_query($LoginRS__query, $Info_Registos) or die(mysql_error());
  65.   $loginFoundUser = mysql_num_rows($LoginRS);
  66.   if ($loginFoundUser) {
  67.      $loginStrGroup = "";
  68.  
  69.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  70.     //declare two session variables and assign them
  71.     $_SESSION['MM_Username'] = $loginUsername;
  72.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  73.  
  74.     if (isset($_SESSION['PrevUrl']) && false) {
  75.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  76.     }
  77.     ?><script>alert("Login successful!");</script><?php
  78.     header("Location: " . $MM_redirectLoginSuccess );
  79.   }
  80.   else {
  81.    ?><script>alert("Login failed!");</script><?php
  82.     header("Location: ". $MM_redirectLoginFailed );
  83.   }
  84. }
  85. ?>
  86. <!doctype html>
  87. <html>
  88. <head>
  89. <meta charset="utf-8">
  90. <title>Login</title>
  91. <style type="text/css">
  92. @import url("style.css");
  93. </style>
  94. </head>
  95.  
  96. <body>
  97.     <h1><img src="http://bytes.com/images/Logo PAP 2.png" alt="" width="327" height="242" align="right">Login</h1>
  98. <form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="Login">
  99.   <label>Utilizador:<br/></label>
  100.     <input type="text" name="utilizador"><br/>
  101.     <label>Password:<br/></label>
  102.     <input type="password" name="password"><br/><br/>
  103.     <input type="submit" value="Login"><br/><br/>
  104.     </form>
  105.     <a href="registo.php">Registar</a>
  106. </body>
  107. </html>
  108. <?php
  109. mysql_free_result($Login);
  110. ?>
  111.  
Did you code previously redirect prior to our changes?
I updated your switch statement as the "long" case didn't have a break.
Can you try now?
May 25 '15 #15
Slaxer13
106 64KB
Yesterday i bailed out at lunch. Give me an hour and i'll try
May 26 '15 #16
Slaxer13
106 64KB
I see a white square in a bigger black one
May 26 '15 #17

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

Similar topics

4
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...
2
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...
2
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...
2
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...
2
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
by: siva07 | last post by:
<SCRIPT language=JavaScript type=text/javascript> <!-- function open1(URL) { popupWin = window.open(URL, 'popup', 'dependent=0,...
12
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...
1
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
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.