Jump to content

Storing info in session


Rabastan

Recommended Posts

Rather new to PHP but I am learning

 

I have a simple login system for a website, and a table for users.

 

user table has these fields;

 

id

firstname

lastname

email

username

password

 

What I would like to do is store the first and last name in the session also in order to display "Welcome FIRSTNAME LASTNAME" on the site

 

Code is as follows;

 

main_login.php

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>

 

checklogin.php

$host="localhost"; // Host name 
$username="******"; // Mysql username 
$password="*****"; // Mysql password 
$db_name="*****"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}
?>

 

Any help is appreciated Thank You

Ran

Link to comment
Share on other sites

What does it matter where I got the code from, this forum is entitled "PHP Coding HELP"!!! Which would lead one to assume its a place to go when you need help with PHP, NOT somewhere to go and get ridiculed about my php. If that is what I was looking for I would have gone to "Tease you because your not as good as I am" forum.

 

Come on people grow the fuck up!! If your not interested in helping don't post, does it really make you feel better to put people down??

 

Rab

Link to comment
Share on other sites

Rather new to PHP but I am learning

 

I have a simple login system for a website, and a table for users.

 

user table has these fields;

 

id

firstname

lastname

email

username

password

 

What I would like to do is store the first and last name in the session also in order to display "Welcome FIRSTNAME LASTNAME" on the site.

 

Code is as follows;

 

main_login.php

 

Yah I am pretty sure that there pretty much explains what I am trying to do!!

 

Rab

Link to comment
Share on other sites

This forum is entitled "PHP Coding HELP"!!! Which would lead one to assume its a place to go when you need help with PHP, NOT somewhere to go and get ridiculed about my php. If that is what I was looking for I would have gone to "Tease you because your not as good as I am" forum.

 

Come on grow the fuck up! Your a mod your tasked to maintain the integrity of this forum, you should be ashamed!!

 

If your not interested in helping don't post, does it really make you feel better to put people down??

 

Rab

 

In response to the above shitty PM you sent me when I was trying to alert you that the old code you COPIED AND PASTED from a crappy website was badly out of date, would you care to explain just how exactly my post is in any way "putting people down"?

 

Just how do you think it is that I was able to recognize that code as being from phpeasystep.com so easily? Do you think it's because their code is perfect, and nobody ever posts it here with problems, or do you think it's because it gets posted here all the time and is constantly problematic?

Link to comment
Share on other sites

Ah Pik, the `ole "stop trying to help me, but give me what I want" thread.  You never win in this one.

 

Back to the OP, the request you posted, has nothing to do with the code you posted.

<?php
session_start();
if(isset($_GET['name'])) {
$name = $_GET['name'];
$_SESSION['name'] = $_GET['name'];
} elseif(isset($_SESSION['name'])) {
$name = $_SESSION['name'];
} else {
$name = 'Guest';
}
echo 'Welcome ' . $name;

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.