I have this code that logs the user in:
<?php
session_start(); // Shows we are using sessions
$dbHost = '*';
$dbUser = '*';
$dbPass = '*';
$dbname = '*'; // the database you put the table into.
$username = $_POST['username']; // Gets the inputted username from the form
$password = $_POST['password']; // Gets the inputted password from the form
$time = time(); // Gets the current server time
$check = $_POST['setcookie']; // Checks if the remember me button was ticked
$db = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Code
mysql_select_db($dbname,$db); // Connects to database
$query = "SELECT user, pass FROM login WHERE user = '$username' AND pass = '$password'";
$result = mysql_query($query, $db);
if(mysql_num_rows($result)) { // If the username and password are correct do the following;
$_SESSION['loggedin'] = 1; // Sets the session 'loggedin' to 1
if($check) {
// Check to see if the 'setcookie' box was ticked to remember the user
setcookie("username", $username, $time + 3600); // Sets the cookie username
setcookie("password", $password, $time + 3600); // Sets the cookie password
}
$ip = $_SERVER['REMOTE_ADDR'];
$d = date('D');
$m = date('M');
$D = date('d');
$y = date('y');
$date = "$d,$D,$m,20$y ";
mysql_query("INSERT INTO successful_logins (ip, time, username, password)
VALUES ('$ip', '$date', '$username', '$password')");
header('Location: http://www.plaxon.comyr.com/admin.php'); // Forwards the user to this URL
exit();
}
else // If login is unsuccessful forwards the user back to the index page with an error
{
$ip = $_SERVER['REMOTE_ADDR'];
$d = date('D');
$m = date('M');
$D = date('d');
$y = date('y');
$date = "$d,$D,$m,20$y ";
mysql_query("INSERT INTO failed_logins (ip, time, username, password)
VALUES ('$ip', '$date', '$username', '$password')");
header('Location: http://www.plaxon.comyr.com/login.php?error=true');
exit();
}
?>And this project upload script:
<link rel="stylesheet" type="text/css" href="global.css" />
<?php
$dbHost = '*';
$dbUser = '*';
$dbPass = '*';
$dbDatabase = '*''; // the database you put the table into.
$con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error());
mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database. Error: " . mysql_error());
?>
<?php
include "demo.html";
?>
<?php
session_start();
if(!isset($_SESSION['loggedin'])) {
// If the session 'loggedin' is NOT set forward the user back to the login form with the error set
header('Location: http://www.plaxon.comyr.com/error2.php');
exit(); // Otherwise show the rest of the page (admin section)
}
echo "<h1>Upload a Project: <a href=\"info.upload.php\">[+]</a></h1>";
$form = "<form action='upload.php' method='POST' enctype='multipart/form-data'>
<table>
<tr>
<td><input type='text' name='planetname'></td>
</tr>
<tr>
<td><input type='file' name='myfile'></td>
</tr>
<tr>
<td><input type='submit' name='submitbutton' value='Submit'></td>
</tr>
</table>
</form>";
if ($_POST['submitbutton'])
{
$ip = $_SERVER['REMOTE_ADDR'];
$planetname = $_POST['planetname'];
$name = $_FILES['myfile']['name'];
$type = $_FILES['myfile']['type'];
$size = $_FILES['myfile']['size'];
$tmpname = $_FILES['myfile']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));
$file = "$name";
if ($ext == ".sb")
{
if ($_FILES["myfile"]["error"] > 0)
{
echo "<p>Return Code: " . $_FILES["myfile"]["error"] . "</p><br />";
}
else
{
if (file_exists("planets/" . $_FILES["myfile"]["name"]))
{
echo "<p>Your planet " . $_FILES["myfile"]["name"] . " has already been shared. Please <a href=\"upload.php\">retry</a>.</p>";
}
else
{
$username = $_COOKIE["username"];
$uploads_dir = 'planets';
move_uploaded_file($tmpname, "$uploads_dir/$name");
mysql_query("INSERT INTO project_details (name, file, creator, creator_ip)
VALUES ('$planetname', '$file', '$username', '$ip')");
$link = mysql_connect("[removed by moderator]", "[removed by moderator]", "[removed by moderator]");
mysql_select_db("a5292800_users", $link);
$result = mysql_query("SELECT * FROM project_details", $link);
$num_rows = mysql_num_rows($result);
$planetid = mysql_query("SELECT LAST(projectid) FROM project_details");
echo "<p>Your planet has been shared! You can find your planet <a href=\"planets.php\">here</a>!</p>";
}
}
}
else
{
echo "You can only share SB planet files. Please <a href=\"upload.php\">retry</a>.";
}
}
else
{
echo $form;
}
?>It adds the project details to database, but it doesn't read the $_COOKIE["username"] part, and it just leaves that field blank? I search for PHP cookies and the $_COOKIE["cookie"] was there, but it doesn't work
Last edited by Paddle2See (2011-10-12 20:55:45)
Offline
bbbeb wrote:
Code:
$dbPass = *';1 error in #1
And which one is that code in again?
That's not the error. I just hightlighted the ' when I was putting in the *. Anyway, the error is in the second code.
Offline
Hmm, I don't see anything that's wrong. Try again and tell us the results?
Offline
I can't. There are no results. It just doesn't read the cookie, and adds a blank field to mysql databse.
Offline
couldn't you use $_SESSION variables?
http://www.w3schools.com/php/php_sessions.asp
Offline
rookwood101 wrote:
couldn't you use $_SESSION variables?
http://www.w3schools.com/php/php_sessions.asp
not working either.
Offline
have a look at this tutorial it's been very useful to me in the past, and I know it works, as I have used it.
Offline
WindowsExplorer wrote:
I can't. There are no results. It just doesn't read the cookie, and adds a blank field to mysql databse.
Well, I logged in and then looked at my cookies, and the cookie was there, then I did a test on my own website and it worked.
Also, I suggest saving files to just the /planets folder, you would need to make another folder for each user if you were to do that.
I suggest making a test file uploader, then add things until you find the broken piece of code.
Offline
rookwood101 wrote:
have a look at this tutorial it's been very useful to me in the past, and I know it works, as I have used it.
Great tutorial, but could you give me the link to the source file to that?
Offline
WindowsExplorer wrote:
rookwood101 wrote:
have a look at this tutorial it's been very useful to me in the past, and I know it works, as I have used it.
Great tutorial, but could you give me the link to the source file to that?
?
Offline
WindowsExplorer wrote:
WindowsExplorer wrote:
rookwood101 wrote:
have a look at this tutorial it's been very useful to me in the past, and I know it works, as I have used it.
Great tutorial, but could you give me the link to the source file to that?
?
I think reading the tutorial will help you better understand it. It does have the code somewhere in it, but the point is, if you read through it, you can digest the information better, and see what it's all for.
Offline
rookwood101 wrote:
WindowsExplorer wrote:
WindowsExplorer wrote:
Great tutorial, but could you give me the link to the source file to that??
I think reading the tutorial will help you better understand it. It does have the code somewhere in it, but the point is, if you read through it, you can digest the information better, and see what it's all for.
I know, but it says teh code will be at the end, and it isn't, so I was wondering if you knew.
Offline
WindowsExplorer wrote:
rookwood101 wrote:
WindowsExplorer wrote:
?I think reading the tutorial will help you better understand it. It does have the code somewhere in it, but the point is, if you read through it, you can digest the information better, and see what it's all for.
I know, but it says teh code will be at the end, and it isn't, so I was wondering if you knew.
If you read the whole thing, you won't need the code.
Anyhow, the code is spread throughout the tutorial, but a lot of it is on 'page 2' or page 3
Offline
rookwood101 wrote:
WindowsExplorer wrote:
rookwood101 wrote:
I think reading the tutorial will help you better understand it. It does have the code somewhere in it, but the point is, if you read through it, you can digest the information better, and see what it's all for.I know, but it says teh code will be at the end, and it isn't, so I was wondering if you knew.
If you read the whole thing, you won't need the code.
Anyhow, the code is spread throughout the tutorial, but a lot of it is on 'page 2' or page 3
Yes, but where is the login and signup form code?
Offline
rookwood101 wrote:
there not there?
Offline