...

View Full Version : Username Session Input?



skill3d
11-12-2011, 12:47 AM
Alright so the title may be a bit misleading but im working on a social network and i have it at the point where users can Register, log-in, Update Status's, and upload pictures.

My question is with the upload part of the social network. I have my upload.php that uses connect.php to connect to the database, then after uploading there is a view.php to view the image. My Login files and Upload files were coded separately and now im implementing them together.

At the top of upload.php i have:


include("connect.php");

$_SESSION['username']="Anthony Cordio";

$username = $_SESSION['username'];

This is where i have the problem, i have a session from before with the log-in that has a username. Instead of manually typing in what username i have to upload as (what other users can do) what would i put to replace "Anthony Cordio" in


$_SESSION['username']="Anthony Cordio";

So that it pulls a session username from when the user is logged in, In other words i want it to autofill the username from the other session.
If i didn't do a good job at explaining or you need more explaining let me know.
Thanks Much, -Anthony


ALSO:


connect.php:

<?php

$error = "Unable to connect.";
$connect = mysql_connect("localhost","root","") or die ($error);
mysql_select_db("phplogin") or die ($error);

session_start();

?>

login.php:

<?php

session_start();

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

if ($username&&$password)
{

$connect = mysql_connect("localhost","root","") or die("Couldn't connect!");
mysql_select_db("phplogin") or die ("Couldn't find db");

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows!=0)
{

while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}

// check to see if they match
if ($username==$dbusername&&$password==$dbpassword)
{
echo "You're in! <a href='member.php'>Click</a> here to continue to the site.";
$_SESSION['username']=$username;
}
else
echo "Incorrect password!";

}
else
die("That user doesn't exist!");


}
else
die("Please enter a username and passord");


?>

sunfighter
11-12-2011, 08:25 AM
You set $_SESSION['username']; in your login script. You can place that anywhere you want it with php by placing this where the name should be:
<?php echo $_SESSION['username']; ?>

But you should do some work on your login script.
read this:
http://www.devshed.com/c/a/PHP/Creating-a-Secure-PHP-Login-Script/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum