Guest User

Untitled

a guest
Jan 26th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. I've got the following code to work now, but there are still a few problems:
  2.  
  3. $("#action_button").click(function() {
  4. $('#success').append("Hello");
  5. var username = $("#username").val();
  6. var password = $("#password").val();
  7. var dataString = '&username=' + username + '&password=' + password;
  8. if(username=='' || password=='') {
  9. $('#success').fadeOut(200).hide();
  10. $('#error').fadeOut(200).show();
  11. } else {
  12. $.ajax({
  13. type: "POST",
  14. url: "processing/logsig.php",
  15. data: dataString,
  16. json: {session_state: true},
  17. success: function(data){
  18. if(data.session_state == true) {
  19. $('#success').append("True");
  20. } else if(data.session_state == fale) {
  21. $('#success').append("False");
  22. }
  23. }
  24. });
  25. }
  26. });
  27.  
  28. It'll process the Php script, but it won't process the JSON... I've got $('#success').append("Hello"); working, but I can't seem to get the ajax json data return to work... It processes the php script because when I reload the page after clicking the action_button, it loads the page that is supposed to come after the user logs in. Any ideas? Also, below is the revised php script:
  29.  
  30. <?php
  31. header('Content-type:application/json');
  32. session_start();
  33. include("global-settings.php");
  34. mysql_connect($dbhost, $dbuser, $dbpass)or die("Could Not Connect: " . mysql_error());
  35. mysql_select_db($dbname) or die(mysql_error());
  36.  
  37. $email = mysql_real_escape_string(strip_tags($_POST["username"]));
  38. $password = sha1($_POST["password"]);
  39. $sql = "SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'";
  40. $result = mysql_query($sql); // or exit("ERROR: " . mysql_error() . "<br>IN QUERY: " . $sql);
  41.  
  42. if (mysql_num_rows($result) > 0) {
  43. $row = mysql_fetch_array($result);
  44. $_SESSION["userid"] = $row['user_pid'];
  45. $json = json_encode(array('session_state' => true));
  46. echo $json;
  47. } else {
  48. $userid_generator = uniqid(rand(), false);
  49. mysql_query("INSERT INTO users (user_pid, email, password, datetime_registered, is_leader) VALUES ('$userid_generator', '{$email}', '{$password}', NOW(), 'no')");
  50. $id = mysql_insert_id();
  51. $leaders = mysql_query("SELECT * FROM users WHERE is_leader LIKE '%yes%'");
  52. while($rows = mysql_fetch_array($leaders)) {
  53. if ($rows['is_leader'] == 'yes') {
  54. $leader_id = $rows['user_pid'];
  55. mysql_query("INSERT IGNORE INTO friends (node1id, node2id, friends_since, friend_type)
  56. VALUES('$leader_id', '$userid_generator', NOW(), 'full')");
  57. }
  58. $_SESSION["userid"] = $userid_generator;
  59. }
  60. if(is_dir($userid_generator)) {
  61. echo "Something wen't wrong. A bug report has been sent and we are doing what we can to fix it.";
  62. $message = 'Registration problem on account number $userid_generator. The user succesfully registered, but there is already
  63. a directory with the account id of $userid_generator.';
  64. mail($bug_report_email, "Registration Bug!", $message);
  65. } else {
  66. mkdir('media/User-PID{' . $userid_generator . '}', 0777);
  67. mkdir('media/User-PID{' . $userid_generator . '}/photos', 0777);
  68. mkdir('media/User-PID{' . $userid_generator . '}/backups', 0777);
  69. mkdir('media/User-PID{' . $userid_generator . '}/videos', 0777);
  70. mkdir('media/User-PID{' . $userid_generator . '}/documents', 0777);
  71. mkdir('media/User-PID{' . $userid_generator . '}/developer', 0777);
  72. mkdir('media/User-PID{' . $userid_generator . '}/developer/apps', 0777);
  73. mkdir('media/User-PID{' . $userid_generator . '}/developer/themes', 0777);
  74. mkdir('media/User-PID{' . $userid_generator . '}/xml', 0777);
  75. }
  76. $json = json_encode(array('session_state' => false));
  77. echo $json;
  78. }
  79. ?>
Add Comment
Please, Sign In to add comment