Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
member login and set cookie help
Old 02-09-2008, 09:12 PM member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hiya

me again lol

as you might of guessed, i am new to php so learning as i go along but trying to make a member part on my site so they have a profile.

so far, they can create an account fine and fill all there details and all info goes to database fine.

but i am struggling to find out how to get it so they can log in and set cookie.

this is the code i have so far but wont work and dont set cookie :-(

PHP Code:
<?
include( "inc/db.php" );

$name $_POST['name'];
$password =  $_POST['password'];


$result mysql_query("SELECT * FROM Profiles WHERE login = $name AND password = $password");  
echo 
$result;
$iTotalNum db_value"SELECT COUNT( * ) FROM `Profiles` $sqlWhere);

if( !
$iTotalNum )

{
echo 
"<center><h4>Sorry, incorrect username and/or password.</h4><br><br></center>";
echo 
"<center><a href='login.php'>Click here to try again.</a></center>";
exit;
}
 

$id mysql_query("SELECT * FROM Profiles WHERE login = $name AND password = $password");
setcookie('member'$name$password$id); 


echo 
"<center><h4>You have successfully logged in.</h4><br><br></center>";
echo 
"<center><a href='index.php'>Please click here to continue.</a></center>";

?>
can someone tell me where i am going wrong pleaseeee cause i have now chewed my fingers down to the elbows trying to work it out.

I need it to set in the cookie the ID of the members name as that will be used throughout the site by reading it of cookie.

in database i got
Profiles >
......ID (auto_increment)
......name
......password

i would also like the cookie to expire after 4 hours, i know it should be something like this

$expire = 60 * 60 * 24 * 1 + time();
setcookie('member', $name, $password, $id, $expire);

but not 100% sure

thanks for any help.. and hopefully i will be able to help others here 1 day!

shaz xx
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 02-09-2008 at 09:19 PM.. Reason: edited cause i missed a bit
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-09-2008, 09:59 PM Re: member login and set cookie help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You may want to consider using a session rather than a cookie.
http://us.php.net/session

Just use session_start() to create your session and then you can use session variables to store and access whatever information is relivant to that user.

Also, I noticed you are not using any encryption for your passwords. Just as a very basic form of security you should apply a sha1 encryption to your password before storing it in your database.

http://us3.php.net/sha1
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-09-2008, 10:10 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hiya

i decided to use cookies because sessions just sounded to complicated and also they may cause some problems to some of the idea's i have ( if i ever get past the profile part ) hehe

and password encryption is something i am going to add but once i get this to all work.. i am doing basic first then going to add that.

i was thinking more along the lines of making my own encryption .. maybe something like.. split the password up into letters then pending on the letter use 3,4 or 5 symbols.. say letter "a" might = f52 and so on then imploding it again to the database and cookie
just rather use that way if i can work it out than a more well known method.

its just the above i need to work out if anyone can help me with that.. then i will sort an encryption method later.

thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 02-09-2008 at 10:13 PM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-09-2008, 10:21 PM Re: member login and set cookie help
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
Trades: 0
You use of setcookie is wrong:

Quote:
setcookie('member', $name, $password, $id, $expire);
the expire is the third parameter, and the value/s is the second (http://ar.php.net/set_cookie). You maybe put all the values in a string like "$name,$password,$id" and then explode it to retrieve the individual values, or set three cookies for each one, but i prefer use the concatenated string.


Quote:
$values = "$name,$password,$id";
setcookie('member', $values, $expire);
Anyway the better way to perform this is the suugestion of NullPointer, with sessions.
__________________
-----------------------

Please login or register to view this content. Registration is FREE
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Old 02-09-2008, 10:38 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
aha thanks!
PHP Code:
$values "$name,$password,$id";
setcookie('member'$values$expire); 
works fantastic, sessions... i just can't get my head around yet so taking the simpler route that i at least know a tiny bit about before i learn them to lol

i am getting this error now lol

Fatal error: Call to undefined function db_value() in /home/content/html/site/process_login.php on line 10

and also.. lol

when i find in the database.. the match for username and password.. how do i go about finding out what the id number is, its primary and set to auto_increment

thanks

shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-09-2008, 11:35 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
fixed it and it works grate wooohooo hehe

thanks for your help

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 01:35 AM Re: member login and set cookie help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Once you get $result from your sql query just build an associative array from it.
PHP Code:
$user mysql_fetch_array($resultMYSQL_ASSOC);

$id $user['id']; // where id is the name of the column in which your user id appears 
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-10-2008, 01:44 AM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
this is the working version lol

and nope i not done the password encryption yet, i still need to work out how to explode words to single letters lol

shaz x

PHP Code:
<?
include( "inc/db.php" );

$name $_POST['name']; $name mysql_real_escape_string($name);
$password =  $_POST['password']; $password mysql_real_escape_string($password);
 

$result mysql_query("SELECT * FROM Profiles WHERE login = '$name' AND password = '$password'");
$row mysql_fetch_array$result );

$testit $row['login'];
if (
$testit == "")
{
echo 
"<center><h4>Sorry, incorrect username and/or password.</h4><br><br></center>";
echo 
"<center><a href='login.php'>Click here to try again.</a></center>";
exit;
}


$userdata = array($row['login'],$row['password'],$row['ID']);
$data implode("|"$userdata);
for(
$i 0$i count($data); $i++);
setcookie('member'$datatime()+3600);


echo 
"<center><h4>Welcome back.<br><br>";
echo 
$row['login'];
echo 
"<br><br>You have successfully logged in.<br><br>";
echo 
"<a href='index.php'>Please click here to continue.</a></center>";
?>
This is dam hard to learn but i am getting there slowly hehe
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 02-10-2008 at 01:22 PM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 02:01 AM Re: member login and set cookie help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You have a random for loop in your code that doesn't appear to have a body.

PHP Code:
for($i 0$i count($data); $i++); //This should look like this:

for($i 0 $i count($data); $i++)
{
     
//body

I don't know how php is handling that particular line of code... in java you would just get an error, but either way I don't see how it is working as intended.
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-10-2008, 02:02 AM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
now i worked out a way to encrypt the password...

this is just a simple thing hehe but will be a lot more complicated as i process it 2 times.. before adding to database and cookie, then just reverse it when the script needs to know the password

PHP Code:
<?
$password 
"abc";
echo 
"unmixed = "; echo $password

$a str_replace("a""fwe8"$password);
$b str_replace("b""6ka"$a);
$new str_replace("c""y2wrok"$b);

// and through the rest of the alphabet...

echo "<br><br>mixed = "; echo $new;

?>
Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 02-10-2008 at 02:04 AM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 02:04 AM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by NullPointer View Post
You have a random for loop in your code that doesn't appear to have a body.

PHP Code:
for($i 0$i count($data); $i++); //This should look like this:

for($i 0 $i count($data); $i++)
{
     
//body

I don't know how php is handling that particular line of code... in java you would just get an error, but either way I don't see how it is working as intended.
OOPS!

Thats because i was trying something out on another php file and left that there.. then knicked it for this php file hehe

thanks for pointing that out

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 02:07 AM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by NullPointer View Post
I don't know how php is handling that particular line of code... in java you would just get an error, but either way I don't see how it is working as intended.
lol it was!
you try it, no error at all, have sorted it now anyway hehe

thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 02:14 AM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
lol
just checked and i still had that loop with no body in my 3 implode statments on my join form to!

i need some kind of program that i can put my php files in to check for errors hehe

i am writing them in notepad at the moment, is there anything better?

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 10:44 AM Re: member login and set cookie help
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
With regards to sessions and cookies, I began my login with sessions and litterally yesturday added cookie support, at first i found sessions a pain and very annouying but its just one of those thing which you just have to learn the knack of using them and your away.

Anyway sessions are generally better because its much more secure to give the user the OPTION not to save the login becasue as many people used shared computers etc it can cause problems.

Anyway i have a simple if/else on my pages which does if session not set but cookie is reset the session.

hope this makes a bit of sense and helps
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 10:54 AM Re: member login and set cookie help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Sharon_leic View Post
lol
just checked and i still had that loop with no body in my 3 implode statments on my join form to!

i need some kind of program that i can put my php files in to check for errors hehe

i am writing them in notepad at the moment, is there anything better?

Shaz x
Dreamweaver helps a bit, but there is no strong error checking in any IDE I've seen for PHP.
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-10-2008, 10:57 AM Re: member login and set cookie help
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
im suprised there isnt any ides which have the PHP core in them, so they can run the script and alert if any errors come up.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 12:43 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
With regards to sessions and cookies, I began my login with sessions and litterally yesturday added cookie support, at first i found sessions a pain and very annouying but its just one of those thing which you just have to learn the knack of using them and your away.

Anyway sessions are generally better because its much more secure to give the user the OPTION not to save the login becasue as many people used shared computers etc it can cause problems.

Anyway i have a simple if/else on my pages which does if session not set but cookie is reset the session.

hope this makes a bit of sense and helps
Hiya
I'm not saying i will never ever use them, i am just trying to make the basic site at the moment while getting the feel for php and MySQL.
I am okish with html and was fantastic with SLS and in SL i used to code slot machines and games and sell them and make a fair bit of money from them but since SL stopped gaming in the world i am just trying to look for other ways to make money coding.. and trying my hand a this lol..
Just that i have to start simple, get the item done so that i have something to look at then the incentive creeps in to perfect it and think about security and alternative methods hehe

Hope that makes sense?

does to me... well there again, my php scripts make sense to me until i try running them and i find i got stupid errors in them

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 12:48 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
NullPointer > Dreamweaver helps a bit, but there is no strong error checking in any IDE I've seen for PHP.

dansgalaxy > im suprised there isnt any ides which have the PHP core in them, so they can run the script and alert if any errors come up.

I thought there would be!
I know a lot of you advanced php'ers would prob never use them but they would be a good help to php newbies like me, would be cool to be able to paste the code in a window and it highlights and error and says why its an error.. bit like m$ word?

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 01:59 PM Re: member login and set cookie help
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
the big problem is becasue PHP is SO good (no bias .. not) and like with all programming langauages is virtually impossible to make a program which can spot all the errors without running it, and even then theres still problems.

i still think a program which could "run" the script would be good..
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 02:08 PM Re: member login and set cookie help
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
the big problem is becasue PHP is SO good (no bias .. not) and like with all programming langauages is virtually impossible to make a program which can spot all the errors without running it, and even then theres still problems.

i still think a program which could "run" the script would be good..
Yes, and one that can recognize MySQL commands to
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to member login and set cookie help

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.55648 seconds with 12 queries