News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

deny direct access to SMF

Started by Gianni_T, May 07, 2005, 03:49:43 AM

Previous topic - Next topic

Gianni_T

Hi all,
how can I deny direct access to my SMF and allow only to see it wrappend in Mambo?

xenovanis

Enter this at line 1 of smf's index.php:


defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
"Insanity: doing the same thing over and over again and expecting different results."

Gianni_T

Quote from: xenovanis on May 07, 2005, 03:57:04 AM
Enter this at line 1 of smf's index.php:


defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

Does this trick works also for attached files?

xenovanis

Quote from: Gianni_T on May 07, 2005, 04:00:31 AM
Does this trick works also for attached files?

I dont know, just try it out.  :)
"Insanity: doing the same thing over and over again and expecting different results."


chadness

You might try this, if you want to display avatars in your login box:
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
}

Firefrog

Is this literally line one above the file info stuff or just at the start of the actual code.


xenovanis

It's just this peace of code, you'd better use the one Chadness posted in the post above you. You'll need to add  it in your SMF's index.php on line 2 just after <?php

And not on line 1, as I said earlier.
"Insanity: doing the same thing over and over again and expecting different results."

Firefrog


Nitro

i have anothe rquestion, first, i wanted to say this little code has been working great! thank you!
now, instead of showing a message, is there a way to redirect automaticaly the direct access and send them to the actual main index ?

how would i go and do this? thanks a bunch!!!
MPF Rocks!!!

Aravot


Orstio

if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
if(!defined('_VALID_MOS')){ redirectexit('http://www.where-you-want-to-go.com/folder',false); }
}

Nitro

Quote from: Orstio on August 02, 2005, 09:40:59 PM
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
if(!defined('_VALID_MOS')){ redirectexit('http://www.where-you-want-to-go.com/folder',false); }
}


this code gave me en error:


Fatal error: Call to undefined function: redirectexit() in /homepages/20/d107436098/htdocs/bb/bb/index.php on line 4


i just replaced the 'where-you-want-to-go with my url, any suggestions?

thank you.
MPF Rocks!!!

Orstio

Quote from: NitroRich on August 02, 2005, 09:56:21 PM
being charter member i guess it has some advantages.

nice!

i will look forward to become one charter member pretty soon and i am tired of waiting for a random answer.

thank you man!!!

While I'm sure everyone here would appreciate your charter membership, it isn't required to receive a quicker reply.  I think something similar to what I posted above has already been suggested somewhere.

Quotethis code gave me en error:

Code:

Fatal error: Call to undefined function: redirectexit() in /homepages/20/d107436098/htdocs/bb/bb/index.php on line 4
i just replaced the 'where-you-want-to-go with my url, any suggestions?

thank you.

It is best to place that code after Line 51. ;)

Orstio

Hmmm... once Subs.php is called, it should be good.  ???

Nitro

on subs.php you mean, to put that code in the subs.php? is that right? because i have it on the index.php for the SMF board
MPF Rocks!!!

Orstio

Yes, it goes in index.php.  But there is a "require" to Subs.php:

require_once($sourcedir . '/Subs.php');

The function named redirectexit is inside Subs.php, so the code added to index.php must be after that require_once statement.

Phoenixoverlord

Hmmm still no love here...

I've placed this after the require_once line in index.php (around 54 or so)

if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
if(!defined('_VALID_MOS')){ redirectexit('http://url/mambo/index.php',false); }
}


And then get this for an answer:

Notice: Use of undefined constant WIRELESS - assumed 'WIRELESS' in /home/flaming/public_html/smftest/Sources/Subs.php on line 1228

Notice: Use of undefined constant WIRELESS_PROTOCOL - assumed 'WIRELESS_PROTOCOL' in /home/flaming/public_html/smftest/Sources/Subs.php on line 1238

Warning: Cannot modify header information - headers already sent by (output started at /home/flaming/public_html/smftest/Sources/Subs.php:1228) in /home/flaming/public_html/smftest/Sources/Subs.php on line 1257

Orstio

What version of the bridge are you using?  Do you have a URL?

Phoenixoverlord

I'm using v3.19a  and SMF 1.0.5. I'll PM you the link. :) Thanks for the help!

BCCZeus

I'm running 3.19a and 1.1 Beta 3 and am getting pretty much the same issues as Phoenix.

BCCZeus

Any update or ideas on this.  Previously my members would just go to my forum url, but now that it's integrated, I'd really love to deny and redirect.

Thanks in advance.

Orstio

How about something like this:

if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
if(!defined('_VALID_MOS')){ header("Location: http://www.example.com/");}
}

BCCZeus

Sweet work Orstio.  Very slick.

BTW I fixed the DiscussBot so it allows you to edit the post when you click the "Discuss" link for the first time.  PM me if you want the updated bot for your next bridge version.

Orstio

QuoteBTW I fixed the DiscussBot so it allows you to edit the post when you click the "Discuss" link for the first time.  PM me if you want the updated bot for your next bridge version.

That's how the original bot worked, actually (I didn't know there was another way at that time).  I will make it optional in future releases, set by param.

BCCZeus

Hmm.  Maybe something screwed up with the last version I got with the bridge.  It would only quote the article and not allow you to edit it. . . weird.  Either way.  Thanks for the deny and redirect.

Orstio

QuoteHmm.  Maybe something screwed up with the last version I got with the bridge.  It would only quote the article and not allow you to edit it. . . weird.  Either way.

QuoteThat's how the original bot worked, actually (I didn't know there was another way at that time).  I will make it optional in future releases, set by param.

To rephrase:  Older versions of the bot worked as you describe.  Nothing is screwed up.  That is just not the way this version of the bot happens to work.  In future releases of the bot, there will be a param to decide whether you wish the bot to behave as you asked, or the way it does now.  Not in this version;  In future versions.

jrfuda

Guys, thanks for this bit of code. I have the redirect working well!

exrace

#28
Thanks for this snippet.
I hacked it a bit to work better with multi-named sites using Location: /index.php? instead of a full url.

// Redirect users who try to access /forum directly
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: /index.php?option=com_smf&Itemid=yourItemidNum");}
}


Then if you change your url or use multiple names for your site it won't redirect them to a hardcoded name on the redirect.

Naesstrom

Ok... I'm not getting this to work at all... tried every version of code in this thread and nothing happends, not even a errormessage... just redirected to SMF when loggin in...
I have this setup:
joomla: http://portal.myurl.com
SMF: http://forum2.myurl.com

the newest versions of everything, joomla, smf and the bridge... anyone got any suggestions....

Kindred

if you want to use wrapped, you have to have smf and joomla on the same subdomain.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Orstio

Quote from: Naesstrom on December 15, 2005, 04:32:22 PM
Ok... I'm not getting this to work at all... tried every version of code in this thread and nothing happends, not even a errormessage... just redirected to SMF when loggin in...
I have this setup:
joomla: http://portal.myurl.com
SMF: http://forum2.myurl.com

the newest versions of everything, joomla, smf and the bridge... anyone got any suggestions....

Putting this in your SMF index.php does not work?

// Redirect users who try to access /forum directly
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: http://portal.myurl.com//index.php?option=com_smf&Itemid=yourItemidNum");}
}


Make sure to change "yourItemidNum" to your Itemid number of your bridge component.

Naesstrom

Quote from: Kindred on December 15, 2005, 04:43:36 PM
if you want to use wrapped, you have to have smf and joomla on the same subdomain.

The wrapper works great... it's just that I don't want it to go directly to the SMF index...

Naesstrom

#33
Quote from: Orstio on December 15, 2005, 04:50:31 PM
Putting this in your SMF index.php does not work?

// Redirect users who try to access /forum directly
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: http://portal.myurl.com//index.php?option=com_smf&Itemid=yourItemidNum");}
}


Make sure to change "yourItemidNum" to your Itemid number of your bridge component.

a little confused... How do I know the itemID of the component... is that the link to the forum on the mainmenu?
btw... that code should be somewhere after
require_once($sourcedir . '/Subs.php');

[edit]
I tried and enter the URL directly in my browser and it didn't matter what ItemID I put in there... I always ended up at the SMF startpage
http://portal.sharpweaponcenter.com/index.php?option=com_smf&Itemid=26
http://portal.sharpweaponcenter.com/index.php?option=com_smf&Itemid=1
http://portal.sharpweaponcenter.com/index.php?option=com_smf&Itemid=89

Orstio

Quotea little confused... How do I know the itemID of the component... is that the link to the forum on the mainmenu?

Yes, when you click on the "Forum" link from your main menu, you will see the url something like

http://portal.myurl.com/index.php?option=com_smf&Itemid=

And the Itemid number will follow the "Itemid=" part.

Naesstrom

Quote from: Orstio on December 15, 2005, 05:02:22 PM
Yes, when you click on the "Forum" link from your main menu, you will see the url something like

http://portal.myurl.com/index.php?option=com_smf&Itemid=

And the Itemid number will follow the "Itemid=" part.

well... thats 26, but it still doesn't work...

exrace

Try a simple relative redirect first like I did in my example above - it works great and fixed many issues I had with users password resets and popups from the forums.

Could be your apache setup is not setup to support this subdomain reference.

Orstio

Quotewell... thats 26, but it still doesn't work...

Where did you put the code?

Naesstrom

Quote from: exrace on December 15, 2005, 05:13:23 PM
Try a simple relative redirect first like I did in my example above - it works great and fixed many issues I had with users password resets and popups from the forums.

Could be your apache setup is not setup to support this subdomain reference.

nope... tried that right now and that didn't work either...

Naesstrom

Quote from: Orstio on December 15, 2005, 05:15:03 PM
Quotewell... thats 26, but it still doesn't work...

Where did you put the code?

in the index.php of the SMF installation, this is how it looks...
// And important includes.
require_once($sourcedir . '/QueryString.php');
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Errors.php');
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Security.php');

// Redirect users who try to access /forum directly
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: http://portal.sharpweaponcenter.com//index.php?option=com_smf&Itemid=26");}}

Orstio

1) You don't want it executing that much.  Place it higher. Directly under the top comments is fine.

2) You have two // before index.php, which could be another potential problem.

Naesstrom

Quote from: Orstio on December 15, 2005, 05:23:58 PM
1) You don't want it executing that much.  Place it higher. Directly under the top comments is fine.

2) You have two // before index.php, which could be another potential problem.

ok... now it looks like this but it still doesn't help!
$forum_version = 'SMF 1.0.5';

// Get everything started up...
// Redirect users who try to access /forum directly
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: http://portal.sharpweaponcenter.com/index.php?option=com_smf&Itemid=26");}
}
define('SMF', 1);
@set_magic_quotes_runtime(0);
error_reporting(E_ALL);
$time_start = microtime();

Orstio


exrace


Naesstrom

Omg... I must have been 2 tired last night... I want it to do the opposite... when I log in I DON'T want to go directly to the SMF... I have always done that since I installed the bridge...

now I finally understand why I thought it nevered worked... :D

Orstio

QuoteOmg... I must have been 2 tired last night... I want it to do the opposite... when I log in I DON'T want to go directly to the SMF... I have always done that since I installed the bridge...

Denying direct access to the forum has nothing to do with redirects on login and logout....

Naesstrom

nope... I missunderstood the entire topic last night... ;)

ChaosEnergy

hi

works perfectly :)

i only have a question, is there a way, to make some code between to give me a chance to reach forum old way, when coming from special adress, or with a parameter in link, or only when going to admin...

sometimes i have little issues when using wrapped mode, and i need a possibility to check if it is wrapped issue or not :P
Chaos Empire ®

Nitro

ok, here we go again. guys, i have been using this little tool for some time and i never had any errors, well actually there is no errors at all, but the redirect code doesn't work any more, i moved my forum to another server. i put this little code in the forum root index.php
if (strpos($_SERVER['QUERY_STRING'], 'dlattach') === false)
{
        if(!defined('_VALID_MOS')){ header("Location: http://www.mypowerforum.com/index.php");}
}


but that doesn't work, it gaves me page cannot be displayed. this is really weird, can someone tell me what am i missing? thank you guys, and specially Orstio for this little cool code.
MPF Rocks!!!

Ouly

I have just tried to access http://www.mypowerforum.com/bb/ and I have been correctly redirected without any error... (with Firefox 1.5 and IE 6.0)

Nitro

hey, that's weird! it wasn't working at first  :D

cool! i don't what happend but... it works now.

thank you man!
MPF Rocks!!!

Ouly

Notice : sometimes, a redirection shouldn't only be :

header("Location: http://...");

but :

header("Location: http://...");
exit;

rmderks

Hi guys,

I am confused. Can i use any of these codes to fix the links in the
email notifications to wrapped.

How can i get my email notifications in wrapped form?

CMS: Joomla
Bridge: not using any, just standard wrap function in Joomla
This is my website: hxxp:www.hortiforum.nl [nonactive]
Template: classic

Thank you so much!!

Roy

Kindred

no...

1- this hack will only work in combination with the bridge
2- using the wrapper component will screw up your forum (the forum does not run well in an iframe)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: