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), - <?php require_once('Connections/Info_Registos.php'); ?>
-
<?php
-
if (!function_exists("GetSQLValueString")) {
-
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
-
{
-
if (PHP_VERSION < 6) {
-
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
-
}
-
-
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
-
-
switch ($theType) {
-
case "text":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "long":
-
case "int":
-
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
-
break;
-
case "double":
-
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
-
break;
-
case "date":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "defined":
-
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
-
break;
-
}
-
return $theValue;
-
}
-
}
-
-
mysql_select_db($database_Info_Registos, $Info_Registos);
-
$query_Login = "SELECT * FROM utilizador";
-
$Login = mysql_query($query_Login, $Info_Registos) or die(mysql_error());
-
$row_Login = mysql_fetch_assoc($Login);
-
$totalRows_Login = mysql_num_rows($Login);
-
?>
-
<?php
-
// *** Validate request to login to this site.
-
if (!isset($_SESSION)) {
-
session_start();
-
}
-
-
$loginFormAction = $_SERVER['PHP_SELF'];
-
if (isset($_GET['accesscheck'])) {
-
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
-
}
-
-
if (isset($_POST['utilizador'])) {
-
$loginUsername=$_POST['utilizador'];
-
$password=$_POST['password'];
-
$MM_fldUserAuthorization = "";
-
$MM_redirectLoginSuccess = "index.php";
-
$MM_redirectLoginFailed = "login_incorreto.php";
-
$MM_redirecttoReferrer = false;
-
mysql_select_db($database_Info_Registos, $Info_Registos);
-
-
$LoginRS__query=sprintf("SELECT utilizador, password FROM utilizador WHERE utilizador=%s AND password=%s",
-
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
-
-
$LoginRS = mysql_query($LoginRS__query, $Info_Registos) or die(mysql_error());
-
$loginFoundUser = mysql_num_rows($LoginRS);
-
if ($loginFoundUser) {
-
$loginStrGroup = "";
-
-
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
-
//declare two session variables and assign them
-
$_SESSION['MM_Username'] = $loginUsername;
-
$_SESSION['MM_UserGroup'] = $loginStrGroup;
-
-
if (isset($_SESSION['PrevUrl']) && false) {
-
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
-
}
-
header("Location: " . $MM_redirectLoginSuccess );
-
}
-
else {
-
header("Location: ". $MM_redirectLoginFailed );
-
}
-
}
-
?>
-
<!doctype html>
-
<html>
-
<head>
-
<meta charset="utf-8">
-
<title>Login</title>
-
<style type="text/css">
-
@import url("style.css");
-
</style>
-
</head>
-
-
<body>
-
<h1><img src="images/Logo PAP 2.png" alt="" width="327" height="242" align="right">Login</h1>
-
<form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="Login">
-
<label>Utilizador:<br/></label>
-
<input type="text" name="utilizador"><br/>
-
<label>Password:<br/></label>
-
<input type="password" name="password"><br/><br/>
-
<input type="submit" value="Login"><br/><br/>
-
</form>
-
<a href="registo.php">Registar</a>
-
</body>
-
</html>
-
<?php
-
mysql_free_result($Login);
-
?>
-
-
I'm thankful for any help.
Peace and love,
Slaxer13
16 2817
Hi Slaxer,
In the code block -
if ($loginFoundUser) {
-
$loginStrGroup = "";
-
You can add: -
?><script>alert("Login successful!")</script><?php
-
Hope that helps!
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.
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
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).
Any suggestion on any site or article i can look in?
Dormilich 8,658
Recognized Expert Moderator Expert
the linked manual pages should get you started.
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 :/
Can I see your updated code?
Try this: -
<?php require_once('Connections/Info_Registos.php'); ?>
-
<?php
-
if (!function_exists("GetSQLValueString")) {
-
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
-
{
-
if (PHP_VERSION < 6) {
-
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
-
}
-
-
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
-
-
switch ($theType) {
-
case "text":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "long":
-
case "int":
-
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
-
break;
-
case "double":
-
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
-
break;
-
case "date":
-
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
-
break;
-
case "defined":
-
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
-
break;
-
}
-
return $theValue;
-
}
-
}
-
-
mysql_select_db($database_Info_Registos, $Info_Registos);
-
$query_Login = "SELECT * FROM utilizador";
-
$Login = mysql_query($query_Login, $Info_Registos) or die(mysql_error());
-
$row_Login = mysql_fetch_assoc($Login);
-
$totalRows_Login = mysql_num_rows($Login);
-
?>
-
<?php
-
// *** Validate request to login to this site.
-
if (!isset($_SESSION)) {
-
session_start();
-
}
-
-
$loginFormAction = $_SERVER['PHP_SELF'];
-
if (isset($_GET['accesscheck'])) {
-
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
-
}
-
-
if (isset($_POST['utilizador'])) {
-
$loginUsername=$_POST['utilizador'];
-
$password=$_POST['password'];
-
$MM_fldUserAuthorization = "";
-
$MM_redirectLoginSuccess = "index.php";
-
$MM_redirectLoginFailed = "login_incorreto.php";
-
$MM_redirecttoReferrer = false;
-
mysql_select_db($database_Info_Registos, $Info_Registos);
-
-
$LoginRS__query=sprintf("SELECT utilizador, password FROM utilizador WHERE utilizador=%s AND password=%s",
-
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
-
-
$LoginRS = mysql_query($LoginRS__query, $Info_Registos) or die(mysql_error());
-
$loginFoundUser = mysql_num_rows($LoginRS);
-
if ($loginFoundUser) {
-
$loginStrGroup = "";
-
-
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
-
//declare two session variables and assign them
-
$_SESSION['MM_Username'] = $loginUsername;
-
$_SESSION['MM_UserGroup'] = $loginStrGroup;
-
-
if (isset($_SESSION['PrevUrl']) && false) {
-
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
-
}
-
?><script>alert("Login successful!");</script><?php
-
header("Location: " . $MM_redirectLoginSuccess );
-
}
-
else {
-
?><script>alert("Login failed!");</script><?php
-
header("Location: ". $MM_redirectLoginFailed );
-
}
-
}
-
?>
-
<!doctype html>
-
<html>
-
<head>
-
<meta charset="utf-8">
-
<title>Login</title>
-
<style type="text/css">
-
@import url("style.css");
-
</style>
-
</head>
-
-
<body>
-
<h1><img src="http://bytes.com/images/Logo PAP 2.png" alt="" width="327" height="242" align="right">Login</h1>
-
<form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="Login">
-
<label>Utilizador:<br/></label>
-
<input type="text" name="utilizador"><br/>
-
<label>Password:<br/></label>
-
<input type="password" name="password"><br/><br/>
-
<input type="submit" value="Login"><br/><br/>
-
</form>
-
<a href="registo.php">Registar</a>
-
</body>
-
</html>
-
<?php
-
mysql_free_result($Login);
-
?>
-
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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!
|
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.
|
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
|
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
| |
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>
|
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" >...
|
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
|
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
|
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
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |