I tested your script locally and it works just fine. $_POST is probably not receiving what you expect.
Hmm… I added the line echo $u . " " . $p . " " right after $p = $_POST['p'], and it’s echoing back the correct username and password. I could show you my C# code if you like, dunno if you know C# or not but maybe you’ll see something. The data I’m POSTing looks like "u=username&p=password".
I suppose it could be worth noting that the ContentType is "application/x-www-form-urlencoded", but I suppose that’s evident from the type of data I’m POSTing.
Sure, post it to paste bin, I’m guessing .net?
Other than that, you’ve probably done this already but, have you tried sending the user directly to the function?
get_user_by('login', 'username')
Yeah, .NET. I was using one method, and then I found a quicker way, but neither work. I’ll post both. I just tried passing ‘test’ directly, but it did the same thing. I’m really at a loss here.
Here’s the C# code, but I don’t know if it’ll help. I found a test .NET POST and GETter, but it did the same thing. http://pastebin.com/SprV69UP
Ok, the C# code looked perfectly fine. I tested it anyway and it works as it should both in my local wordpress installation and a remote one.
As you can see, the code I used is almost identical to yours so the problem is definitely somewhere else.
Are you 100% sure that user login exists in the database?
I am 100% sure the user exists. I just checked, and there is a user named “test” (what I’ve been using) with the username “test” and the nickname “test” on my users panel in the backend. I’ve tried it with a couple admin accounts, too, and the same thing happens. I have to wonder if, for some reason, the database is empty because I’m running the file outside WordPress…? At this point, it has to be something like the database is empty for whatever reason.
That shouldn’t be it, since I’ve been trying your code outside wordpress -even contacting a remote host- and it works fine, but just to be sure, you can paste the function inside functions.php of your theme and trying it there.
Other than that, have you tried getting the user by id or email?
I did try by email. So, then, the issue is likely with something in my site’s configuration?
Maybe? At this point, it’s probably something incredibly silly we’re not noticing. Have you tried saving the query wp generates and pasting that directly into phpmyadmin?
This is the only query that looks relevant…
[12] => Array
(
[0] => SELECT * FROM wp_users WHERE user_login = 'admin'
[1] => 0.000102996826172
[2] => require, require_once, require_once, require_once, WP->init, wp_get_current_user, get_currentuserinfo, wp_validate_auth_cookie, get_user_by, WP_User->get_data_by
)
I’m trying to install phpMyAdmin right now, but I don’t know how well it’s going to work (or even what I’m looking for).
Looks perfectly normal. Yeah, you don’t even need phpmyadmin, just run the query directly to see if you get any results, you can probably use ssh for a remote host or terminal/console for local.
Pretty sure I did this already but it didn’t work… I’ll try it again, though. Nope, not working. I replaced the get_user_by line with this:
$user = $wpdb->get_var("SELECT * FROM $wpdb->wp_users WHERE user_login = 'test'",0,0); and it’s still not working.
And before you say I didn’t use a semicolon, I tried it with and without.