Jump to content

AJAX with PHP on same page


Recommended Posts

I'm new to AJAX, and I'm working with some 3rd party code as a learning tool.

Came across this section but:


    type: "POST",  
    url: "my_code.php",  
    data: "username="+ usr,  
    success: function(msg){  

I would prefer NOT having a my_code.php file, but rather to include the PHP code as part of the single file that already contains all the other scripting.

Can this be achieved? What do I need to put in the URL line to direct it to self-examine?

Pros and cons of proceeding this way?


Thanks folks.

Link to comment
Share on other sites

Whatever code is in my_code.php has to be moved into the current file. Obviously.

What happens after that depends on what the rest of the code looks like. If the file doesn't process POST data for anything else then you can use standard practices for handling form inputs (such as by checking if the REQUEST_METHOD is POST) and you don't have to change the AJAX any further.

Link to comment
Share on other sites

Thanks. Any other basic tutorial links would be helpful too.

While developing my script, I noticed that the username is NOT case sensative.

(There is NO string-to-lowercase in my code, yet it is acting as if it exists)

Did I miss a step in my database or table?

Should username disallow case differences (which would limit the number of potential combinations)?

Passwords come to mind too, of course.

Edited by phppup
Forgot item
Link to comment
Share on other sites

In a database the case sensitivity of a field depends on which collation you apply to that field. If the collation name ends with "ci" it is case insensitive.

The default collation would normally be case-insensitive but changed for fields where you specifically need sensitivity.

I personally would count "fred" and "frEd" as the same username.

You wouldn't be storing passwords as plain text for searching anyway.

Link to comment
Share on other sites

Got it.

(should names be case sensative)

But AJAX is client side, so sanitizing is still highly recommended within PHP for the server side, right?

On a related note, I've seen sanitizing examples that trim or remove HTML characters. Shouldn't an entry with such problems simply be rejected rather than repaired?

Are the PHP sanitizing filters reliable on their own (to replace all the code that was required in the past)?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.