Check if user is on showthread.php
Hugop Offline
Junior Member
**
Posts: 4
Joined: Dec 2015
Post: #1
Check if user is on showthread.php
Hi,

I am making a plug-in and I would like to know how to check if the user is reading a thread.

PHP Code:
if(user_reading_thread == "true")

Something like that.

(This post was last modified: 12-11-2015 08:31 AM by Hugop.)
12-11-2015 08:31 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: Check if user is on showthread.php
The easiest way is by checking the user location, something like:

PHP Code:
if(THIS_SCRIPT == 'showthread.php')


12-12-2015 12:47 AM
Find all posts by this user Quote this message in a reply
Hugop Offline
Junior Member
**
Posts: 4
Joined: Dec 2015
Post: #3
RE: Check if user is on showthread.php
This is what I have been using but it won't work.

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function redirectthiss()
{
	
	global $mybb;

	if($_SERVER['SCRIPT_NAME'] == "showthread.php")
	{ 
		
		
			redirect(
				htmlentities("index.php"),
				htmlentities("1"),
				htmlentities("2")
			);

		
	}
	
}


I tryed with "*" and != too but it refuses to redirect.

12-15-2015 01:54 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Check if user is on showthread.php
I don't know where you want to put your code.
If you do it in your plugin, just hook to showthread_start. Something like this:

PHP Code:
$plugins->add_hook('showthread_start','myred');
function myred(){
	redirect('index.php','You are redirected to index','Redirecting');
}


(This post was last modified: 12-15-2015 02:06 AM by RateU.)
12-15-2015 02:04 AM
Find all posts by this user Quote this message in a reply
Hugop Offline
Junior Member
**
Posts: 4
Joined: Dec 2015
Post: #5
RE: Check if user is on showthread.php
(12-15-2015 02:04 AM)RateU Wrote:  I don't know where you want to put your code.
If you do it in your plugin, just hook to showthread_start. Something like this:

PHP Code:
$plugins->add_hook('showthread_start','myred');
function myred(){
	redirect('index.php','You are redirected to index','Redirecting');
}

I see, the hook was the problem all the time Cry
Is there somewhere a list with all hooks?
12-15-2015 07:50 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: Check if user is on showthread.php
I think you can find it in MyBB Docs.
But personally, I prefer to find it inside the script directly, so I know whatever variables exists, which hooks I can use for my purpose and etc.

12-16-2015 12:57 AM
Find all posts by this user Quote this message in a reply
Hugop Offline
Junior Member
**
Posts: 4
Joined: Dec 2015
Post: #7
RE: Check if user is on showthread.php
I see, thank you!
12-16-2015 01:49 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: