NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] Disable MySQL In A Script?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 01-03-2007, 10:06 AM THREAD STARTER               #1 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




[RESOLVED] Disable MySQL In A Script?


[RESOLVED]

Hey,
Okay, i need a way in PHP to disable MySQL access for the rest of the script. Users will be allowed to upload their scripts and i would like to execute them for reasons i'm not going to reveal yet
But i need to obviously secure it best i can so is there any way to disable MySQL access, so as to kinda run in sandbox mode?
Last edited by beaver6813; 01-05-2007 at 12:17 PM.
beaver6813 is offline  
Old 01-03-2007, 10:43 AM   #2 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: United Kingdom
Posts: 413
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
 




at the top of all the scripts
PHP Code:
<?php
ini_set
('disable_functions','mysql_query,mysql_connect,etc,etc,etc');
?>
To list all mysql functions.
????: NamePros.com http://www.namepros.com/programming/276405-resolved-disable-mysql-in-a-script.html

I'm not sure if that would work though, just a thought:
http://uk.php.net/features.safe-mode

Lee
__________________
Linux Screenshots
lee101 is offline  
Old 01-03-2007, 10:48 AM   #3 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 363
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
if you have apd installed, http://ca.php.net/manual/en/ref.apd.php , you can use the following method of disabling the functions you wish:

for example:
PHP Code:
override_function('mysql_connect'''"print 'mysql_connect function has been disabled';");
????: NamePros.com http://www.namepros.com/showthread.php?t=276405
override_function('mysql_select_db'''"print 'mysql_select_db function has been disabled';"); 
http://ca.php.net/manual/en/function...e-function.php

etc etc... but besure to disable the mysqli functions as well if they are applicable.

Also if you don't want to lose functionality of the functions for yourself you can use rename_function to rename the functions to a secure name for your use. for example

PHP Code:
rename_function('mysql_connect''hidden_for_you_mysql_connect' ); 
http://ca.php.net/manual/en/function...e-function.php
__________________
Canadian Domain Registrar Ready.ca
baxter is offline  
Old 01-03-2007, 11:43 AM THREAD STARTER               #4 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Brilliant Ill give rep in a sec
Okay another incredibly annoying feature i can't get to work is that when i use my error handler in PHP it works fine with registering the first error, but doesn't pickup the others and it doesn't pickup parse errors, PHP overrides my error handler for parse errors.

Any ideas?
beaver6813 is offline  
Old 01-03-2007, 12:14 PM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Not sure why it would only do the first error however.

An error handler cannot deal with parse errors as they are found before the script is executed and is outside the scope of the script. The following is taken from THIS manual page:-

Quote:
The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
Peter is offline  
Old 01-03-2007, 12:16 PM THREAD STARTER               #6 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Okies, so there is definately no way around that? So it returns all parse errors instead of just the first one found?

All i'm doing at the moment is picking up errors and setting error_log to write all errors to a text file which i can read at a later date. However even when i put in 3 errors like unclosed brackets and unterminated lines etc it still shows only one of the errors...
beaver6813 is offline  
Old 01-03-2007, 12:18 PM   #7 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
sorry edited my post must have been just after you replied.

As far as I am aware there is nothing you can do about reporting parse errors. I believe it is the zend engine that actually deals with the following errors:-

E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_STRICT
????: NamePros.com http://www.namepros.com/showthread.php?t=276405

Hence why a custom error handler cannot deal with them.

Originally Posted by beaver6813
All i'm doing at the moment is picking up errors and setting error_log to write all errors to a text file which i can read at a later date. However even when i put in 3 errors like unclosed brackets and unterminated lines etc it still shows only one of the errors...
Unfortunately only the first will display as the script terminates when the first error is found.
Peter is offline  
Old 01-05-2007, 12:17 PM THREAD STARTER               #8 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Thanks Resolved!
beaver6813 is offline  
Old 01-05-2007, 03:24 PM   #9 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
how did you sort the problem?
Peter is offline  
Old 01-06-2007, 01:58 AM THREAD STARTER               #10 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Originally Posted by filth@flexiwebhost
how did you sort the problem?
Using Ajax and PHP i wrote a script that requests the problem file, returns the error PHP gives if its a Parse/Fatal error and then goes to process. It then returns the line number of the problem script highlighted and if its something easy like an unterminated line it puts in the semi-colon. If its something harder to fix like brackets, it'll just return that error.
????: NamePros.com http://www.namepros.com/showthread.php?t=276405

I've also taken a peek at a debugger written in C++ that actually taps straight into PHP's Zend engine, but i doubt i'd be able to do that in PHP
beaver6813 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:07 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger