Protect Pages

This is a discussion on "Protect Pages" within the PHP Forum section. This forum, and the thread "Protect Pages are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 26th, 2006, 13:07
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 465
Thanks: 1
Thanked 0 Times in 0 Posts
Protect Pages

hey i have a login script and its working fine but i want to protect the page so if peopel not logged in that cant view the pageso i put this code

<?
include("Login/include/session.php");
if($session->logged_in){
echo "You are viewing the protected page";
}
else{
echo "You are not allowed to view this page";
}
?>


at the top of the page before any code and at top it says

You are not allowed to view this page

but it still views the page heres an example

www.3d-modelling-art-online.com/Gallery.php

could any one help please
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 26th, 2006, 14:30
Reputable Member
Join Date: Feb 2006
Location: London
Age: 26
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Re: Protect Pages

Use this...

else{
echo "You are not allowed to view this page";
die();
}

In your original code, you are echoing some text, but after it's done that, it will continue through the rest of your code!

die(); will kill the script. You could also use exit(); instead...

You can also redirect them with the code below. You should still use die after the redirect.

else{
header("location : http://www.differentpage.com");
die();
}

Cheers,
Jim.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 26th, 2006, 14:43
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 465
Thanks: 1
Thanked 0 Times in 0 Posts
Re: Protect Pages

but before the else code above it dont u have to put <? so it recordnises the code mate

and as i am beginner at this lol where should i put the code so it works make and is that code right because at beginning doesnt it have to have <? and at end of code doesnt ti ahve to be ?>

Thanx
Aaron

Last edited by Aaron1988; Oct 26th, 2006 at 14:49. Reason: more text
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 26th, 2006, 18:22
Up'n'Coming Member
Join Date: Jan 2006
Location: East Sussex
Age: 27
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Protect Pages

The code needs to go at the very top of the page, what jimz says will work but for easy of typing he just didnt put the full code in. All he means is that underneath the line that says
echo "You are not allowed to view this page";
you should put the die statement - die();
You are also using short hand php tags, instead of using <? and ?> to denote php you should use <?php, the reason is that the tag <? can be interpreted differently depending on the server you use where as <?php is standard on all php installed servers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 26th, 2006, 18:45
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 465
Thanks: 1
Thanked 0 Times in 0 Posts
Re: Protect Pages

i am a beginner lol can you show me the example of the cod ein full so i can jsut copy and paste it in my website please because i am a total beginner

well i done it but when i use the redirect code doesnt redirect me ?

Last edited by Aaron1988; Oct 26th, 2006 at 18:59.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
login protect pages

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript - Updating web pages with snippets from other pages Ydot JavaScript Forum 3 Jul 10th, 2007 14:38
How can I best protect my images? Craigj1303 Webforumz Cafe 14 Apr 28th, 2007 05:14
Protect web content webdevelopa Scripts and Online Services 4 Feb 24th, 2007 21:18
Protect the script. Voxart JavaScript Forum 3 Nov 6th, 2005 14:38
Scripting Needed(adding pages to pages) Amari Classic ASP 1 Sep 4th, 2004 18:06


All times are GMT. The time now is 09:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved