2013-10-15 156 views
1

我有以下网址PHP页面:

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

下面的JavaScript文件包含在PHP页面:

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

的一些-JS -file.php需要使用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... 
    } 
?> 

}); 
}); 

由于某些原因,$ _GET ['s']为空。任何想法为什么?预先感谢任何帮助!

+3

**危险**:您正在使用[an **过时的**数据库API](http://stackoverflow.com/q/12859942/19068)并应使用[现代替换](http:// php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻击](http://bobby-tables.com/)**,现代的API会使[防御]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己从。 – Quentin

回答

1

传递参数的JavaScript文件,以及:

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

N.B:请注意Quentin's comments并确保你使用的方法安全。

+2

**危险**:这易受[XSS](http://en.wikipedia.org/wiki/Cross-site_scripting)攻击。切勿将外部数据插入到HTML中而不加以消毒!添加'htmlspecialchars'来修复它。 – Quentin