Using SESSION variable in a Javascript
Using SESSION variable in a Javascript
At the top of the page, Before the html tag, I have this
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?>
Inside the HTML in the head section I have this:
<script>
window.onload = function()
{
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
var args = "<?php echo $_SESSION['params'] ?>";
url += args;
alert(url);
}
</script>
But what I get is this , Why?
http://beleuramyhome.org.au/phpBB3/viewtopic.php?<?php echo $_SESSION['params'] ?>
Instead of the combined strings?
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?>
Inside the HTML in the head section I have this:
<script>
window.onload = function()
{
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
var args = "<?php echo $_SESSION['params'] ?>";
url += args;
alert(url);
}
</script>
But what I get is this , Why?
http://beleuramyhome.org.au/phpBB3/viewtopic.php?<?php echo $_SESSION['params'] ?>
Instead of the combined strings?
Re: Using SESSION variable in a Javascript
Is the other PHP code parsed correctly?
Re: Using SESSION variable in a Javascript
Yes, plenty, but not in this page.
This seems to me such a simple thing to do...
Why not working?
Thanks
This seems to me such a simple thing to do...
Why not working?
Thanks
Re: Using SESSION variable in a Javascript
The code looks correct as far as I can tell.
Re: Using SESSION variable in a Javascript
I think:
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
should be:
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php/?";
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
should be:
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php/?";
Re: Using SESSION variable in a Javascript
No, the link to get here on the website in my email is without that extra slash...
"viewtopic.php?f=75&t=81069&e=1&view=unread#unread"
I am lost with this...
"viewtopic.php?f=75&t=81069&e=1&view=unread#unread"
I am lost with this...
Re: Using SESSION variable in a Javascript
Yes i know, when i use it all as one string it works.
It also works if i add the two strings as strings
It doesn't work if i try to get the arguments using the $_SESSION...
It also works if i add the two strings as strings
It doesn't work if i try to get the arguments using the $_SESSION...
Re: Using SESSION variable in a Javascript
I have replicated exactly your code:
Code: Select all
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<link href="index.css" rel="stylesheet">
<script>
window.onload = function()
{
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
var args = "<?php echo $_SESSION['params'] ?>";
url += args;
alert(url);
}
</script>
</head>
<body>
<div id="container">
</div>
</body>
</html>
Re: Using SESSION variable in a Javascript
Well, it seems something is wrong at my end.
In design mode, I insert the Javascript script into the head section,
but when looking at the uploaded result on the server, it is missing the entire script
This will explain why, what seems to be a simple thing, doesn't work.
Below is the source of the page
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<style>
body
{
background-color: transparent;
color: #000000;
font-family: Arial;
font-weight: normal;
font-size: 13px;
line-height: 1.1875;
margin: 0;
padding: 0;
}
</style>
<link href="MasterFrame.css" rel="stylesheet">
</head>
<body>
<script src="iframeurl.js"></script>
</body>
</html>
In design mode, I insert the Javascript script into the head section,
but when looking at the uploaded result on the server, it is missing the entire script
This will explain why, what seems to be a simple thing, doesn't work.
Below is the source of the page
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<style>
body
{
background-color: transparent;
color: #000000;
font-family: Arial;
font-weight: normal;
font-size: 13px;
line-height: 1.1875;
margin: 0;
padding: 0;
}
</style>
<link href="MasterFrame.css" rel="stylesheet">
</head>
<body>
<script src="iframeurl.js"></script>
</body>
</html>
Re: Using SESSION variable in a Javascript
Maybe you have enabled "Generate external file for page specific JavaScripts" in Tools->Options->HTML?
This will move the script to another file and therefore it will not be processed by the PHP parser,.
This will move the script to another file and therefore it will not be processed by the PHP parser,.
Re: Using SESSION variable in a Javascript
Yes, the two options were checked, have no idea how.
Anyway, the generated code below is still not doing it, why?
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<style>
body
{
background-color: transparent;
color: #000000;
font-family: Arial;
font-weight: normal;
font-size: 13px;
line-height: 1.1875;
margin: 0;
padding: 0;
}
</style>
<link href="MasterFrame.css" rel="stylesheet">
<script>
window.onload = function()
{
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
var args = <?php echo $_SESSION['params'] ?>;
url += args;
//document.getElementById("InlineFrame1").setAttribute("src", url);
alert(url);
}
</script>
</head>
<body>
</body>
</html>
Anyway, the generated code below is still not doing it, why?
<?php
session_start();
$str = "f=6&t=3&e=1&view=unread#unread";
$_SESSION['params'] = $str;
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 14 - http://www.wysiwygwebbuilder.com">
<style>
body
{
background-color: transparent;
color: #000000;
font-family: Arial;
font-weight: normal;
font-size: 13px;
line-height: 1.1875;
margin: 0;
padding: 0;
}
</style>
<link href="MasterFrame.css" rel="stylesheet">
<script>
window.onload = function()
{
var url = "http://beleuramyhome.org.au/phpBB3/viewtopic.php?";
var args = <?php echo $_SESSION['params'] ?>;
url += args;
//document.getElementById("InlineFrame1").setAttribute("src", url);
alert(url);
}
</script>
</head>
<body>
</body>
</html>
Re: Using SESSION variable in a Javascript
I mean, not showing the alert()...
Re: Using SESSION variable in a Javascript
Did you look in the browser's debugger for errors? (F12)
Re: Using SESSION variable in a Javascript
Hi Pablo,
Just fixed it, there was a mismatch generated with the CSS
I created again the page from scartch and all good
Thanks again
Just fixed it, there was a mismatch generated with the CSS
I created again the page from scartch and all good
Thanks again