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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:21+00:00 2026-05-29T15:41:21+00:00

When I set the session in a file called signin.php : $user = ‘john’;

  • 0

When I set the session in a file called signin.php:

$user = 'john';
$_SESSION['user'] = $user;

echo "
<script>
$.ajax({
    url: 'array.php', 
    type: 'post',
    data: {'user': $user}
});
";

In another file (index.php), I want to get:

<?php

session_start();

echo "log in as <span id=\"user\"></span><br/>"; 
$user =  $_POST['user']

echo "
<script>
$('#user').text(function() {
    setInterval(function(){
        $('#user').load($user).fadeIn(10);
    }, 1000);
</script>
";

?>

I know I completely messed up with the code. What I want is that when the session is set in the signin.php file, I want $user in the content in “log in as $user” automatically updated without refresh the page, any help will be greatly appreciated!

  • 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-05-29T15:41:23+00:00Added an answer on May 29, 2026 at 3:41 pm

    First, work on diligently formatting your code more effectively. That code you posted was all over the place. This is a bad practice to get in and leads to errors, bugs, and other effects which can be difficult find due to the formatting.

    If I follow what you’re doing, when someone logs in and then hits the index.php page, you want to be able to load a user’s information from another file that will give back the user data asynchronously?

    signin.php

    Your code is confusing in what it appears to be doing; you simply have not told us enough both in code and explanation to understand what the workflow entails.

    For instance, in signin.php, you’re echoing a <script> tag that does an $.ajax() request, but who/what get’s this code? Is this part of the signin.php content, if the user successfully logs in? Does this mean the signin.php will load the page to use the $.ajax() here, or is that meant to run from the $.ajax() on success?

    If it’s the latter, you need to return regular Javascript with no markup (like a <script> tag wrapped around it) and use dataType: 'script' in the options.

    Also, I would at least use a more descriptive word than array.php; if you’re getting user data from it, name that file something like userdata.php.

    $user = 'john';
    $_SESSION['user'] = $user;
    
    echo "
    <script>
    $.ajax({
        url: 'userdata.php', 
        type: 'post',
        dataType: 'script',
        data: 'json=' + jQuery.serialize({user: '$user'})
    });
    ";
    

    Then in userdata.php, you can access it with $_POST['json'].

    index.php

    This honestly makes no sense:

    $('#user').text(function() {
        setInterval(function(){
            $('#user').load($user).fadeIn(10);
        }, 1000);
    );
    

    Why is the setInterval() in an anonymous function that’s run while setting $.text()? This is one of those What? moments, where I’m not even sure what you’re trying to accomplish.

    Before that though, you have:

    $user = $_POST['user'] <<< Note here, you need a ; at the end
    

    Why is this a $_POST? Does the signin.php use $_POST to log a user in? Here, I believe you want $_SESSION (I think, hope, ??), since that’s where you stored the username when the user logged in using signin.php.

    This is my best guess as to what you’re trying to do (assuming you’re returning JSON-formatted data):

    <?php
    
    session_start();
    
    $user =  $_SESSION['user'];
    
    echo "log in as <span id=\"user\"></span><br/>"; 
    
    echo "
    <script>
    $.ajax({
        url: 'userdata.php',
        type: 'post',
        data: 'json=' + jQuery.serialize({user:'$user'}),
        dataType: 'json',
        success: function(data){
            $('#user').text(data.fullname);
        }
    });
    </script>
    ";
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain to me why this happens? I have a file called profile.php
I have a session variable that I set like this: <?php $token = md5(uniqid(rand(),
I have a global.php file that I call from the top of every script.
I made a php file, called createCaptcha.php, and the code is this : create_image();
What we use to set the session time out in php. I found following:
I have an image upload script, originally I kept it in a file called
I am trying to set Session values using a IHttpModule. I have set the
I have tried the obvious SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED, but my
I am currently in C# and I have set Session variables on each page.
I set a session like this: request.session['mykey']= 33 How do I clear it? I

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.