Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Easiest way to get a chunk of code to run only if a user is a guest?  (Read 4523 times)

0 Members and 1 Guest are viewing this topic.

elwave

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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!
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt

Code: [Select]
if (!USER_ID) {
    //your code
}

elwave

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt

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

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

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
Logged

elwave

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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

Solved I guess!
Logged

elwave

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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!
Logged

elwave

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120

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!
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt

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

  • Coppermine frequent poster
  • ***
  • Country: gb
  • Offline Offline
  • Gender: Male
  • Posts: 120
Re: Easiest way to get a chunk of code to run only if a user is a guest?
« Reply #10 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!
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 20 queries.