ajax - PHP/JSON Login script (Twitter style) not setting sessions -
i'm having trouble getting twitter style login work properly, reason gets stuck at
session_register("useremail"); session_register("userpass");
and doesn't redirect after it. if enter wrong account data, works , appropriate error message pops up.
this full code:
<?php if(empty($_post['email']) || empty($_post['password'])) { die(msg(0,"all fields required")); } if(!(preg_match("/^[\.a-z0-9_\-\+]+[@][a-z0-9_\-]+([.][a-z0-9_\-]+)+[a-z]{1,4}$/", $_post['email']))) die(msg(0,"you haven't provided valid e-mail")); $host="localhost"; $username="root"; $password="x"; $db_name="x"; $tbl_name="x"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $useremail=$_post['email']; $userpass=$_post['password']; $useremail = stripslashes($useremail); $userpass = stripslashes($userpass); $useremail = mysql_real_escape_string($useremail); $userpass = mysql_real_escape_string($userpass); $sql="select * $tbl_name email='$useremail' , password='$userpass'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("useremail"); session_register("userpass"); echo msg(1,"/backoffice/"); } else { echo msg(0,"invalid e-mail or password."); } function msg($status,$txt) { return '{"status":'.$status.',"txt":"'.$txt.'"}'; } ?>
and js part
$(document).ready(function(){ $('#signin').submit(function(e) { login(); e.preventdefault(); }); }); function login() { hideshow('loadinglogin',1); error(0); $.ajax({ type: "post", url: "submit_login.php", data: $('#signin').serialize(), datatype: "json", success: function(msg){ if(parseint(msg.status)==1) { window.location=msg.txt; } else if(parseint(msg.status)==0) { error(1,msg.txt); } hideshow('loadinglogin',0); } }); } function hideshow(el,act) { if(act) $('#'+el).css('visibility','visible'); else $('#'+el).css('visibility','hidden'); } function error(act,txt) { hideshow('error',act); if(txt) $('#error').html(txt); }
session_register() deprecated.
use:
session_start(); $_session['useremail'] = @useremail; $_session['password'] = @password;
Comments
Post a Comment