简体   繁体   中英

How to pass via url a PHP variable to be inserted in a JS script url

I need to pass a couple of PHP variables via url. These variables need to be inserted in a JS script which loads a script.

I have this code on the HTML (.php) page which loads the script:

<script type="text/javascript" src="https://www.example.com/index.php?controller=GzFront&action=load&cid=1&layout=calendar&show_header=F&eid=6262&group=1&local=4"></script>

I need to pass the variables "eid" (number) and "group" (number) via URL from another page.

How can I do this? Should I use a url like www.domain.com/scriptpage.php?eid=6262&group=1 ? And then, how can I put these 2 variables in the script url?

I'd like to use one script/one page to show different contents depending on the variables passed via URL from a HTML (.php) page.

Solved this way:

add the variable to the url using?:

pagename.php/?var1=par1&var2=par2

in the script url add:

<?php echo $_GET['var1']; ?>
<?php echo $_GET['var2']; ?>

where you need the variable.

https://www.example.com/index.php?eid=<?php echo $_GET["eid"]

that's it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM