Jump to content

Archived

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

SilverNova

Why doesn't this work?! :\

Recommended Posts

http://lov3d.com/test.htm

They all show.. :\ I thought test 2 didnt but realised you went 1,3,4.. :P

See your sig - I had a brief look around  :)

Share this post


Link to post
Share on other sites
test1test3test4test5
Warning: Cannot modify header information - headers already sent by (output started at /home/lov3dco/public_html/test.php:3) in /home/lov3dco/public_html/test.php on line 24

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
yeah it is encoded with md5 in the table

the password field for the row is 098f6bcd4621d373cade4e832627b4f6.. which = "test"
there are other fields which just have blank entries so this shouldn't matter? like "email" for their email address etc.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
what about something in php.ini or htaccess that is making something output before the php page is even called from the server, that could be causing it.???

Share this post


Link to post
Share on other sites
[img]http://www.lov3d.com/test.png[/img]

That's what I have.

Also, why can't i see this warning message?!!!? I'm using FF, all I get after login is:

"test1test3test4test6" on the test.php page :\ ???

Share this post


Link to post
Share on other sites
browsers handling sessions differently I never heard of it, it has something to do with php.ini I would guess, for now give us your entire php.ini file, and anything you might have in your .htaccess page.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I changed it to:

[code]
<?php
session_start();
?>
<?php
echo "test1";
$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5
[/code]

..etc.

Still nothing..

Share this post


Link to post
Share on other sites
try what wildteen said for now, remove test1, the echo at the top, see if that fixes that part, then we can concentrate on the part below that to get the query to work.

Share this post


Link to post
Share on other sites
he was right, the error is changing based on teh location, I don't know the technicalities of how far it has to be, but I guess don't use echo's too close to the thing, just remove test1

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Ok, test.php now looks exactly like the above and returns a blank page..

Think businessman just put them in earlier to differentiate what was going on

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Change
[code=php:0]if($rows = mysql_num_rows($query)){[/code]

to
[code=php:0]if(mysql_num_rows($query) == '1'){[/code]

What does that produce?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.