Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP, security and features

Featured Replies

While making some basic PHP-code for a site, I've created this small script:

 

 

 

 

 

 

 




//This script has been modified, variables have been changed/removed for security reason.



<?



mysql_connect($host,$username,$password);



@mysql_select_db($database) or die( "Unable to select database");







$query="SELECT * FROM info";



$result=mysql_query($query);







mysql_close();







$article = $_GET["article"];







$content=mysql_result($result,$article,"content");



echo "$content";







?>

 

 

 

 

 

 

 

What it does is use the URL (like if you enter hi.php?article=5 it will find article number 5) to get the right document from the database. However, I'm a bit concerned about security. My knowledge of PHP is a bit lacking, basically I can create a script like this and mod phpbb, but that's about it. Are there any obvious security flaws in this way of using a database?

 

 

 

 

 

 

 

Beyond that, I'd like to tweak it a bit.

 

 

 

 

 

 

 

At the moment, the table it uses looks like this:

 

 

 

 

 

 

 

ID | CONTENT

 

 

 

0 | Blabla

 

 

 

1 | Blabla

 

 

 

2 | Blabla

 

 

 

 

 

 

 

Et cetera. When I use the above script to get an article, the script does not get the article that has the relevant ID number, it gets the article with that position in the table. Now, they are both the same so it doesn't matter, but it's a bit inconvenient for those times when I need to make changes to it. Is there a simple way to make it go by the ID column instead of location in the table?

 

 

 

 

 

 

 

Cheers.

If you make it $article = int($_GET["article"]); instead, it'll make convert the $_GET value into a number... Any text would get the number 0, so if a hacker would try to use a inject here, it wouldn't work... It's the same method used on tip.it, and we havent been (that way) hacked yet ;)

And about the selection thing...

 

 

 

 

 

 

 

//This script has been modified, variables have been changed/removed for security reason.

 

 

 

<?

 

 

 

$article = intval($_GET["article"]);

 

 

 

 

 

 

 

mysql_connect($host,$username,$password);

 

 

 

@mysql_select_db($database) or die( "Unable to select database");

 

 

 

 

 

 

 

$query = "SELECT * FROM info WHERE id = ".$article;

 

 

 

$result = mysql_query($query);

 

 

 

 

 

 

 

while ($myrow = mysql_fetch_array($result)) {

 

 

 

print $myrow['content'];

 

 

 

}

 

 

 

 

 

 

 

mysql_close();

 

 

 

 

 

 

 

?>

Also, make ID a primery key field..
  • Author

Thanks for the help, both scripts work great! :)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.