Current location: Hot Scripts Forums » Programming Languages » PHP » PHP User Authentication


PHP User Authentication

Reply
  #1 (permalink)  
Old 07-01-04, 11:26 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Question PHP User Authentication

Gooday people.

I read up this tutorial on how to create a user authenticaon script but then I realised how bad it is. It uses the following method to authenticate. This works well. But the tutorail had no info on how to protect the pages it self. You could go to the page direct adn they would obviously work.

PHP Code:

//LOG IN AREA

$sql "SELECT * FROM `promoter` WHERE 1 AND `Email` = '$email' AND `Password` = '$password'";
$resultAuth mysql_query($sql) or die ("Unable to get results.");
$num mysql_numrows($resultAuth) or die ("<meta http-equiv='refresh' content='1; url=error.php'>");
$resultAuth2 mysql_query($sql) or die ("Unable to get results.");

if (
$num == 1) {

echo
'
<title>Blah blah blah</title>'
;


Now querying this databqse is great as I can use one of the variables ( resultAuth2['idname'] ) to query the main page that the login page redirects to.

I read somthing about global variables or somthing but that tutoral just dont make sence to me but sounds like what I need.

Q1. How can I get a variable to the next php page.
Q2. How can I redirect them to the login page if they try to find the main page without them login in.

Last edited by dihan; 07-01-04 at 11:28 AM.
Reply With Quote
  #2 (permalink)  
Old 07-01-04, 11:46 AM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
You could use sessions; have a bit of code to check the session variable at the top of the page and if not set send them to the login page.

// Login page
session_start();
session_register($variable);
// Set the variable '$variable' in the form

// Other pages
session_start();
if ($variable not equal - I dont know this bit - '1' )
{ header login page }

I have just made this up from memory; my memory is not very good but this should give you the gist of it.

Anthony
Reply With Quote
  #3 (permalink)  
Old 07-01-04, 01:03 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah for more detailed information goto www.php.net/sessions

I use php.net for all my questions. It's a wonderful resource.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #4 (permalink)  
Old 07-01-04, 03:09 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
close...

Thats great.. I had a read and got the following but I just cannot find a simple solution for the pages yet. All the forums have really complicated methods.

PHP Code:

//page1.php

session_start();
$_SESSION['promoter'] = 'PROMOTER';
echo 
"<meta http-equiv='refresh' content='1; url=page2.php'>";

//page2.php
session_start();
$promoter $_SESSION['promoter']; 
This works but I need somthing like what Bonzo mentioned in order to send it to page1.php if someone have not logged in and tried to get on to page2.php

had a read through php.net but I still dont know enough to understand the functions that people post on there.
Reply With Quote
  #5 (permalink)  
Old 07-01-04, 03:38 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
The only other way I can think of doing it using an alert box or include a box saying not logged in and click here to go to login page. I find the header a bit of a pain as it has to be output first.

Anthony
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a PHP user management system waffffffle2 Script Requests 2 06-19-04 04:32 AM
Quick Question for you php guru's Tokahashi PHP 3 04-09-04 12:00 PM
user authentication advice andyhume PHP 0 02-06-04 03:34 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Ad management and optimisation using php surebetdmg PHP 0 08-28-03 06:45 PM


All times are GMT -5. The time now is 05:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.