Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:50:23+00:00 2026-06-02T09:50:23+00:00

This php code is called through ajax from javascript and should return a numeric

  • 0

This php code is called through ajax from javascript and should return a numeric code and a message. I can return an array from the PHP script but when I read the ajax response that response contains more than the returned array, it has the other echoed statements. Is there a way to send information from the Php that is only the return array? I want only the json object {"return_code":0,"return_msg":"Login successful."}.

This is the information returned through ajax to the javascript with alert(login_info);.

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the

date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely
misspelled the timezone identifier. We selected ‘America/New_York’ for
‘EDT/-4.0/DST’ instead in
/Library/WebServer/Documents/Pagelinks_Dev/login_user.php on line 60
{“return_code”:0,”return_msg”:”Login successful.”}

This is the ajax call.

var message = $.ajax({
    url: "login_user.php",
    type: "POST",
    data: { username_email: username_email, upass: user_passwd },
    cache: false,
    async: false,
    success: function (login_info) {
        if (login_info != '') 
        {
          alert(login_info);
        }
    },
    error: function (request, status, error) {
        alert ("status "+status+" error "+error+"responseText "+request.responseText);
    },
}).responseText;

PHP script

<?php include("dbconnect.php"); ?>

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();

function login_user( $username_email, $password_text ) {
    global $dbco;

    $password = md5($password_text);
    $privPost = 1; // 3: max.
    $privSedit = 0;

    $messages = array( 'log_no_un_em' => 'Enter username or email.',
            'log_no_pw' => 'Enter password.',
            'log_un_em_pw_incorrect' => 'Incorrect login info.',
            'log_success' => 'Login successful.'
    );

    $return = array();

    $l_un_em = isset($username_email) ? $username_email : '';
    $l_pword = isset($password_text) ? $password_text : '';

    if (!$l_un_em) {
        /* echo $messages['log_no_un_em'];
        return; */
        $return['return_code'] = -1;
        $return['return_msg'] = $messages['log_no_un_em'];
        echo json_encode($return);
    }
    if (!$l_pword) {
        /* echo $messages['log_no_pw'];
        return; */
        $return['return_code'] = -1;
        $return['return_msg'] = $messages['log_no_pw'];
        echo json_encode($return);
    }

    mysql_select_db("luxcal", $dbco);

    while (true) {
        $md5_pw = md5($password_text);
        $r_getuser = mysql_query("SELECT * FROM users WHERE (user_name = BINARY '".mysql_real_escape_string($l_un_em)."' OR email = '".mysql_real_escape_string($l_un_em)."') AND (password = '$md5_pw' OR temp_password = '$md5_pw') AND status >= 0");
        if (mysql_num_rows($r_getuser) == 0) {
            /* echo $messages['log_un_em_pw_incorrect'];
            return; */
            $return['return_code'] = -1;
            $return['return_msg'] = $messages['log_un_em_pw_incorrect'];
            echo json_encode($return);
        }
        $row = mysql_fetch_assoc($r_getuser);
        /* if ($row['privs'] < 1) { echo $messages['log_no_privs']; break; } */
        if ($row['temp_password'] == $md5_pw) { //new password
            mysql_query("UPDATE users SET password = '".$md5_pw."', temp_password = NULL WHERE user_id = '{$row['user_id']}'");
        }
        $today = date('Y-m-d');
        if ($row['login_0'][0] == '9') { //first login
            mysql_query("UPDATE users SET login_0 = '".$today."', login_1 = '".$today."', login_cnt = 1 WHERE user_id = '{$row['user_id']}'");
        } else {
            mysql_query("UPDATE users SET login_1 = '".$today."', login_cnt = login_cnt+1 WHERE user_id = '{$row['user_id']}'");
        }
        $_SESSION['uid'] = $row['user_id'];
        $_SESSION['unm'] = stripslashes($row['user_name']);
        $_SESSION['uml'] = stripslashes($row['email']);
        $_SESSION['cL'] = $row['language'];
        /* echo '<meta http-equiv="refresh" content="0;url=livemass_CENTER34.php">'; */ //default page
        break;
    }

    $return['return_code'] = 0;
    $return['return_msg'] = $messages['log_success'];

    echo json_encode($return);
    /* return; */
}

echo login_user(trim($_REQUEST['username_email']), trim($_REQUEST['upass']));

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:50:24+00:00Added an answer on June 2, 2026 at 9:50 am

    If you want to return json, you can’t have any other text outputted with the json string. Change ini_set('display_errors', 1); to ini_set('display_errors', 0);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I am using this PHP code: if (isset($_GET['c'])) { $pages = array(home, upload, signup);
I am trying to write PHP code to loop through an array to create
i use json_encode to send back data from php to jquery through ajax. and
My .php code in a file fetchvalues.php looks like this: echo json_encode(array($PostedDate.Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email)); This file
Can PHP's ob_start be called more then once? Sorry if this is a dumb
This PHP code... 207 if (getenv(HTTP_X_FORWARDED_FOR)) { 208 $ip = getenv('HTTP_X_FORWARD_FOR'); 209 $host =
I have this php code: if ($merchant_rows > 0){ while($r=mysql_fetch_array($get_merchant)){ $merchant_id = $r['merchant_id']; }
I'm using this php code in image.php file to merge a png image with
Say i have this PHP code: $FooBar = a string; i then need a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.