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 8706313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:35:07+00:00 2026-06-13T03:35:07+00:00

I’m making a login system, and when I send a request from an AJAX

  • 0

I’m making a login system, and when I send a request from an AJAX connection, the session is not getting set.
Sending the connection:

function onSubmit(form){
    var username = form.username.value;
    var password = form.password.value;
    if(username == ''){
        document.getElementById('error').innerHTML='<font color="red"><b>Please enter a username</b></font>';
        return;
    }
    if(password == ''){
        document.getElementById('error').innerHTML='<font color="red"><b>Please enter a password</b></font>';
        return;
    }
    if(username != '' && password != ''){
        document.getElementById('error').innerHTML='';
        showDiv('loadinglogin');    
        var dataString = 'username='+username+'&password='+password;
    $.ajax({  
      type: "POST",  
      url: "util/login.php",  
      data: dataString,  
      success: function(msg) {  
        if(msg == "ok"){
            document.getElementById('error').innerHTML='<font color="green"><b>Login good, redirecting</b></font>';
            hideDiv('loadinglogin');    
            window.location = "test.php";
        }else{
            document.getElementById('error').innerHTML='<font color="red"><b>Invalid login</b></font>';
            hideDiv('loadinglogin');    
        }
      }  
    }); 



    }
}

Setting the session/handle login:

<?php
include('database.php');
session_start();
function in_db($u,$p){
    $p = md5($p);
    $p = sha1($p);
    $p = sha1($p);
    $p = md5($p);
    $sql = "SELECT * FROM `users` WHERE `username` = '$u' AND `password` = '$p'";
    $result = mysql_query($sql) or die(mysql_error());  
    while($row = mysql_fetch_object($result))
    { 
        return true;    
    }
    return false;
} 
if(isset($_POST['username']) && isset($_POST['password']) && !isset($$_SESSION['user']) && !isset($$_SESSION['pass'])){
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    if(in_db($username,$password)){
        $_SESSION['user'] = $user;
        $_SESSION['pass'] = $pass;
        print("ok");
    }else{
        print("bad");
    }
}else{
    print("bad");
}
?>

Not sure if I’m doing somthing wrong :/

EDIT: I pulled this from ERROR_LOG

[18-Oct-2012 07:27:00 UTC] PHP Warning: session_start() [function.session-start]: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and ‘-,’ in /util/login.php on line 2

PHP.ini

register_globals = off
allow_url_fopen = off

expose_php = Off
max_input_time = 60
variables_order = "EGPCS"
extension_dir = ./
upload_tmp_dir = /tmp
precision = 12
SMTP = relay-hosting.secureserver.net
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="


; Only uncomment zend optimizer lines if your application requires Zend Optimizer support

;[Zend]
;zend_optimizer.optimization_level=15
;zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
;zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
;zend_extension=/usr/local/Zend/lib/Optimizer-3.3.3/ZendExtensionManager.so
;zend_extension_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3/ZendExtensionManager_TS.so


; -- Be very careful to not to disable a function which might be needed!
; -- Uncomment the following lines to increase the security of your PHP site.

;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru,
;             phpinfo, exec, system, dl, fsockopen, set_time_limit,
;                     popen, proc_open, proc_nice,shell_exec,show_source,symlink"
  • 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-13T03:35:08+00:00Added an answer on June 13, 2026 at 3:35 am

    Put session_start(); at very beginning of your file, before include().

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.