Jump to content

Why doesn't this work?! :\


SilverNova

Recommended Posts

  • Replies 57
  • Created
  • Last Reply
As I said earlier there "something" above session_start();
also if all the tests are showing something isn't working right.
make sure
<?php
session_start();
?>
the <?php make sure it's at the top wall of the page, with nothing else above it.not html, or anything.
Something is being outputted on line 3 in test.php. As this where PHP has detected where the output has started:
[quote]Warning: Cannot modify header information - headers already sent by ([color=red][b]output started at /home/lov3dco/public_html/test.php:3[/b][/color]) in /home/lov3dco/public_html/test.php on line 24[/quote]
Note the bit in bold above. Thats the important bit you want to read.
I've never had to use php.ini before, all I know is that it's a global set of events etc

You're welcome to have a look - http://lov3d.com/php.ini

I presume it's in the right place, I took it from php.net after being told I should use (well, open) it. I don't seem to have a php.ini file elsewhere on my server unless i'm not looking in the right places.

It's not the .htaccess :\ - it's blank at the moment
maybe sometimes you can't have anything next to session_start();
good practice, try putting it in it's own section
<?php
session_start();
?>
<?php
everything else here

Try that, but I don't understand this, the reason itw as coming up blank is the username and password don't match, or one of the queries is wrong, I don't see what else can be causing this.
[code]session.cookie_lifetime = 0[/code]
increase that to 4 hours will allow the cookie to work after the browser is shut down.  There is nothing wrong with php.ini what about .htaccess
THe thing I would suggest is give me a little while if no one else can help.
I am leaving for like 2 hours.  Be back later.
The error isnt to do with the session anymore. But to do with the header redirect on line 24. From looking at the sreenie, you have output on line 3 - echo "testl"; Remove that otherwise the header function wont work (on line 24). Pleae read the error message correctly and that you understand it.
changed php.ini

[code]
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
[/code]

to

[code]
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 2400
[/code]

and test.php now looks like this after taking out the echo:

[code]
<?php
session_start();
?>
<?php

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }
echo "test3";
mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query
echo "test4";
if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";   

header('Location: ' . $page);
}else {
echo "test6";
    session_destroy();
}


?>[/code]

Still blank, apart from the echo's - http://lov3d.com/test.htm
You have a bunch of echos which is why your code is not working try this:
[code=php:0]<?php
session_start();

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }

mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query

if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";

header('Location: ' . $page);
}else {
    session_destroy();
}

?>[/code]
Okay so something is failing somewhere.

Chnage this:
[code]if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";

header('Location: ' . $page);
}else {
    session_destroy();
}[/code]
to this:
[code]if($rows = mysql_num_rows($query)){
    echo "login successful";
}else {
    echo "login failed";
}[/code]
Do you get anythink now?
I had a typo before, it should of been this:
[code]if(mysql_num_rows($query) == '1'){[/code]
Are you getting login successfull now?
If you are you can replace:
[code]if(mysql_num_rows($query) == '1'){
    echo "login successful";
}else {
    echo "login failed";
}[/code]
with:
[code]if(mysql_num_rows($query) == '1')
{
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var

    header('Location: index.php');
}
else
{
    session_destroy();

    echo "login failed, please try again";
}[/code]
Nope. sorry  :-\

[code]
<?php
session_start();

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }

mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query

if(mysql_num_rows($query) == '1'){
    echo "login successful";
}else {
    echo "login failed";
}

?>
[/code]

gives login failed

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.