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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:23:38+00:00 2026-05-22T21:23:38+00:00

I made a simple login using JavaScript, but record the username in a PHP

  • 0

I made a simple login using JavaScript, but record the username in a PHP session.It’s a simple web chat, so I want when the chat page is loaded the user to be forced to pick an username, but after that I want to store that info ina a PHP session and if the page is reloaded for some reason to do a check if $_SESSION[‘UserName’] is empty and if it’s not to stop the script from executing again.I put my login JS in <body onload..> and the code looks like this:

<body onload = "showUser(), showChat(), <?php if ($_SESSION['UserName']==""){
{
  Login();
}?>">

I’m just learning now, so I gues I have some newb mistakes, like I’m almost sure that I’m not calling the Login() function right (it’s JS function), but that’s my strating point.Could anyone explain to me, how should I do the check properly and add the JS function in my PHP code?

P.S And I don’t know if this really matter but if I remove the PHP code and leave liek this:

<body onload = "showUser(), showChat(),Login()">

My script is executed properly and I get everything that should be shown when the page is loaded, but when I add the PHP script and try to load the page I get blank page.I really wonder what’s the reason for this too?

  • 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-22T21:23:39+00:00Added an answer on May 22, 2026 at 9:23 pm

    You can simply call this as:

    <?php 
        if($_SESSION['UserName'] == ""){ 
    ?>
    <body onload="showUser(), showChat()">
    <?php
        }
        else
        {
    ?>
    <body onload="showUser(), showChat(), Login();">
    <?php
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On Windows, testing different OSes is made simple using VMs. Is there a simple
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we
I made a simple counter, but it increments by 2 instead of 1. $handle
I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I've made a simple app for the purpose of posting to a Facebook Page
I made a simple login form where a user can click on a register
I have written a simplte PHP login script which starts a session: //Lets start
I want to make myself a simple webapp using vb.net.I am trying to make
I have made a simple test application for the issue, two winforms each containing
I've made a simple OpenCV application with Visual Studio 2008 and I've built it

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.