forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: elwave on May 22, 2011, 06:56:31 pm

Title: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 22, 2011, 06:56:31 pm
Basically yeah erm, I'd like a chunk of code to run only if the person is a guest on my gallery. I have a vaaague idea how something like this might come together but.. pretty vague. It would be awesome to have some help!

Thanks guys, and keep up the good work :)

Wave!
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: Stramm on May 22, 2011, 09:00:36 pm
Code: [Select]
if (!USER_ID) {
    //your code
}
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 23, 2011, 03:17:14 am
Erm.. how would I specify the status of that user? Or does that pertain to any user who currently has an ID (IE, is logged in?)

Sorry, all a bit new!! :)
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: Stramm on May 23, 2011, 07:17:57 am
This specifies the status of the user. If he is not logged in, has no ID, then run the following code.

You haven't told us, where you want to have that or what you want to achieve, so I can't give you more information.
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 23, 2011, 09:47:16 am
This specifies the status of the user. If he is not logged in, has no ID, then run the following code.

You haven't told us, where you want to have that or what you want to achieve, so I can't give you more information.

Sorry hehe, I mean.. the code will just display on the main page, I guess in template.html in my theme? The gallery is bridged with my forum, but I guessed that made no difference?

So.. anyone within that if statement will be a guest then? :) Do I need any kind of else statement, or is it ok?
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: Αndré on May 23, 2011, 10:36:10 am
If you want to use it on your main page, use anycontent.php (please read the docs if you have no clue how that file is supposed to work).

anyone within that if statement will be a guest then?
Yes.


Do I need any kind of else statement
No, as you said
I'd like a chunk of code to run only if the person is a guest on my gallery
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 23, 2011, 03:20:25 pm
Cool thank you! I'll get stuck into this a bit later I think! :)

Solved I guess!
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 26, 2011, 09:43:56 am
hm, I tried this code (I actually stuck it like this into the template.html of my theme as I want it to run on ever page):

<?php
if (!USER_ID) {
    <!-- Begin: Code  -->
<script type="text/javascript" src="http://srcgoeshere.com/src"></script>
<!-- End: Code -->
}
?>


But when I just went on my gallery logged in as my own user (admin and member) it still ran the code (I know because it displays something on the screen when it runs). Any idea why? My gallery is bridged with MyBB as I mentioned, I dunno if that makes a difference!

And oh I just realized, am I being dumb and it has to in fact read something akin to "if {!USER_ID=guest}" or similar?

Sorry, I'm not great with code I just sit here trying to get it working xD

Wave!
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 26, 2011, 10:11:43 am
Oh I see the problem! Of course, this is an html file haha :)

So it's just flat-out ignoring the php lol

hm... I'll have a play around!
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: Stramm on May 26, 2011, 10:42:28 am
If you want to use it on your main page, use anycontent.php (please read the docs if you have no clue how that file is supposed to work).
As Αndré pointed out, anycontent.php is covered in the docs. That's a good place to start.
Title: Re: Easiest way to get a chunk of code to run only if a user is a guest?
Post by: elwave on May 26, 2011, 11:29:17 am
Ah, I actually ended up bunging it in theme.php like this:

Code: [Select]
if (!USER_ID) {
echo "<!-- Begin: Code  -->
<script type='text/javascript' src='http://srchere.com/src'></script>
<!-- End: Code -->";
}

just because I wanted a simple way to get it to show on every page like my template.html stuff does.

I would have used anycontent if it was just the main page I wanted though, but ofc I just wanted to get it working nice and fast! It seems ok atm which is mega awesome! ^_^

Thank you very much both of you!