PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 13th, 2012, 12:09 AM
scm22ri scm22ri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 49 scm22ri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 34 m 35 sec
Reputation Power: 4
Wrote a function, it's working but don't know how to use it?

Hi Everyone,

I wrote a function for a login script. I tested the function and it's working but when I include it on my website it's not working. I'm not sure what I'm doing wrong. What do you guys think?

Thanks Everyone.

syntax for function

PHP Code:
function loggeduser($name$password){ 

  
$name mysql_real_escape_string($name); 
  
$password mysql_real_escape_string($password); 
   
  
$password sha1($password); 
   
    
// getting the ID here 
     
$sql_id mysql_query("SELECT * FROM practice WHERE name='$name' AND password='$password'");   
     while(
$row mysql_fetch_array($sql_id)){ 
     
$id $row["id"]; 
    }  

     
$sql = ("SELECT id FROM practice WHERE name='$name' AND password='$password'"); 
     
$result mysql_query($sql) or die(mysql_error()); 
      
     
$countmysql_num_rows($result); 
      
     if (
$count == 1){ 
     
$_SESSION['authorized'] = true
     
$_SESSION['id']; // <-- not sure if I need this?  
     
$_SESSION['password'] = $password
     
$_SESSION['name'] = $name
      
    
header("location:userspage.php"); 
      
     } else { 
       echo 
"Wrong username and password <br>";  
     }  



login script

PHP Code:
<?php 
session_start
(); 
include
"connect_to_mysql3.php"
$loggedinuser $_SESSION["id"]; 
$name $_SESSION["name"]; 
    
// include 'edit-car-function-for-login.php'; 
   
 
if (isset( $_POST['name'], $_POST['password'] )){ 

    
$name $_POST['name']; 
    
$password $_POST['password']; 
     
    
$password sha1($password); 
     
    
$name mysql_real_escape_string($name); 
    
$password mysql_real_escape_string($password); 
     
    
$sql_id mysql_query("SELECT * FROM practice WHERE name='$name' AND password='$password'");   
    while(
$row mysql_fetch_array($sql_id)){ 
    
$id $row["id"]; 
    }  
     
    
$sql = ("SELECT id FROM practice WHERE name='$name' AND password='$password'"); 

    
$result mysql_query($sql); 
     
    
$count=mysql_num_rows($result); 
     
    if(
$count==1){ 


    
$_SESSION["name"] = $name
    
$_SESSION["id"] = $id

   
header("location:userspage.php"); 
    

   } else { 
   echo 
"Wrong Username and Password.";  
  }  
}

Reply With Quote
  #2  
Old November 13th, 2012, 12:37 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,855 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 16 h 5 m 43 sec
Reputation Power: 813
Hi,

what does "not work" mean? Do you get an error message? Does your computer crash?

Apart from that, I don't get what you're trying to do. OK, you have a function. But you don't use this function in your login script and instead write down some similar (but different) code. Um, is this another try?

The code itself also has several oddities. What's the point of repeating the same query twice? Why do you need a "while" loop to fetch a single row?

Also you must not store the password hash in the session. This is extremely unsecure and completely pointless (what do you need the hash for when the user is already logged in?). The password hash is supposed to be stored in exactly one column in the database and nowhere else. Not in the session, not in a cookie.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Wrote a function, it's working but don't know how to use it?

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap