javascript - Using PHP to parse URL and provide it as variable to HTML -
since couldn't find answer question anywhere, here comes question. before that, answers/helps in anyway.
the pseudo-code of index.php page is:
<html> <head><script> <?php $links = parse_ini_file('links.ini'); if(isset($_get['l']) && array_key_exists($_get['l'], $links)){ $my_phpvar = $links[$_get['l']]; } else{ header('http/1.0 404 not found'); echo 'unknown link.'; } ?> var myjsvar= <?php echo $my_phpvar; ?> function go(){ document.cookie = "visited=; expires=thu, 01 jan 1970 00:00:00 gmt"; window.location.href = "myjsvar"; } </script></head> <body><a id="mya1" href="javascript:go();" target="_blank">click</a></body> </html>
as evident, in above code myjsvar comes my_phpvar, , my_phpvar comes seperate file links.ini (sorry if i'm boring you, since it's evident in code, don't wanna miss out can help)
i have added rules .htaccess file in root of directory index.php located. rules have been added are
rewriteengine on rewritecond $1 !^(index\.php) rewriterule ^(.*)$ index.php?l=$1 [l]
the links.ini file looks this:
ex = https://www.example.com
so main issue is: when browse url http://www.yoursite.com/short/index.php?l=ex , , click button initiate function go(), doesn't take me website https://www.example.com
once again, solves/helps solve issue.
enclose jsvar
inside quotes:
var myjsvar = "<?php echo $my_phpvar; ?>";
and later, use variable (and not sring):
window.location.href = myjsvar;
Comments
Post a Comment