+ Reply to Thread
Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By misson

Thread: function works on local not on remote

  1. #1
    arp1445's Avatar
    arp1445 is offline x10Hosting Member arp1445 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    14

    Question function works on local not on remote

    hi... I'm using x10's free hosting service...
    I wrote a function as below:
    PHP Code:
    function prevent_url_injection($unsafe) {
            
    // preventing from sql injection by url get method
            
    $find_eveil_chars = array("'""\"""#""//""/*""*/""--");
            
    $safe str_replace($find_eveil_chars""$unsafe);
            return 
    $safe;

    I wrote this function for prevent url injection.
    This works fine on my local server... But not working on remote server...
    The strange thing is: 1)I created a new php file (for test only) and it works fine on remote server. 2) When I try with my existing files - include it, or wrote function as standalone - it did not worked

    Can anyone tell me how to fix and whats going on?
    Thanks in advance.
    Last edited by arp1445; 01-09-2012 at 02:27 AM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: function works on local not on remote

    Define "does not work".
    Nothing is always absolutely so.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: function works on local not on remote

    Never write your own SQL escape function. It's too easy to get something wrong and completely unnecessary. The database extensions provide their own functions to prevent SQL injection. In any case, you shouldn't be escaping data, you should be using prepared statements; prepared statement parameters aren't vulnerable to injection.

    For an example of how your function gets something wrong, how does it handle the entirely valid name of "O'Neill"?
    Last edited by misson; 01-08-2012 at 02:31 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    arp1445's Avatar
    arp1445 is offline x10Hosting Member arp1445 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    14

    Re: function works on local not on remote

    Quote Originally Posted by misson View Post
    Never write your own SQL escape function. It's too easy to get something wrong and completely unnecessary. The database extensions provide their own functions to prevent SQL injection. In any case, you shouldn't be escaping data, you should be using prepared statements; prepared statement parameters aren't vulnerable to injection.

    For an example of how your function gets something wrong, how does it handle the entirely valid name of "O'Neill"?
    Hmm.. thats interesting... I'll use prepared statements.
    But my function was only to get numeric id from GET method... so it wont even show any errors in spite of bad/evil chars from url...

    ---------- Post added at 08:28 AM ---------- Previous post was at 08:25 AM ----------

    Quote Originally Posted by descalzo View Post
    Define "does not work".
    Sorry for my bad English :p *edited*

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: function works on local not on remote

    When descalzo wrote that he wanted you to define "does not work", it's not because your statement was grammatically incorrect, it's because "does not work" is ambiguous. We can't know how it's not doing what you want. Are you getting an error? Is the function not returning the value you expect for some input? "Does not work" tells us nothing about what's going on. Always state explicitly what you want (or expect) and what you actually get, which includes any error messages.
    arp1445 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  6. #6
    arp1445's Avatar
    arp1445 is offline x10Hosting Member arp1445 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    14

    Re: function works on local not on remote

    ok, sorry - thanks for explanation, I got it!

    No error, its like a ghost bug.
    function is ok, it passes values correctly - returns values also correctly.
    But it should return the cleaned-up value -- its not cleaning up.

    Thats where the problem is.
    I'm saying is, this function is working fine when I create new php file, for test purpose but not on production mode.
    Its very strange.

    Thanks.

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: function works on local not on remote

    How are you passing/getting the strings? Be specific.

    Examples? Does it ever work properly?
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 10-14-2010, 01:50 PM
  2. Local host name
    By gar38 in forum Free Hosting
    Replies: 4
    Last Post: 03-06-2008, 12:54 AM
  3. Replies: 1
    Last Post: 02-26-2008, 04:50 PM
  4. Local host to remote host
    By dchamai in forum Free Hosting
    Replies: 5
    Last Post: 02-21-2008, 09:57 AM
  5. Replies: 2
    Last Post: 01-25-2008, 09:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers