Jump to content

nielcleo

Members
  • Posts

    100
  • Joined

  • Last visited

About nielcleo

  • Birthday 07/14/1993

nielcleo's Achievements

Member

Member (2/7)

4

Reputation

  1. its not working its still not validate the input user and pass :(..but when i echoed only $_GET['userid'] and $_GET['userpass']; it displaying the data input from the form but when i used the code to validate it from the database its not working
  2. here's my new code:index.php <html><head><script type="text/javascript">function loadXMLDoc(){var xmlhttp;var x=document.getElementById("username").valuevar y=document.getElementById("password").valueif (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","validate_logon.php?userid="+x+"&&userpass="+y,true);xmlhttp.send();}</script></head><body><input id="username" name="username" type="text" /><br><input id="password" name="password" type="text" /><div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc()">Change Content</button></body></html> and i use $_GET['userid'] and $_GET['userpass'] and i echo it in validate_logon.php and its working displaying the userid and userpass that the user input on the forms.. but i encounter a problem on validate_logon.php when i use to connect it with my database.. i always got wrong password.. though i input correct login details..here's the validate_logon.php <?php$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name=""; // Database name$tbl_name=""; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// username and password sent from form$myusername=$_GET['userid'];$mypassword=$_GET['userpass'];// To protect MySQL injection (more detail about MySQL injection)$myusername = stripslashes($myusername);$mypassword = stripslashes($mypassword);$myusername = mysql_real_escape_string($myusername);$mypassword = mysql_real_escape_string($mypassword);$sql="SELECT * FROM $tbl_name WHERE userid='$myusername' and user_pass='$mypassword' ";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $mypassword and redirect to file "login_success.php"session_register("myusername");session_register("mypassword");header("location:login_success.php");}else {echo "Wrong Username or Password";}echo "<br />";echo "<br />";echo "<br />";echo $myusername;echo "<br />";echo $mypassword;?>
  3. nielcleo

    Php Header

    main.php..only holds a members content
  4. nielcleo

    Php Header

    here's my index.php <?phpsession_start();if(session_is_registered(myusername)){header("LOCATION: index.php?p=success");}?> <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>New Page 1</title><script type="text/javascript" language="javascript" src="ceres.js"></script></head><body><a href="?p=page1">page1</a> | <a href="?p=page2">page2</a> | <a href="?p=page3">page3</a><br><table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><tr><form name="login" method="post" action="checklogin.php"><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"><tr><td colspan="3"><strong>Member Login </strong></td></tr><tr><td width="78">Username</td><td width="6">:</td><td width="294"><input name="myusername" type="text" id="myusername"></td></tr><tr><td>Password</td><td>:</td><td><input name="mypassword" type="text" id="mypassword" ></td></tr><tr><td> </td><td> </td><td><input type="submit" name="Submit" value="Login"></td></tr></table></td></form></tr></table><div id="main_div"></div></body></html><?$x=isset($_GET['p'])?$_GET['p']:"";switch($x){case"page1":include("page1.php");break;case"page2":include("page2.php");break;case"page3":include("page3.php");break;case"check":include("checklogin.php");break;case"success":include("main.php");break;default:echo"Nopage is selected Yet";}?>
  5. nielcleo

    Php Header

    it still error and i got error because its redirecting on the page its self..im checking my index.php if the session still available it will redirect on the members page.. which has a link..index.php?p=members..any tricks that you can suggest that will not show the original php that having a content of the members page..
  6. nielcleo

    Php Header

    hii would like to ask if it is possible to use index.php?p=page1 header("location:index.php?p=page1"); when i use that in header it sends me The page isn't redirecting properlywhat is the rightway to redirect me in a page without displaying the original php file in the adress bar..
  7. but the username and password doesnt send to the PHP..
  8. how can i insert the validation in database.. with this..index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Login</title> <script type="text/javascript"> var XMLHttpRequestObject = false; if (window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); } else if (window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } function getData(dataSource, divID) { var user_name = document.getElementById('user_name').value var password = document.getElementById('password').value var data = user_name + "|" + password; if(XMLHttpRequestObject) { var obj = document.getElementById(divID); obj.innerHTML = "Loading from " + dataSource; XMLHttpRequestObject.open("POST", dataSource); XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); XMLHttpRequestObject.onreadystatechange = function() { if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { obj.innerHTML = XMLHttpRequestObject.responseText; } } XMLHttpRequestObject.send("data=" + data); } return false; } </script></head><body><h2>Login to this site!</h2><form action="login.html" name="logonForm"><table> <tr> <td> User name: </td> <td> <input id="user_name" name="user_name" type="text" /> </td> </tr> <tr> <td> Password: </td> <td> <input id="password" name="password" type="password" /> </td> </tr> <tr> <td> </td> <td> <br /><input id="logon" type="submit" value="Login" onclick="return getData('checklogin.php', 'loginResultDiv')" /> </td> </tr></table><div id="loginResultDiv"> </div></form></body></html> checklogin.php <?php $data = $_POST['data']; echo "You entered >$data<"; if($data == 'uuserr|password') { echo "<h1>Hello! Welcome to the site!</h1>" ; } else { echo "<h1>Invalid Login! Try Again</h1>"; }?> and i also trying putting $data = stripslashes($data); $data = mysql_real_escape_string($data); for protection but it doesnt work
  9. what should i need to use:(
  10. i dont have background on javascript sir thats why i got confused what argument should i do.. to gives me the output that i need :(
  11. im not getting it on the part of the http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp :( im confused how to insert the php code on the function
  12. the number of rows.its working when im not using the ajax.. but will go.. http://url.com/checklogin.php and if it satisfy the statement it will redirect on the success page..i want to happen is load the checklogin.php without leaving the index.php..thats why itry to put ajax dynamic content to do that.. but the problem i encounter i always got WRONG USER NAME AND PASSWORD though i input the right one..
  13. here isajax.js/* Simple AJAX Code-Kit (SACK) v1.6.1 *//* ©2005 Gregory Wild-Smith *//* www.twilightuniverse.com *//* Software licenced under a modified X11 licence, see documentation or authors website for more details */function sack(file) {this.xmlhttp = null;this.resetData = function() { this.method = "POST"; this.queryStringSeparator = "?"; this.argumentSeparator = "&"; this.URLString = ""; this.encodeURIString = true; this.execute = false; this.element = null; this.elementObj = null; this.requestFile = file; this.vars = new Object(); this.responseStatus = new Array(2); };this.resetFunctions = function() { this.onLoading = function() { }; this.onLoaded = function() { }; this.onInteractive = function() { }; this.onCompletion = function() { }; this.onError = function() { }; this.onFail = function() { };};this.reset = function() { this.resetFunctions(); this.resetData();};this.createAJAX = function() { try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { this.xmlhttp = null; } } if (! this.xmlhttp) { if (typeof XMLHttpRequest != "undefined") { this.xmlhttp = new XMLHttpRequest(); } else { this.failed = true; } }};this.setVar = function(name, value){ this.vars[name] = Array(value, false);};this.encVar = function(name, value, returnvars) { if (true == returnvars) { return Array(encodeURIComponent(name), encodeURIComponent(value)); } else { this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true); }}this.processURLString = function(string, encode) { encoded = encodeURIComponent(this.argumentSeparator); regexp = new RegExp(this.argumentSeparator + "|" + encoded); varArray = string.split(regexp); for (i = 0; i < varArray.length; i++){ urlVars = varArray[i].split("="); if (true == encode){ this.encVar(urlVars[0], urlVars[1]); } else { this.setVar(urlVars[0], urlVars[1]); } }}this.createURLString = function(urlstring) { if (this.encodeURIString && this.URLString.length) { this.processURLString(this.URLString, true); } if (urlstring) { if (this.URLString.length) { this.URLString += this.argumentSeparator + urlstring; } else { this.URLString = urlstring; } } // prevents caching of URLString this.setVar("rndval", new Date().getTime()); urlstringtemp = new Array(); for (key in this.vars) { if (false == this.vars[key][1] && true == this.encodeURIString) { encoded = this.encVar(key, this.vars[key][0], true); delete this.vars[key]; this.vars[encoded[0]] = Array(encoded[1], true); key = encoded[0]; } urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0]; } if (urlstring){ this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator); } else { this.URLString += urlstringtemp.join(this.argumentSeparator); }}this.runResponse = function() { eval(this.response);}this.runAJAX = function(urlstring) { if (this.failed) { this.onFail(); } else { this.createURLString(urlstring); if (this.element) { this.elementObj = document.getElementById(this.element); } if (this.xmlhttp) { var self = this; if (this.method == "GET") { totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString; this.xmlhttp.open(this.method, totalurlstring, true); } else { this.xmlhttp.open(this.method, this.requestFile, true); try { this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") } catch (e) { } } this.xmlhttp.onreadystatechange = function() { switch (self.xmlhttp.readyState) { case 1: self.onLoading(); break; case 2: self.onLoaded(); break; case 3: self.onInteractive(); break; case 4: self.response = self.xmlhttp.responseText; self.responseXML = self.xmlhttp.responseXML; self.responseStatus[0] = self.xmlhttp.status; self.responseStatus[1] = self.xmlhttp.statusText; if (self.execute) { self.runResponse(); } if (self.elementObj) { elemNodeName = self.elementObj.nodeName; elemNodeName.toLowerCase(); if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") { self.elementObj.value = self.response; } else { self.elementObj.innerHTML = self.response; } } if (self.responseStatus[0] == "200") { self.onCompletion(); } else { self.onError(); } self.URLString = ""; /* These lines were added by Alf Magne Kalleland ref. info on the sack home page. It prevents memory leakage in IE */ delete self.xmlhttp['onreadystatechange']; self.xmlhttp=null; self.responseStatus=null; self.response=null; self.responseXML=null; break; } }; this.xmlhttp.send(this.URLString); } }};this.reset();this.createAJAX();} ajax-dynamic-content.js /************************************************************************************************************Ajax dynamic contentCopyright (C) 2006 DTHMLGoodies.com, Alf Magne KallelandThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USADhtmlgoodies.com., hereby disclaims all copyright interest in this scriptwritten by Alf Magne Kalleland.Alf Magne Kalleland, 2006Owner of DHTMLgoodies.com************************************************************************************************************/var enableCache = true;var jsCache = new Array();var dynamicContent_ajaxObjects = new Array();function ajax_showContent(divId,ajaxIndex,url,callbackOnComplete){var targetObj = document.getElementById(divId);targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;if(enableCache){ jsCache[url] = dynamicContent_ajaxObjects[ajaxIndex].response;}dynamicContent_ajaxObjects[ajaxIndex] = false;ajax_parseJs(targetObj);if(callbackOnComplete) { executeCallback(callbackOnComplete);}}function executeCallback(callbackString) {if(callbackString.indexOf('(')==-1) { callbackString = callbackString + '()';}try{ eval(callbackString);}catch(e){}}function ajax_loadContent(divId,url,callbackOnComplete){if(enableCache && jsCache[url]){ document.getElementById(divId).innerHTML = jsCache[url]; ajax_parseJs(document.getElementById(divId)) evaluateCss(document.getElementById(divId)) if(callbackOnComplete) { executeCallback(callbackOnComplete); } return;}var ajaxIndex = dynamicContent_ajaxObjects.length;document.getElementById(divId).innerHTML = 'Loading content - please wait';dynamicContent_ajaxObjects[ajaxIndex] = new sack();if(url.indexOf('?')>=0){ dynamicContent_ajaxObjects[ajaxIndex].method='GET'; var string = url.substring(url.indexOf('?')); url = url.replace(string,''); string = string.replace('?',''); var items = string.split(/&/g); for(var no=0;no<items.length;no++){ var tokens = items[no].split('='); if(tokens.length==2){ dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]); } } url = url.replace(string,'');}dynamicContent_ajaxObjects[ajaxIndex].requestFile = url; // Specifying which file to getdynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url,callbackOnComplete); }; // Specify function that will be executed after file has been founddynamicContent_ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function}function ajax_parseJs(obj){var scriptTags = obj.getElementsByTagName('SCRIPT');var string = '';var jsCode = '';for(var no=0;no<scriptTags.length;no++){ if(scriptTags[no].src){ var head = document.getElementsByTagName("head")[0]; var scriptObj = document.createElement("script"); scriptObj.setAttribute("type", "text/javascript"); scriptObj.setAttribute("src", scriptTags[no].src); }else{ if(navigator.userAgent.toLowerCase().indexOf('opera')>=0){ jsCode = jsCode + scriptTags[no].text + '\n'; } else jsCode = jsCode + scriptTags[no].innerHTML; } }if(jsCode)ajax_installScript(jsCode);}function ajax_installScript(script){ if (!script) return; if (window.execScript){ window.execScript(script) }else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery window.setTimeout(script,0); }else{ window.setTimeout( script, 0 ); }}function evaluateCss(obj){var cssTags = obj.getElementsByTagName('STYLE');var head = document.getElementsByTagName('HEAD')[0];for(var no=0;no<cssTags.length;no++){ head.appendChild(cssTags[no]);}}
  14. Hi, i have here basic login system.. i tried to use ajax ..my problem is the data from the form was not send to checklogin.php thats why its always prompt WRONG USER NAME AND PASSWORD.. here's the code... login.php <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>New Page 1</title><script type="text/javascript" language="javascript" src="ceres.js"></script></head><body><table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><tr><form name="login" method="post" action="checklogin.php"><td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"><tr><td colspan="3"><strong>Member Login </strong></td></tr><tr><td width="78">Username</td><td width="6">:</td><td width="294"><input name="myusername" type="text" id="myusername" onKeyPress="return force(this.name,this.form.id,event)"></td></tr><tr><td>Password</td><td>:</td><td><input name="mypassword" type="text" id="mypassword" ></td></tr><tr><td> </td><td> </td><td><input type="submit" name="Submit" value="Login" onclick="ajax_loadContent('main','checklogin.php');return false"></td></tr></table></td></form></tr></table> <div id="main_div"></div></body></html> index.php <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>New Page 1</title><script type="text/javascript" src="js/ajax.js"></script><script type="text/javascript" src="js/ajax-dynamic-content.js"></script></head><body> <div id="load_div"></div> <div id="main"></div> <script type="text/javascript">ajax_loadContent('main','login.php');</script></body></html> checklogin.php <?php$host="localhost"; // Host name$username=""; // Mysql username$password=""; // Mysql password$db_name=""; // Database name$tbl_name="login"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// username and password sent from form$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];// To protect MySQL injection (more detail about MySQL injection)$myusername = stripslashes($myusername);$mypassword = stripslashes($mypassword);$myusername = mysql_real_escape_string($myusername);$mypassword = mysql_real_escape_string($mypassword);$sql="SELECT * FROM $tbl_name WHERE userid='$myusername' and user_pass='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $mypassword and redirect to file "login_success.php"session_register("myusername");session_register("mypassword");header("location:login_success.php");}else {echo "Wrong Username or Password";}?>
×
×
  • Create New...