I have a variable I need to drop into a javascript file and can't seem to get any results. I've tried making the .js into a php and adding an echo but it doesn't work.
I have a file that calls this in it
<script type="text/javascript" src="/file.php"></script>
Inside of file.php I have this line
style: {
color: '#<?php echo $_SESSION['colorOne']; ?>'
}
Everything works perfect when I replace the php with an actual color (#FFFFFF). I run into problems when I add the php.
PHP can emulate any content you'd like, even Images, PDF and Office files.
First, don't confuse Javascript with CSS.
<link rel="stylesheet" href="/file.php">
At the beginning of the file.php
, make sure you start the session:
<?php
session_start();
?>
.style: {
color: #<?php echo $_SESSION['colorOne']; ?>;
}
If this does not work, you should debug if your session is init and working correctly, like make a new PHP file and put in <?php session_start(); print_r($_SESSION); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With