Geeky Bird Geeky Bird - 5 months ago 7
jQuery Question

ECHO a <script> via php. I want to know the proper way to do it

I have a url path that will send through this

myGlobalFunction();
from a different file.

So the following script tag will catch the user on the website root and forward him to the login page. I can't seem to make this working. I know i am messing the single and double quotes. :(

if (!isset($_SESSION['role']))
{
echo '<script>window.location.assign("'echo myGlobalFunction();'/onboardingform/core/admin/login.php")</script>';
exit();

}

Answer

You're not concatenating the strings properly. Use . operator to concatenate the string like this.

<?php

echo '<script>window.location.assign("'. myGlobalFunction().'/onboardingform/core/admin/login.php")</script>';

And there is no need of echo statement inside another echo.

Comments