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 2714
Hi Slaxer,
In the code block -
if ($loginFoundUser) {
-
$loginStrGroup = "";
-
You can add: -
?><script>alert("Login successful!")</script><?php
-
Hope that helps!
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
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?
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.
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
computerfox
I tried to do that but it does exactly the same thing
Do you have JavaScript enabled?
Sorry for the delay. How can i see that?
:facepalm:
Visit this page and let me know what you see: http://safe.abelgancsos.com/jstest.htm -
<?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":
-
break;
-
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);
-
?>
-
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?
Yesterday i bailed out at lunch. Give me an hour and i'll try
I see a white square in a bigger black one
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |