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.
|
|
|
|
|
![]() |
||
Protect Pages
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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 |
|
|
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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. |
![]() |
| Tags |
| login protect pages |
| Thread Tools | |
|
|
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 20:18 |
| Protect the script. | Voxart | JavaScript Forum | 3 | Nov 6th, 2005 13:38 |
| Scripting Needed(adding pages to pages) | Amari | Classic ASP | 1 | Sep 4th, 2004 18:06 |