Page 1 of 1

restricting page access

Posted: Mon Jun 21, 2004 4:31 am
by bugthefixer
i have a page whose url is like this
http://www.rp.com/category?name=1&cat=blue
this page is infact accessed from a link in previous page..
the problem is if i write this url as it is in browser then this page is access as normal..but i want to restrict it so that if this page is accessed from the previous page only then it is displayed otherwise it should display a message access denied..
secondaly my variables name and cat appear in the url as it is ..how can i make them look like encoded..

Posted: Mon Jun 21, 2004 5:17 am
by Grim...
One way:

Code: Select all

<?php
$referrer = $HTTP_REFERER; //this is the name of the page the user came from
if ($referrer != 'yourpagename.php')
{
    print "Access Denied";
    exit;
}

//rest of page here

?>

Posted: Mon Jun 21, 2004 8:25 am
by tim
use sessions.

8)

Posted: Mon Jun 21, 2004 9:23 am
by feyd
I'd have to agree with tim here, using referer could easily not work, as a lot of browsers/proxies either don't send or strip out such a header.

Posted: Mon Jun 21, 2004 9:36 am
by tim
I wish the session tutorial was still around by jason. that would be a excellent link to post here.

feyd, did u leave a msg about that in the mod forum?

Posted: Mon Jun 21, 2004 9:39 am
by feyd
yeah.. jason no say any'ting yet.

thanks

Posted: Tue Jun 22, 2004 12:55 am
by bugthefixer
thanks all of for replying..
i have used sessions in my website but i cant figure out how i use sessions for this purpose

Posted: Tue Jun 22, 2004 1:08 am
by Illusionist
on your first page set a session variable:

Code: Select all

$_SESSION['mine'] = "page1";
Then on your other page check that sessino variable:

Code: Select all

if($_SESSION['mine'] != "page1"){
    echo "Access Denied!"
}else{
    //the rest of your page
}
Atleast thats what i would do!