Easiest way to get a chunk of code to run only if a user is a guest? Easiest way to get a chunk of code to run only if a user is a guest?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Easiest way to get a chunk of code to run only if a user is a guest?

Started by elwave, May 22, 2011, 06:56:31 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

elwave

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!

Stramm


elwave

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!! :)

Stramm

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.

elwave

Quote from: 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.

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?

Αndré

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).

Quote from: elwave on May 23, 2011, 09:47:16 AM
anyone within that if statement will be a guest then?
Yes.


Quote from: elwave on May 23, 2011, 09:47:16 AM
Do I need any kind of else statement
No, as you said
Quote from: elwave on May 22, 2011, 06:56:31 PM
I'd like a chunk of code to run only if the person is a guest on my gallery

elwave

Cool thank you! I'll get stuck into this a bit later I think! :)

Solved I guess!

elwave

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!

elwave

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!

Stramm

Quote from: Α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).
As Αndré pointed out, anycontent.php is covered in the docs. That's a good place to start.

elwave

Ah, I actually ended up bunging it in theme.php like this:

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!