Jump to content

PHP Redirect through AJAX


samerhannoun
 Share

Recommended Posts

Dears, Now I am developing a registration script using php AJAX,So when the user fill the field successfull, the script start session and redirect him to the userhome.php and this is a page contain session variable to prevent non-registered users from view it.the problem, when the script redirect the user the userhome.php content will be viewed in the (div/area/span)thats we create it for server respone behinde the reg. form.I don't need to redirect the user using java script, via checking the (div) thats containing server response So what Can I do.Below the script.Regform.php//////<html><head><script src="jax.js"></script><title>Registration test</title></head><body><form name="reg" id="reg1" onsubmit="return validate()">Email:<input type="text" name="umail" id="umail1"><br>Password:<input type="password" id="upass1" name="upass"><br>Study/job:<select name="uspe" id="uspe1"><?include("getlist.php");?><br><input type="button" onclick="validate()" value="join docr" id="bt"></form><span id="msgs"></span></div></body></html>//////////////Jax.jsvar xmlhttpfunction validate(){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Your browser does not support AJAX!"); return; }var un=document.getElementById("umail1").value;var up=document.getElementById("upass1").value;var us=document.reg.uspe.options[document.reg.uspe.selectedIndex].value document.getElementById("bt").value="Loading...";var url ="proc.php?uname=" + un + "&upass=" +up+ "&uspe=" +us;xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function stateChanged(){if (xmlhttp.readyState==4) { x= document.getElementById("msgs").innerHTML=xmlhttp.responseText; if(x=="yes") { window.location = "userhome.php"; } }}function GetXmlHttpObject(){if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); }if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); }return null;}////////proc.php<?$uname=$_GET["uname"];$upass=$_GET["upass"];$uspe=$_GET["uspe"];is_valid_reg($uname,$upass,$uspe);function is_valid_reg($uname,$upass,$uspe){$result = "TRUE";if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $uname)){$result = "FALSE";echo "Please Enter vaild Mail Address";}elseif($result=="TRUE"){include("contfig.php");$sql=mysql_query("select umail from ruser where umail='$uname'");$num=mysql_num_rows($sql);if($num>0){$result= "FALSE";echo "This mail alredy taken by anthor user";}}if($result=="TRUE"){if(strlen($upass)<6){echo "Password too short";$result ="FALSE";}}if($result=="TRUE"){if($uspe=="1"){echo "Please Select Your Study/Job";$result="FALSE";}}if($result=="TRUE"){if ($_SERVER['HTTP_X_FORWARD_FOR']) {$ip = $_SERVER['HTTP_X_FORWARD_FOR'];} else {$ip = $_SERVER['REMOTE_ADDR'];}$rdate=date('d/m/Y-h:m:s');$sql=mysql_query("insert into ruser(umail,upass,uspeid,uip,rdate) values('$uname','$upass','$uspe','$ip','$rdate')");if(!($sql)){die('Error: ' . mysql_error());}else{echo "yes";}}}?>

Edited by Rainjo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...