1

I have a PHP page with the following URL:

http://xyz.com/dev/gallery.php?k=1&s=35

The following Javascript file is included on the PHP page:

<script type="text/javascript" src="js/some-js-file.php"></script>

The some-js-file.php needs to be filled dynamically using PHP:

jQuery(function($){$.supersized({

<?php 
$sql = "SELECT * FROM tbl WHERE id=".$_GET['s']." ORDER BY pos ASC"; 
$result = mysql_query($sql); 
    while($rs = mysql_fetch_row($result)){
    ...do some output here...
    }
?>

});
});

For some reason, $_GET['s'] is empty. Any ideas why? Thanks in advance for any help!

1

1 Answer 1

1

Pass the parameter to the JavaScript file as well:

<script src="js/some-js-file.php?s=<?php print $_GET['s']; ?>"></script>

N.B.: Please pay attention to Quentin's comments and make sure that you use the approach securely.

Sign up to request clarification or add additional context in comments.

1 Comment

Danger: This is vulnerable to XSS attacks. Never insert external data into HTML without sanitising it! Add htmlspecialchars to fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.