|
|
All answers provided by Markus Diersbock
|
Question: |
Only What You Want
To prevent SQL Injection and other security breaches in my PHP scripts, I'm writing a
function to validate user submitted data. What invalid characters
should I parse out?
|
Answer:
|
It is easier to validate against data for what you do want, rather than trying to filter out what you don't. The best way to think about this, is to use the analogy of a night club guest list.
A night club uses a "guest list" to match those who they want to allow entry -- say 200 people. This is far easier to implement than using a "not-a-guest list", because that list would have to account for every person who is not wanted in the club -- which would be impossible to maintain with a population of 6.4 billion. But, this is exactly what many programmers try to do in their code.
They "scrub" the input, using various replacement routines on any invalid characters. The problem is, as in our night club analogy, that you can't foresee new additions that may arise in the future -- new exploits. So the better method is to only allow characters through that you deem valid. These would included letters, numbers, hyphens, periods, apostrophes, etc. And even better, you can accomplish this in one line with a regular expression:
$mystring = preg_replace("/([^'\-_.@A-z0-9\s])/","", $mystring);
This line is a catch-all, but you could build on this code by creating a function that uses a switch statement and multiple regular expressions that validate on specific strings like phone numbers, email addresses, social security numbers, etc.
See my VBScript version of the same example.
|
|
Question: |
Active Security
What is the best way to secure my ActiveX DLLs under IIS when using ASPs?
|
Answer:
|
Take a look at my previous write up from the Downloads Page: Link
|
|
Question: |
Out With the ASP, In with the PHP
My website used to be hosted
on a Windows 2000 server (and had ASP files) and is now on a LINUX server (and has PHP files). The problem is that many search engines
still have links to these
old files.
For example:
Old file: www.mydomain.com/myfile.asp
New file: www.mydomain.com/myfile.php
Obviously when the user hits that old ASP file they get a 404 PAGE NOT FOUND
error.
To not drop in the Page Rankings, I need to keep these files until the various
search engines index my new pages. I've set up some ASP files on my new server and have them redirect to
their PHP equivalents for a few of the important files. But when I do this,
Apache parses the extension and tries to download the file to the user,
rather than displaying it in their browser.
How can I get Apache to ignore the ASP extension or at least get it to
process the file like a PHP or HTM file so it can redirect? Also, if
possible, I'd like to have an email sent to me if a user hits one of those
files so I can keep track of which search engines still have these old
links. How do I do this?
BTW, I have a vhost account, so I don't have access to the server's config
files. |
Answer:
|
You can do this simply by adding a MIME type directive for PHP to a .htaccess file in the root directory of your website.
1) Create the .htaccess file with your favorite text editor and add the
following line:
AddType application/x-httpd-php
.asp
This directive treats ASP files as if they were PHP files.
2) Run chmod 644 .htaccess to allow public read permissions
3) The next step can be done in two ways: A or B.
A: The fastest is to create a symbolic link for the PHP file with an ASP
extension. This side-steps the browser redirection and makes it appear to
the user that they are in fact accessing the requested ASP file.
ln -s myfile.php
myfile.asp
B: But since you wanted an email to be sent to you, you'll need to create the
ASP file and add the PHP code to it. You can use the sample below:
$refer=$_SERVER['HTTP_REFERER'];
$script=$_SERVER['SCRIPT_NAME'];
$ebody="RefURL: $refer\nPage:
$script\n";
mail("you@domain.com",
"* * Redirect Notice * *", $ebody);
header("HTTP/1.1 301 Moved Permanently");
header("Location: ./about.php");
exit();
In this example, an email is sent with the referring page that displayed your
outdated link and the name of the ASP file. The script then redirects to the new PHP file.
Remember to run chmod on myfile.asp and set it to 645.
|
|
Question: |
Problem with XP on
Mini-Notebook
I just installed Windows XP SP2 on my Toshiba
Portege 3110CT. If my Port Replicator is attached, Windows will stop booting
after the splash screen. In the Event Log the error that occurs is "ACPI
BIOS Is Attempting to Write to an Illegal IO Port Address". |
Answer:
|
The BIOS on your notebook is outdated. You'll need to flash your BIOS to the
latest version 7.7 which you can download from
Toshiba (Info
Page) or from our
site if the file becomes unavailable.
|
Notice: You are free to use any
information on this page for personal purposes. Information on this page cannot
be reproduced outside of this website without the affixed copyright notice (at
the bottom of the page) or the written permission of
SwingNote, LLC.
|
|