General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 8th, 2003, 02:09 PM
pjp pjp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 pjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help with sessions

i'am trying to update a login script to work with php version 4.3 and have come up with following but i can't gt it to work. i am new to sessions so any help would be appreciated.

authmain.php
<?
session_start();

if ($_POST['userid'] && $_POST['password'])
{
// if the user has just tried to log in

$db_conn = mysql_connect("localhost", "root", "choltas");
mysql_select_db("auth", $db_conn);

$query = ("select * from auth
where name='$_post[userid]'
and pass='$_POST[password]'");
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $userid;

$_SESSION['valid_user'] = $userid;
}
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if(isset($_SESSION['valid_user']))

//if (session_is_registered("valid_user"))
{
echo "You are logged in as: $valid_user <br>";
}
else
{
if (isset($userid))
{
echo "Could not log you in";
}
else
{
echo "You are not logged in.<br>";
}

member only.php

if(isset($_SESSION['valid_user']))
//if (session_is_registered("valid_user"))
{
echo "<p>You are logged in as $valid_user.</p>";
PHP Code:
<?

Reply With Quote
  #2  
Old March 8th, 2003, 03:21 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 6
try this,...

PHP Code:
<?
session_start
();

if (
$_POST['userid'] && $_POST['password'])
{
// if the user has just tried to log in

$db_conn mysql_connect("localhost""root""choltas");
mysql_select_db("auth"$db_conn);

$query = ("select * from auth where name='$_post[userid]' 
and pass='$_POST[password]'"
);
$result mysql_query($query$db_conn);
if (
mysql_num_rows($result) >)
{
// if they are in the database register the user id
$_SESSION['valid_user'] = $result['userid'];
}
}
?>
<html>
<body>
<h1>Home page</h1>
<? 
if(isset($_SESSION['valid_user']))
{
echo 
"You are logged in as: $_SESSION['valid_user']<br>";
}
else 
{
echo 
"You are not logged in.<br>";
}

member only.php

if(isset($_SESSION['valid_user']))
{
echo 
"<p>You are logged in as $_SESSION['valid_user'].</p>";
}
__________________
-- Jason

Reply With Quote
  #3  
Old March 8th, 2003, 05:32 PM
pjp pjp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 pjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thank you for your response, i had updated my code which looked similar to what you posted but all that happens is that the username and password disappear and nothing else happens

any ideas why

Reply With Quote
  #4  
Old March 8th, 2003, 06:01 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 6
let me explain how I do it,...maybe it will make more sense.

PHP Code:
if($_POST['Submit'] == "Submit")
{
     
$errors '';
     if(!isset(
$_POST['username'])) { $errors "need a username"; }
     if(!isset(
$_POST['password'])) { $errors "need a password"; }



then you do your query...

PHP Code:
 $find_user mysql_query("select * from users where unsername='{$_POST['username']}' and password='{$_POST['password']}'"); 


if everything seems to be ok,..grab the array and set session vars.

PHP Code:
if(mysql_num_rows($find_user) = 1)
{
     
$user mysql_fetch_array($find_user);
     
$_SESSION['user_id'] = $user['user_id'];



I think you are missing the main function here

PHP Code:
 mysql_fetch_array 

or
PHP Code:
 mysql_fetch_row 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > help with sessions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway