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

  • SEARCH
  • Home
  • 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 8873981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:36:19+00:00 2026-06-14T18:36:19+00:00

I know it looks like a banal question but please read the whole thing,

  • 0

I know it looks like a banal question but please read the whole thing, I am stumped by this.

I have an AJAX call on one of my pages, it’s a dynamic messaging system:

function validateMessage(){

  var recipient = document.getElementById("send_to").value;
  var subject = document.getElementById("popup_subject").value;
  var message = document.getElementById("popup_message").value;

  var parameters="message="+message+"&recipient="+recipient+"&subject="+subject;

   if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
   }
   else
   {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }

   xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById("error_mess").innerHTML = xmlhttp.responseText;
    }
  }

  xmlhttp.open("POST","include/send_message.php",false);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  xmlhttp.send(parameters);

  }

It’s implemented as synchronous for a reason, that’s not the issue here. I tried switching to asynchronous and the problem remains.

This is the send_message.php file, it just grabs the POST variables and saves them into the database:

<?php
session_start();
include('db.php');
dbConnect();

$message=$_POST['message'];
$subject=$_POST['subject'];
$recipient=$_POST['recipient'];

$result=mysql_query("select * from korisnici where username='$recipient' ") or die(mysql_error());
$row=mysql_fetch_array($result);
$num=mysql_num_rows($result);

if($recipient=="Poruka za..." || $subject=="Naslov..." || $message=="Poruka" || $recipient=="" || $subject=="" || $message=="")
    echo "<p style='color:red;'>Morate popuniti sva polja.</p>";
elseif($num==0)
    echo "<p style='color:red;'>Korisnik ne postoji.</p>";
else{
    $prima=$row['id_user'];
    $salje=$_SESSION['id_user'];
    mysql_query("insert into poruke (salje, prima, naslov, poruka)
        values ('$salje', '$prima', '$subject', '$message') ") or die(mysql_error());
    echo "<p style='color:green;'>Poruka uspješno poslata!</p>";
}

?>

However, when I tried to save the $_SESSION[‘id_user’] variable (as the sender) I found a problem – it turns out the session is being destroyed every time this AJAX call runs! So doing print_r($_SESSION) right after session_start() prints an empty array.

The session is alive on the original page itself, and refreshing that page keeps the session alive. Only when I click the button to make the AJAX call, the session disappears. Can someone spot the issue?

  • 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-14T18:36:20+00:00Added an answer on June 14, 2026 at 6:36 pm

    Here’s the solution, as given to me by he technical support team of my hosting provider:

    Set suhosin.session.encrypt=Off in /home/username/public_html

    Set suPHP_ConfigPath /home/username/public_html in .htaccess.

    And that’s it, works now. No time to investigate these settings at this point, but I hope this will help someone in the same situation.

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

Sidebar

Related Questions

I know this looks like a stupid question but how to download this url?
I know this looks like a silly question, but using object oriented stuff with
I know this may looks like a previously asked question but I'm facing a
I know this question looks like previous questions, but it is slightly different. I
I want to know what this looks like. I don't have any ideas about
This looks like a long shot, but does anyone know of a way to:
I know this question looks like a dupe: I checked and it's not In
I know this looks like a lot of text, but I think it's a
This looks like a bug, but I'm not sure. As far as I know,
i have a URL that looks like this ......index.php?option=com_jumi&fileid=8&Itemid=34 i know that i can

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.