web diary

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



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 4th, 2007, 19:46
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
web diary

Hi forumz
I've got a friend who wants me to make him a diary that only him can access and maybe some other friends. Anyone with such a script would be very helpful

Cheers Jon
Reply With Quote

  #2 (permalink)  
Old Aug 4th, 2007, 19:53
1840dsgn's Avatar
SuperMember

SuperMember
Join Date: Jun 2007
Location: Canterbury
Age: 19
Posts: 717
Thanks: 0
Thanked 0 Times in 0 Posts
Re: web diary

Just create a login authentication system with PHP. Look for tutorials theres plenty out there, and ready made scripts.
Reply With Quote
  #3 (permalink)  
Old Aug 4th, 2007, 23:17
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

Since there's only a few person viewing it, you'd only need one or two usernames so mysql would be pointless i guess.
This might work, haven't tested it.
login form:
Code: Select all
<form action="login.php" method="post">
<p>Username<br>
<input type="text" name="user"></p>
<p>Password:<br>
<input type="password" name="pass"></p>
<p><input type="submit" value="login"></p>
</form>
login.php:
PHP: Select all

<?php 
session_start
$username
=$_POST['user'];
$password=$_POST['pass'];
$checkuser="username"//replace username with your own.
$checkpass="password123"//replace with your own password like above

if($username == $checkuser && $password == $checkpass) {
$_SESSION['loggedin'] == $username;
} else {
echo 
"wrong username/password";
}
?>
everypage that should be protected from people not logged in should have:

PHP: Select all

<?php 
session_start
;
if (!isset(
$_SESSION['loggedin'])) {
echo 
"you aren't logged in";
exit();

?>
<!-- html here -->

That should work
Sorry if you know how to do this already.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Aug 5th, 2007, 10:51
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

Quote:
Originally Posted by alexgeek View Post
Since there's only a few person viewing it, you'd only need one or two usernames so mysql would be pointless i guess.
This might work, haven't tested it.
login form:
Code: Select all
<form action="login.php" method="post">
<p>Username<br>
<input type="text" name="user"></p>
<p>Password:<br>
<input type="password" name="pass"></p>
<p><input type="submit" value="login"></p>
</form>
login.php:
PHP: Select all

<?php 
session_start
$username
=$_POST['user'];
$password=$_POST['pass'];
$checkuser="username"//replace username with your own.
$checkpass="password123"//replace with your own password like above

if($username == $checkuser && $password == $checkpass) {
$_SESSION['loggedin'] == $username;
} else {
echo 
"wrong username/password";
}
?>
everypage that should be protected from people not logged in should have:

PHP: Select all

<?php 
session_start
;
if (!isset(
$_SESSION['loggedin'])) {
echo 
"you aren't logged in";
exit();

?>
<!-- html here -->

That should work
Sorry if you know how to do this already.

Says there is an error on this line
PHP: Select all

$username=$_POST['user']; 

Reply With Quote
  #5 (permalink)  
Old Aug 5th, 2007, 13:56
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

sorry it should be:
PHP: Select all

session_start(); 

the missing semi-colon meant that it did not finish the line
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Aug 5th, 2007, 15:56
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

wow that was cool. And can you put a logout buttons? what code do u put to it?
Reply With Quote
  #7 (permalink)  
Old Aug 5th, 2007, 16:01
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

I use this method:
PHP: Select all

<?php 
session_destroy
();
echo 
"You have logged out";
?>
Save it as logout.php
then just link to it normally like:
<a href="logout.php">Click here to logout</a>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #8 (permalink)  
Old Aug 5th, 2007, 16:26
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

I have put the code in the logout.php file and this is what I get

Code: Select all

Warning:  session_destroy(): Trying to destroy uninitialized session in /mypath/logout.php on line 2
You have logged out
did I mess somewhere?
Reply With Quote
  #9 (permalink)  
Old Aug 5th, 2007, 16:51
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

oh sorry
i think it should be:
PHP: Select all

   <?php 
session_start
();
session_destroy();
echo 
"You have logged out";
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #10 (permalink)  
Old Aug 5th, 2007, 17:13
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

that works but if you click back it still displays the details that are supposed to be secure. Even when you put a wrong password it still dispays the information but still gives you the "wrong password"
Checkout here. Is it neccessary to display everything that I have put here?
Reply With Quote
  #11 (permalink)  
Old Aug 5th, 2007, 17:16
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

What's the link to the page that the content is actually on?
and what username/password are you using?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #12 (permalink)  
Old Aug 5th, 2007, 18:02
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

http://john.habari.co.tz/loginphp/
Username: admin
Password: 123

After login try to click on NOT link says "you aren't logged in"
Reply With Quote
  #13 (permalink)  
Old Aug 5th, 2007, 18:11
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

okay i don't understand what the "not.php" page is for.
but put this on your content protected page after session_start();
PHP: Select all

print_r ($_SESSION); 

and tell me what you get.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #14 (permalink)  
Old Aug 6th, 2007, 18:46
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

When I login I get this
Code: Select all
Array ( ) you aren't logged in
am I supposed to add the protected pages script to the login.php?
Reply With Quote
  #15 (permalink)  
Old Aug 6th, 2007, 18:53
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
Re: web diary

Ok. Let me just put the whole thing here:

index.php
HTML: Select all
<form action="login.php" method="post">
<p>Username<br>
<input type="text" name="user"></p>
<p>Password:<br>
<input type="password" name="pass"></p>
<p><input type="submit" value="login"></p>
</form>

login.php
PHP: Select all

<?php
session_start
();
$username=$_POST['user'];
$password=$_POST['pass'];
$checkuser="admin"//replace username with your own.
$checkpass="123"//replace with your own password like above

if($username == $checkuser && $password == $checkpass) {
$_SESSION['loggedin'] == $username;
} else {
echo 
"wrong username/password";
}
?>

<?php
session_start
;
print_r ($_SESSION);
if (!isset(
$_SESSION['loggedin'])) {
echo 
"you aren't logged in";
exit();
}
?>

<b><i>Many details here</i></b><br />
<a href="logout.php">Click here to logout</a><br />
<a href="not.php">NOT</a>
logout.php
PHP: Select all

<?php
session_start
();
session_destroy();
echo 
"You have logged out";
?>
not.php
PHP: Select all

<?php
session_start
;
print_r ($_SESSION);
if (!isset(
$_SESSION['loggedin'])) {
echo 
"you aren't logged in";
exit();
}
?>
Please correct incase of any errors
Reply With Quote
  #16 (permalink)  
Old Aug 6th, 2007, 21:17
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

Okay for starters you don't need to link to the not page, as it's already in the login code.
What is the exact problem you are having?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #17 (permalink)  
Old Aug 6th, 2007, 21:18
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: web diary

Oh and my fault, change:

$_SESSION['loggedin'] == $username;

to

$_SESSION['loggedin'] = $username;
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Tags
diary

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
Diary/archive help, trying to use CSS to display DIVs dynamically... thintin Web Page Design 1 May 1st, 2008 20:54


All times are GMT. The time now is 22:21.


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43