Jump to content

Security Issues


steviemac

Recommended Posts

Hello,  I am using <?=$PHP_SELF?> in a search form so it will stay on the same page.  I have been advised that there are security risk to using that and that is is susceptible  to sql injections and my database can be at risk.  I have read about using the following code instead:

htmlentities($_SERVER['PHP_SELF'])

Is that more secure or are there other code that is more secure?

 

Also could someone look at my database connection and see if there are any issues with it?

 

<?php

$db_host = "localhost";
$db_user = "user";
$db_pass = "password";
$db_name = "database";

function db_connect() {
    global $db_host;
    global $db_user;
    global $db_pass;
    global $db_name;
    $connection = mysql_connect($db_host,$db_user,$db_pass);
    if (!(mysql_select_db($db_name,$connection))) {
        echo "Could not connect to the database";
    }
    return $connection;
}

// Connect to the database
db_connect();
?>

 

Thank you for any help you can provide.

Link to comment
Share on other sites

OK I can turn off register_globals  but I am not ser how to use this code. <?PHP echo basename($_SERVER['SCRIPT_FILENAME']);?>

 

I am using the ($_SERVER['PHP_SELF']) in a search form  <form action="

<?=$PHP_SELF?>" method="post" name="search" id="search" >

that is used to search a database.

 

Thanks for any further help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.