PDA

View Full Version : Authenticated User Session Control On Non-VB Page


LifesGreatestGift
08-03-2009, 02:12 AM
I am currently running an image hosting script and want to limit it to my members only.

The image hosting script is located at

/home/jesse123/public_html/TW7S.com/images/

and my forum is

/home/jesse123/public_html/TheWindows7Site.com/forum/

Here is the code I have in the image hosting scripts index page:


<?

$url = "http://www.thewindows7site.com/forum/";


$curdir = getcwd ();
chdir('/home/jesse123/public_html/thewindows7site.com/forum');
require_once('/home/jesse123/public_html/thewindows7site.com/forum/global.php');


if ($bbuserinfo['userid'] =0) {


?>
<script type="text/javascript" language="JavaScript">
<!--
alert("You Must Register/Login To The Forum\n\To Use This Feature. -Administration Team");

window.location="<?php echo $url; ?>";
// -->
</script>

<?

}

else

{
echo"Thanks For Logging In, <b>$username</b>";
}

chdir ($curdir);

// IMAGE HOSTING SCRIPT .........


What am I doing wrong?

Andrew Green
08-03-2009, 02:56 AM
Try this:

<?php

error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'pageName');

chdir ("../forum");
require_once('./global.php');

if (! $vbulletin->userinfo['userid'])
{
print_no_permission();
exit();
}
echo "Hello!";

exec_shut_down();
?>

LifesGreatestGift
08-03-2009, 03:09 AM
Thanks for the reply

now when i visit the image hosting script, it redirects me to my forums login, I login and nothing happens.

Here is the image hosting

http://images.tw7s.com/
>exact location: /home/jesse123/public_html/TW7S.com/images

and here is my forum

http://thewindows7site.com/forum/
>exact location: /home/jesse123/public_html/thewindows7site.com/forum

I added this to the image host script


<?

$url = "http://www.thewindows7site.com/forum/";


error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'pageName');

chdir('/home/jesse123/public_html/thewindows7site.com/forum');
require_once('/home/jesse123/public_html/thewindows7site.com/forum/global.php');

if (! $vbulletin->userinfo['userid'])
{
print_no_permission();
exit();
}
echo "Hello!";

exec_shut_down();

// Below Here Is Image Host Script Index Code //

Andrew Green
08-03-2009, 03:17 AM
cookies aren't going to work across different domains like that.

LifesGreatestGift
08-03-2009, 03:21 AM
so i should put the script in forum/image/ ??

Its on the same server

Andrew Green
08-03-2009, 03:24 AM
yes, you also don't need the full path for the chdir and require, the relative paths in my example should work.

LifesGreatestGift
08-03-2009, 03:28 AM
ok image script is now in

/home/jesse123/public_html/thewindows7site.com/forum/imagehost

and forum is in

/home/jesse123/public_html/thewindows7site.com/forum

I put the following at the top of the imagehost index.php


<?

$url = "http://www.thewindows7site.com/forum/";


error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'pageName');

chdir ("../forum");
require_once('./global.php');

if (! $vbulletin->userinfo['userid'])
{
print_no_permission();
exit();
}
echo "Hello!";

exec_shut_down();

// Rest of Image Host Script Below //


and get this


Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/jesse123/public_html/thewindows7site.com/forum/imagehost/index.php on line 11

Warning: require_once(./global.php) [function.require-once]: failed to open stream: No such file or directory in /home/jesse123/public_html/thewindows7site.com/forum/imagehost/index.php on line 12

Fatal error: require_once() [function.require]: Failed opening required './global.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/jesse123/public_html/thewindows7site.com/forum/imagehost/index.php on line 12

Andrew Green
08-03-2009, 03:32 AM
with this going into a subfolder of forum go with this:

chdir ("../");

LifesGreatestGift
08-03-2009, 03:36 AM
ok, its working! Thank you! But one quick question

How would I go about changing it from giving a no permission login screen when not logged in, to having my popup, and directing them to the main page like this



$url = "http://www.thewindows7site.com/forum/";

<NON CODED> If user isnt logged in

then do this</NON CODED>

<script type="text/javascript" language="JavaScript">
<!--
alert("You Must Register/Login To The Forum\n\To Use This Feature. -Administration Team");

window.location="<?php echo $url; ?>";
// -->
</script>

Andrew Green
08-03-2009, 03:39 AM
Where it says "print_no_permission();" is what happens if they don't have a userid.

Where it says "hello!" is what happens if they do.

Replace each as you see fit.

LifesGreatestGift
08-03-2009, 03:41 AM
do i leave the exit in there?

Andrew Green
08-03-2009, 03:42 AM
yes, that exits the script, leaving everything bellow that available only to users with a userid

LifesGreatestGift
08-03-2009, 03:44 AM
thank you it works :-P

http://thewindows7site.com/forum/imagehost/