Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Gobo on June 14, 2006, 03:46:13 AM

Title: Using a condition check in a link -- how?
Post by: Gobo on June 14, 2006, 03:46:13 AM
hi

I want to create a hyperlink which basically does the following:

When someone clicks on it, it checks:

- Is this person a guest or member?
>>>>If guest it takes them to Page X
>>>>If member it checks if they belong to the proper membergroup of not?
>>>>>>>If they do go to page Z
>>>>>>>If not go to page X

Is this possible with PHP?

And if yes can someone kindly code it for me? Thanks
Title: Re: Using a condition check in a link -- how?
Post by: jacortina on June 14, 2006, 10:17:09 AM
In the php which 'echo's out the link, you can use conditions so that different links are generated for different users.

It would be something like this, I believe:


    global $user_info;

    if ($user_info['is_guest']) echo '<a href="...Guest link target here...">Link Text</a>';
    elseif (in_array(#, $user_info['groups'])) echo '<a href="...Group# link target here...">Link Text</a>';
    else echo '<a href="...Default link target here...">Link Text</a>';


Replace the '#' in the 'in_array(#, $user_info['groups'])' with the number of the membergroup you want to supply with the particular link (you could actually have mulitple 'elseif' lines before the 'else' for default).

And put all the correct links in the 'a href="', of course.

Using the same Link Text, the link would appear the same to all, but clicking would take user to the appropriate place.
Title: Re: Using a condition check in a link -- how?
Post by: Gobo on June 14, 2006, 01:54:29 PM
wow thanks :D

I'm gona try it out very soon :D

Thank you very very much :D
Title: Re: Using a condition check in a link -- how?
Post by: JayBachatero on June 14, 2006, 06:25:38 PM
Take a look at this post also.  It's basically what you want.
http://www.simplemachines.org/community/index.php?topic=89070.msg609060#msg609060
Title: Re: Using a condition check in a link -- how?
Post by: Gobo on June 14, 2006, 07:33:31 PM
thanks jay :D

Nice to see you again :D hope you are in the best of health :D
Title: Re: Using a condition check in a link -- how?
Post by: JayBachatero on June 14, 2006, 08:15:07 PM
Thanks.  I am finally back to SMF :).