Jump to content

Why doesn't this work?! :\


SilverNova

Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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.
Link to comment
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
Link to comment
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.
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
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]
Link to comment
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?
Link to comment
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]
Link to comment
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
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.