Jump to content

[SOLVED] Cleaning a string before inserting it into a php file


neoform

Recommended Posts

other than:

< ? > ' " $

 

what else should i escape from a string if i'm to write it into a php file?

 

i'm writing the following line to my vars.php file

 

$file_contents .= "define('".$var_name."', base64_decode('".base64_encode($value)."'));\n";

 

I wanna get away from using base64 since it's completely unreadable, but I don't want to create an exploit either.. ($var_name is already clean, only [A-Za-z\_] accepted).

Enclose your string in single quotes, then you only need to escape single quotes and backslashes.  Nothing else.

 

You might want to consider heredoc syntax as well, which doesn't require escaping.

 

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.