[SOLVED] Get $_SESSION variable from the php page it is on.

Get help using Construct 2

Post » Tue May 05, 2015 8:05 am

I have a login system that loads a .php page and that displays that you are logged in at the top of the screen like this..

Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

Then below that on the page will be the whole construct2 bit. (the canvas)
So construct2 has nothing to do with the login system I use and it will be on a .php page.

QUESTION:
How do I grab that $_SESSION variable and load it into a global variable in Construct2?


Thanks.
Last edited by UberDark on Tue May 05, 2015 10:33 pm, edited 1 time in total.
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue May 05, 2015 10:09 am

Set a javascript variable in the web page, and fetch it using the browser object's execute custom javascript.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue May 05, 2015 10:22 am

All i have on the page now (besides the construct2 portion) is:

Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

Not sure how to add javascript to the page but something like..

<script>
var currentuser = $_SESSION['user_name'];
</script>


Would that work? Or am i totally off?
Never done any javascripting..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue May 05, 2015 10:24 am

UberDark wrote:All i have on the page now (besides the construct2 portion) is:

Hey, <?php echo $_SESSION['user_name']; ?>. You are logged in.

Not sure how to add javascript to the page but something like..

<script>
var currentuser = $_SESSION['user_name'];
</script>


Would that work? Or am i totally off?
Never done any javascripting..



<html>

mehhh



<body>
<javascript>

var username = "<?php echo $_SESSION[username]; ?>";

</javascript>
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue May 05, 2015 10:25 am

I seeee. So you can include php into the javascript.
Cool bud. Cheers :)
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue May 05, 2015 10:29 am

Just as long as your index file has a .php extension :) (simply change .html to .php and make sure your links to it are updated too.)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue May 05, 2015 10:44 am

:)
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue May 05, 2015 8:44 pm

@lennaert

Let me bother you some more maestro..

I get the concept of what you are saying but since i only just learned a bit of php and now i have to get into javascript i am finding it hard to do.
In Construct2 i should basicly do something like this?

System>Set variableX to "ExecJS('username')" ?

Is this correct? Or is it not ExecJS I should be using? Perhaps EvalJS?
Completely lost it now..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue May 05, 2015 9:23 pm

set var = Browser.ExecJS("window.MyUsername")


in the index file I have :

<script>
var MyUsername = "Lennaert";
</script>
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue May 05, 2015 9:31 pm

Hold on.. I initially asked if <script> was the way to go but you corrected me it should be <javascript>..
Now you use <script>?
Confusing haha
Cheers though man. You rule
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Next

Return to How do I....?

Who is online

Users browsing this forum: ST314 and 31 guests