NorKayak
-
Posts
8 -
Joined
-
Last visited
Posts posted by NorKayak
-
-
14 minutes ago, DanEthical said:
Have you tried with a Modal or JS alert?
Probably use a Session or Cookie to determine who is online?
I know a little about session and cookie but how can I use that to know if a user is actually online and interact with him?
-
I have a general question. Just need to be put on the right direction.
I made that little game I put on a server. Now I wish that 2 persons could play against each other online. So I made a signup/login and I can list all the users against which you would like to play. Now how could I know who is actually online and send him/her an alert when it is his/her turn to play?
My first idea was to send emails every time it's a player turn to make a move; but there must be something more elegant to do in-game?
I'm having a lot of fun coding that thing and any help would be great 🙂
-
Also, is your SESSION variable called "Sess_Name" or "$Sess_Name"? Note that your code adds a dollar sign to the name.
You mean I should remove the $ sign?
-
$_SESSION variables are global. Have you got session_start() at the top of the page?
Yes:
<?phpob_start();session_start();?> -
When viewing the page in your browser, does the correct name appear in the source code?
Are you getting any JavaScript errors? In case you're not aware, you can right-click the page in a browser like Chrome. Then click the Inspect Element option. The errors would be displayed in the Console tab.
Thanks I didn't think about that... I checked and the codes reads: var tempoVar = null;
It seems then that the $_SESSION variable is not recognized in the function. Could that have something to do with declaring the variable global? So I tried this:
<?php$theName = global $_SESSION['$Sess_Name'];?>But the browser doesn't accept it... -
It looks like json_encode() adds the quotes for you. Try changing this:
var tempoVar = "<?php echo json_encode($theName); ?>";
To this:var tempoVar = <?php echo json_encode($theName); ?>;
Ok, I tried. Still not working. The diference is before I had the output "NULL" and now nothing...
-
Hi;
I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables.
I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL.
Why is that? Where is the problem?
ThankHere is my code:
function InitField() {
<?php$theName = $_SESSION['$Sess_Name'];?>var tempoVar = "<?php echo json_encode($theName); ?>";var myInput = document.getElementById('theSurname');myInput.value = tempoVar;}
How to detect if a user is online?
in PHP Coding Help
Posted
Thanks guys for all the good infos. 👍😊 Gonna have a look into all that and see what I can come up with.