Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Need some help with an array (i think)

Aloittaja Gunfreak010, joulukuu 28, 2007, 03:31:02 AP

« edellinen - seuraava »

Gunfreak010

Im not sure if its an array, as im a php noob >.<.

Anyways heres a code I have currently
global $user_info;

if ($user_info['is_guest'])
echo ' ';

elseif (in_array(1, $user_info['groups']))
echo '<center><br>You are an Admin';


else
echo '<center><br>You are logged in</center>';



Look at the bolded part... how would I make it display my name or whomever is logged into admin

Like...
You are an Admin Gunfreak or if it was Example it would say

You are an Admin Example


Also, is it possible to get the session id from this sort of thing?

If so, would it be possible to implement it into a link and how?

Like

<a href=http://www.hi.com/$sessid [nofollow]>

I know, its way off, but is there a php linking ability that could possibly allow this?

Thanks for the help, also, if they have one, where can I find a list of arrays for smf as well as a description of how to use them. Thanks!

SA™

#1
are you trying to put a login box on another page other than smf

if so try this

<h3>User Information</h3><p class="gensmall">';


// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';

// Only tell them about their messages if they can read their messages!
if ($context['allow_pm'])
echo ', ', $txt[152], ' <a href="', $scripturl, '?action=pm">', $context['user']['messages'], ' ', $context['user']['messages'] != 1 ? $txt[153] : $txt[471], '</a>', $txt['newmessages4'], ' ', $context['user']['unread_messages'], ' ', $context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1'];
echo '.<br />';

// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '
<b>', $txt[616], '</b><br />';

// Are there any members waiting for approval?
if (!empty($context['unapproved_members']))
echo '
', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '<br />';

echo '
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a><br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />
', $context['current_time'];
}
// Otherwise they're a guest - so politely ask them to register or login.
else
{
echo '
', $txt['welcome_guest'], '<br />
', $context['current_time'], '<br />

<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>

<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" style="margin: 3px 1ex 1px 0;"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<div style="text-align: right;">
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
<select name="cookielength">
<option value="60">', $txt['smf53'], '</option>
<option value="1440">', $txt['smf47'], '</option>
<option value="10080">', $txt['smf48'], '</option>
<option value="43200">', $txt['smf49'], '</option>
<option value="-1" selected="selected">', $txt['smf50'], '</option>
</select>
<input type="submit" value="', $txt[34], '" /><br />
', $txt['smf52'], '
<input type="hidden" name="hash_passwrd" value="" />
</div>
</form>';

}
echo '</p><p class="gensmall">';


see it working here
http://waynesworld.kicks-ass.net/index.php
look for User Information on the right
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
LainaaMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Gunfreak010

No, I just have TP with it and use that. What im trying to do is make it so that I can have an admin only link that links to one of the functions that requires a session id... but how would I make it display a persons user name with one of the arrays as well as what I mentioned above?

Kays

To see what the array contains use this:

echo '<pre>', print_r($user_info), '</pre>';

What you can use to check if the user is an admin is $user_info['is_admin']. And the member's name is $user_info['name']

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Gunfreak010

#4
Nice, that was what I was looking for krays! I tampered with it a bit, and realized I could take off the pre tags, but there is one thing that bothers me a little...

Rather than saying
Welcome Gunfreak, it says Welcome Gunfreak1

That 1 there is a little bothersome for me... how can I take it off?

Edit:
While the 1 still remains on the $user_info, I realized that I could use the $context array by looking at the admins template, and thankfully, I got it to work without the 1, however the information on taking off the 1 would still be helpful nonetheless

Another thing I realized with the admins template, was that I can use
', $context[sessionid],' to display the current session id. These will both help me to produce my block in tinyportal

Either way, Id like to thank the above poster for the valuable information

Kays

The <pre> tags are just there to format the display of the array.

That "1" could be caused by a number of things. Could you post the code around where that is?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Gunfreak010

All I use around the 1 is the following

global $user_info;

echo '', print_r($user_info[name]), '';


Also, this is using Tiny Portal if that means anything...

Kays

The print_r was just a way to show you all the elements in that array. Here just use echo. You don't need to enclose it in quotes since it's a variable.

echo $user_info['name'];

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Gunfreak010

Ok, I thought I was good, but my block only applies to group one with the following code

if (in array(1, $user_info['groups']));

It only applies to the Admin in group one. I understand I can change it like so

if (in array(1,2,3,etc., $user_info['groups']));

However that would require changing whenever an admin group is added... I tried this

if (in array(1, $user_info['is_admin']));

but sadly it did not work as I had expected it to, as I thought it was similar to the groups one :(. Is there any trick to doing this?

Also, im starting to understand the coding with PHP now, so im writing all of the above from memory, which ill be honest about, I couldnt do just a few days ago, so thats helping me a bit, as well as the knowledge of how these run predefined scripts and actions, so that may help me in the future...

Kays

Well, here's a few small problems.  :)

For a start, don't place a semi-colon after an if statement. And then you've got the prarmeters for that function backwards. Plus $user_info['groups'] is an array.

$user_info['groups'][0] are the assigned member groups
$user_info['groups'][1] is the post based member group.


if (in array($user_info['groups'][0], array(1,2)))

I think that will only work when the member has one assigned group. To do it properly you should loop through each of the assigned groups

BTW, user group 3 are the board moderators.  It's not an actual group to which members are assigned. So there no need to check for for that group.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Advertisement: