Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-05-07 09:55:14
Point:500 Replies:9 POST_ID:828552USER_ID:11059
Topic:
PHP Scripting Language;Hypertext Markup Language (HTML);JavaScript
Recently Ive succesful y done login user form in php and html example, but I get question
how can I display login result message on the page we do login process instead of
using header() php function to redirect the result and display it on other pages?
As we know for user acces-control, we need login form on home webpage.
In the form tag in home page, probably we will do code as follows
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
in which after user typing login and password and submit the form by executing
login-exec.php that is for authurization checking for mysql_database and get $_session
variable in order to make desicion whether the login is succesful or fail , The login
result will be displayed , most people will use header(location: login-fail.php) php coding for redirect the page to the new failed-mesage page or header(location:login-succes.php)
for successful result.
I want to display the result on the exact the home webpage where I did login form
and I don't want my home page for any refresh during login result display since
my server is really slow. Any idea for doing that instead of using
header() in php coding. Can I control the existing home webpge javascript and html
in order to display the login result ?
BE reminded, my home page have a lot of thing besides login-form
Please advise
Duncan
Part of coindg for login-exec.php
===========================
how can I display login result message on the page we do login process instead of
using header() php function to redirect the result and display it on other pages?
As we know for user acces-control, we need login form on home webpage.
In the form tag in home page, probably we will do code as follows
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
in which after user typing login and password and submit the form by executing
login-exec.php that is for authurization checking for mysql_database and get $_session
variable in order to make desicion whether the login is succesful or fail , The login
result will be displayed , most people will use header(location: login-fail.php) php coding for redirect the page to the new failed-mesage page or header(location:login-succes.php)
for successful result.
I want to display the result on the exact the home webpage where I did login form
and I don't want my home page for any refresh during login result display since
my server is really slow. Any idea for doing that instead of using
header() in php coding. Can I control the existing home webpge javascript and html
in order to display the login result ?
BE reminded, my home page have a lot of thing besides login-form
Please advise
Duncan
Part of coindg for login-exec.php
===========================
//Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; // echo "1-1=".$_SESSION['SESS_MEMBER_ID']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); // require_once('member-index.php'); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:
Expert: stevepwales replied at 2024-05-07 17:34:08
Sorry mate i been out all day have a look at
this using jquery for future use makes using ajax a lot easier to deal with
http://api.jquery.com/jQuery.ajax/
it does away with a lot of the code you can use the result of the ajax call in an easy to use jquery function
this using jquery for future use makes using ajax a lot easier to deal with
http://api.jquery.com/jQuery.ajax/
it does away with a lot of the code you can use the result of the ajax call in an easy to use jquery function
Author: duncanb7 replied at 2024-05-07 13:01:09
it works now if using POST open and change send(null) as follows and also
need to setRequestHeader
var login= document.getElementById("login").value;
var password= document.getElementById("password").value;
xmlhttp.open( "POST", ref,true );
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
and xmlhttp.send("login="+login+ "&password="+password); in ajax function, getData()
THanks with close these thread
Duncan
function getData(link)
{
var ref=link;
var xmlhttp;
var login= document.getElementById("login").value;
var password= document.getElementById("password").value;
//alert("login="+login+ "&password="+password);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
//alert("IE7");
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if ( xmlhttp.readyState == 4 && xmlhttp.status==200)
{
alert("1");
document.getElementById("loginresult").innerHTML=xmlhttp.responseText;
//alert(xmlhttp.responseText);
}
}
xmlhttp.open( "POST", ref,true );
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("login="+login+ "&password="+password);
}
need to setRequestHeader
var login= document.getElementById("login").value;
var password= document.getElementById("password").value;
xmlhttp.open( "POST", ref,true );
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
and xmlhttp.send("login="+login+ "&password="+password); in ajax function, getData()
THanks with close these thread
Duncan
function getData(link)
{
var ref=link;
var xmlhttp;
var login= document.getElementById("login").value;
var password= document.getElementById("password").value;
//alert("login="+login+ "&password="+password);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
//alert("IE7");
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if ( xmlhttp.readyState == 4 && xmlhttp.status==200)
{
alert("1");
document.getElementById("loginresult").innerHTML=xmlhttp.responseText;
//alert(xmlhttp.responseText);
}
}
xmlhttp.open( "POST", ref,true );
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("login="+login+ "&password="+password);
}
Author: duncanb7 replied at 2024-05-07 11:35:55
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$login and $password is empty after using alert(xmlhttp.responseText) in getData();
Why it is not working ?
$password = clean($_POST['password']);
$login and $password is empty after using alert(xmlhttp.responseText) in getData();
Why it is not working ?
Author: duncanb7 replied at 2024-05-07 11:29:31
Be reminded using header() and action="/login-exec.php" , it all work fine
BUt using ajax it is not working
BUt using ajax it is not working
Author: duncanb7 replied at 2024-05-07 11:26:56
$login = clean($_POST['login']);
$password = clean($_POST['password']);
it seems it is not working for those code above in ajax, please advise
$password = clean($_POST['password']);
it seems it is not working for those code above in ajax, please advise
Author: duncanb7 replied at 2024-05-07 11:25:14
complete login-exec.php and I take out all header() function and
add echo result . but the reult is always Login-fail even I input correct
login
add echo result . but the reult is always Login-fail even I input correct
login
<?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); echo "login-form"; // header("location: login-form.php"); // exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' "; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; // echo "1-1=".$_SESSION['SESS_MEMBER_ID']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); echo "login-member"; // require_once('member-index.php'); // header("location: member-index.php"); // exit(); }else { //Login failed echo "login-fail"; //header("location: login-failed.php"); // exit(); } }else { die("Query failed"); }?> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:
Author: duncanb7 replied at 2024-05-07 11:22:33
I learn a lot of ajax, and now I try this function of getData() but it won't work
Modifiy login page code and add code
<form method="post" action="javascript:getData('http://www.mysite.com/login-exec.php')" name="loginPopupForm">
<div id="loginresult">LoginResult</div>
I check using ajax to access control check that is not working because the
variable of $login or $password is equal to empty or '' in login-exec.php
Modifiy login page code and add code
<form method="post" action="javascript:getData('http://www.mysite.com/login-exec.php')" name="loginPopupForm">
<div id="loginresult">LoginResult</div>
I check using ajax to access control check that is not working because the
variable of $login or $password is equal to empty or '' in login-exec.php
function getData(link){var ref=link;var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari//alert("IE7"); xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if ( xmlhttp.readyState == 4 && xmlhttp.status==200) {// alert("1"); document.getElementById("loginresult").innerHTML=xmlhttp.responseText;//alert(xmlhttp.responseText); } } xmlhttp.open( "GET", ref,true ); xmlhttp.send(null);} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:
Accepted Solution
Expert: stevepwales replied at 2024-05-07 10:18:10
250 points AVERAGE
If u dont want to refresh and want to vailidate on home page you will need to combine php and ajax
Assisted Solution
Expert: COBOLdinosaur replied at 2024-05-07 10:16:08
250 points AVERAGE
Put the login form in an iframe.
You could also use AJAX, but the re-direct on the backend would screw it up. If you use an iframe, the login can be submitted to the existing script and the re-direction would be returned in the iframe. The main page would not need to be refreshed.
Cd&
You could also use AJAX, but the re-direct on the backend would screw it up. If you use an iframe, the login can be submitted to the existing script and the re-direction would be returned in the iframe. The main page would not need to be refreshed.
Cd&