1

It may look like a stupid question, but I went through various pages since 2 days, and didn't get to a solution by myself. So I made a session variable like this:

<?php
session_start();

$_SESSION['currentpage']="home";
?>

(I checked, it does make the variable and assign it right.)

Then I tried to use it as a parameter here:

<body onload="changepage($_SESSION['currentpage'])">

It doesn't pass the variable. I tried to put it into directly the function, like not as a parameter, but inside it, doesn't work either. I am seriously missing something here I bet. Can someone please help out? Thanks.

0

2 Answers 2

5

You are missing the PHP tags:

<body onload="changepage('<?php echo $_SESSION['currentpage']; ?>')">
Sign up to request clarification or add additional context in comments.

3 Comments

Or the shorter version, if your php.ini allows these: <?=$_SESSION['currentpage']; ?>
@StefanCandan Yeah, sure. That just comes down to personal preference, both works.
Oh my god. Thanks a lot, works now. Didn't know how to make it phpish there..:)
0
<body onload="changepage($_SESSION['currentpage'])">

Should be

<body onload="changepage('<?php echo $_SESSION['currentpage'];?>')">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.