How to put php variable in JS link

Asked

Viewed 59 times

0

Hey, guys, what’s up? I’m having trouble putting PHP variable in link JS, what I need to know this because I’m trying to make a u login system on my site... see the line of code r get a supposed solution. Thanks in advance!!!!!!!!


My problem is that I have this command line in Javascript that is inside the file:

<?
$opts = uniqid(rand(), true);
echo "<script> window.location.assign('http://localhost/web/'" . $opts . '") </script>;
?> 

but this line of code just doesn’t happen... How to proceed?

  • Try "<script> window.location.assign('http://localhost/web/$opts') </script>"; or "<script> window.location.assign(\"http://localhost/web/$opts\") </script>";.

1 answer

0


Try the following block:

<?
$opts = uniqid(rand(), true);
echo "<script> window.location.assign('http://localhost/web/" . $opts . "') </script>";
?> 

You’re not closing the " after the tag <script>

This putting ' the more, see: 'http://localhost/web/'" . $opts . '"

Thus, if the variable’s value is page1 will be printed: 'http://localhost/web/'page1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.