PDA

View Full Version : How to fetch a userid


Sprite-
10-05-2009, 10:38 PM
I am writing a script that uses vbulletin for usernames and userids.

Currently, I know I can use

$info = fetch_userinfo($userid);
$username=$info["username"];
echo $username;

to display a username for a userid.

My problem is going the other way around. Does anyone know how to display a userid for a username?

Any help would be appreciated. Thanks!

Edit: Also I am aware that I can do this with an sql query. I don't want to have to do that.

Lynne
10-05-2009, 11:56 PM
Look up fetch_userid_from_username in the API

Bandit8007
10-11-2009, 10:52 AM
hello people can somebody help out on a lillte issue i have?

im using a own build php script that does read a txt file and tranfers it intoo a sorted php file
but it was build for a blog....

to tell what it does in short is....

ya can manually add releases to page... sofar it works fine but i can't get the userinfo on it

global $user_identity;
get_currentuserinfo();


$todaydate = date("m/d/Y");

$riplist .= '{[1] = [[music]],[2] = [['.$user_identity.']],[3] = [['.$todaydate.']],[4] = [['.$artist.' ('.$year.') '.$album.']],},'."\r\n";

}

// append closing bracket to riplist.
$riplist = $riplist."}";

// we have our riplist, now write to file.
if ($handle = fopen ($rel_file3, "ab")) {
// find the file size in bytes and remove one ie trailing bracket on last line
$truncate = filesize("$rel_file3") - 1;
// remove trailing bracket.
ftruncate ($handle, $truncate);
// write our new rips plus closing bracket }
if (fwrite($handle, $riplist)) {
print "<p>Thanks! Your rips were successfully added to the database.</p>";
} else {
print "<p>Something went wrong with the writing to DB file process. Please report to admin.</p>";
}
fclose($handle);
} else {
print "<p>Couldn't open the file for writing!</p>";
}

} else

print "<p>You didn't not add owt.</p>";

}

sofar that works fine
but i have trouble to add the user that posted it

global $user_identity;
get_currentuserinfo();


$todaydate = date("m/d/Y");

$riplist .= '{[1] = [[music]],[2] = [['.$user_identity.']],[3] = [['.$todaydate.']],[4] = [['.$artist.' ('.$year.') '.$album.']],},'."\r\n";

}

the last coded part us the issue

cause im getting the error:

Fatal error: Call to undefined function fetch_userinfo() in /var/www/Forum/database/releases.php on line 324

line 324 is empty

322> global $user_identity;
323> get_currentuserinfo();
324> empty

any idea how to fix?
thnx :)

Lynne
10-11-2009, 03:58 PM
This error:
Call to undefined function fetch_userinfo() in /var/www/Forum/database/releases.php on line 324

.... it can't find the function. Did you include the file that defines the function fetch_userinfo in your code?

Bandit8007
10-11-2009, 05:53 PM
im sorry i mixed up the first soultion... that was posted in here

the fatal error that takes place is
Fatal error: Call to undefined function get_currentuserinfo() in /var/www/Forum/database/releases.php on line 323

and this is what script does use now ( but thats wordpress code)
322> global $user_identity;
323> get_currentuserinfo();
324> empty

so it wont work with vbulletin

so im trying to get a work around to get the userinfo....

Lynne
10-11-2009, 06:40 PM
Weel again, it's an unidentified function which means you are calling it, but the file that contains the function is not being included. What file do you identify the function get_currentuserinfo in?

Bandit8007
10-12-2009, 02:23 PM
well im not sure i understand fully...

but it does concern the current user thats on that(Vbulletin) page to post a release

to explain in short...

ive created a empty page as did get posted in here in mods
and used $include php for it

a part of that script is posted on post nr 9 above
anything does work fine on a wordpress instalation

but not on VB...

cause the member thats online on VB and that wants to post a release will not be added due that error it does gave...

so i need to change that script so it gets the user thats on VB and that does post that release....

maybe this helps you... ( i hope)..
if not then ill gave the full script ect what belongs to it... send me then a pm pls

gracias Lynne :)

Lynne
10-12-2009, 02:46 PM
The problem is it wants to use the function get_currentuserinfo() but it is unable to since you haven't included the function in the script. Find the function in your files and either copy it into your page or include the page in your script:
require_once(DIR . '/thatPage.php');

Bandit8007
10-13-2009, 05:26 AM
Lynne i think ya total misunderstand me a bit or i fail to explain it correctly...
but im gonnay try to explaim a bit easyer

in root >> new made empty page called releases.php if has indeed included the php that needs to be show >> <tbody>
<tr>


<td colspan="2"><p><?php include('database/releases.php'); ?></p>

</tr>
</tbody>
</table>

that /database/releases.php <<<

does look for that userinfo

ill post that part ofl script

from line 322 until 354

and the error i do get comes from that line 324
(again this worked in wordpress but not in vbulletin)
global $user_identity;
get_currentuserinfo();


$todaydate = date("m/d/Y");

$riplist .= '{[1] = [[music]],[2] = [['.$user_identity.']],[3] = [['.$todaydate.']],[4] = [['.$artist.' ('.$year.') '.$album.']],},'."\r\n";

}

// append closing bracket to riplist.
$riplist = $riplist."}";

// we have our riplist, now write to file.
if ($handle = fopen ($rel_file3, "ab")) {
// find the file size in bytes and remove one ie trailing bracket on last line
$truncate = filesize("$rel_file3") - 1;
// remove trailing bracket.
ftruncate ($handle, $truncate);
// write our new rips plus closing bracket }
if (fwrite($handle, $riplist)) {
print "<p>Thanks! Your rips were successfully added to the database.</p>";
} else {
print "<p>Something went wrong with the writing to DB file process. Please report to admin.</p>";
}
fclose($handle);
} else {
print "<p>Couldn't open the file for writing!</p>";
}

} else

print "<p>You didn't not add owt.</p>";

}

Lynne
10-13-2009, 02:33 PM
OK, let's start with this.... what file is the function get_currentuserinfo in? Is it in the releases.php file? Is that file readable to the public? Try copying the function out of the file and putting it into your page - does it work now?

Bandit8007
10-13-2009, 04:05 PM
that function get userinfo is in /database/releases.php
when i take that out of it....
anything works....
except i do get a empty field on who has posted it....
the fileds that are getting posted are those >>>

$riplist .= '{[1] = [[music]],[2] = [['.$user_identity.']],[3] = [['.$todaydate.']],[4] = [['.$artist.' ('.$year.') '.$album.']],},'."\r\n";

Lynne
10-13-2009, 04:28 PM
It sounds like something wrong with the function then if you aren't getting any output from it.

Bandit8007
10-13-2009, 05:56 PM
yes Lynne.... and its the function get userinfo....

cause the current function is used by wordpress

so i need to change it to apply to VB

thats why i posted it....
cause VB can't read the function now....

Lynne
10-13-2009, 06:30 PM
So, you rewrote the vbulletin fetch_userinfo function and called it get_currentuserinfo? Do you include global.php anywhere in your script?

Bandit8007
10-14-2009, 01:47 PM
no no no...

the current info is the default that comes with the script... thus >>get_currentuserinfo <<
i did try to use ftech_userinfo but that aint working eighter....

thers total no include global.php anywhere in this script....

thnx for helping lynne .. ill respect that!

Lynne
10-14-2009, 03:12 PM
OK, so you have a function get_currentuserinfo that came with your script, however, it doesn't seem to be getting the current userinfo - correct? So, it seems that that function is missing something that it needs to work.

In vBulletin, if you want to do anything with the user information (userid, username, etc), then you need to include global.php somewhere in your script (or init.php) because it has the necessary functions to get that information. Is there some file with your script that you need to include and are not? You'll have to take a look at other pages used with that script to figure that out.

Bandit8007
10-14-2009, 03:31 PM
yes i do have have in /database/releases
the releases.php and it there is a include funtion.php
to get releases.php working
so i think i need include aswell the global.php in releases.php

Thats what ya meant lynne?

i will try that...

or do i need something else?

Lynne
10-14-2009, 03:43 PM
I really don't know what you need since you are talking about using a bunch of non-vb scripts that I am not familiar with.

Bandit8007
10-14-2009, 03:54 PM
well it does something now though! so thats good! and you doing good aswell!

ive replaced >>get_currentuserinfo

with

$info = fetch_userinfo($userid);
$username=$info["username"];
echo $username;

and also included global.php

this works!

but... the return to the user section is a zero 0

so it does something!

ill guess the zero is the usrid admin im right?

ifso then it looks we almost there.....

but im looking not for the id but username :)

Lynne
10-14-2009, 03:59 PM
0 means your are showing up as unregistered (usually 1 is the admin). You need to include global.php at the beginning of the script and it needs to be able to see that you are on the site. Is your vbulletin cookie set up for the whole site or just the /forums part? And, are you logged in to the site?

Bandit8007
10-15-2009, 04:19 PM
well after reading up many threads etc...

i did rebuild it as it should
step 1 >> custom pages
step 2 >> hook made include php

and after reading this post! >> cause its the same issue i have (lucky me )
http://www.vbulletin.com/forum/showthread.php?t=168316

this solution >>>

When I tried to access it via $vbulletin->userinfo['userid']; it worked

so all probs is solved but i get now indeed userid 1

ive changed it intoo >>> $vbulletin->userinfo['username']; <<< and that was the trick!

thnx for ur help Lynne....!

this topic is solved :)

Lynne
10-15-2009, 04:42 PM
Glad you got it working!