Jump to content

header problem


corillo181

Recommended Posts

plus it meant with a if statement.. wich is this

[code]
<?php
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;
$_SESSION['level'] = $level;
mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'");

header('Location: ../home.php');
}
}
?>
[/code]
Link to comment
Share on other sites

no i still get the same warning this is the whole code


[code]
<?php
session_start();  // Start Session
include '../includes/db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
echo "Please enter your password and username! <br />";
include '../htmlforms/login.html';
exit();
}


// check if the user info validates the db
$sql = mysql_query("SELECT * FROM tra_users WHERE username='$username' AND password='$password' AND activated='yes'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;
$_SESSION['level'] = $level;
mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'");
header('Location: ../index.php');
exit();
}
} else {
echo "You could not be logged in! Either the username and password do not match or you have not validated your membership. Check your email to activate your name or make sure you have your username and password correct!<br />
Please try again!<br />";
include '../htmlforms/login.html';
}
?>

[/code]
Link to comment
Share on other sites

this si what i got in home.php to test the code you just saw and it doesn't work it keeps showing me log in..

[code]

<?php
session_start();
include_once'header.php';
include_once'db.php';

if(isset($username)){echo'<a href=mem/memberpage.php>My Info</a> | <a href="phpscript/logout.php">Logout</a>';
}else{
echo'<a href="phpscript/check_user.php">Login</a>';
}

?>


[/code]
Link to comment
Share on other sites

Read the error. Output was started by the db.php file on line 2. Since you are including another php, db.php, any output from that file is also part of the current page. Check the db.php file for echo statements or anything else that will output to the browser.

Ray
Link to comment
Share on other sites

this is the db.
[code]<?php
$host = 'mysql';
$user = 'user';
$pass = 'password';
$db_name = 'database';

$sqlconn = mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($db_name);
?>

[/code]

this is where user get the session
[code]<?php
/* Check User Script */
session_start();  // Start Session
include '../includes/db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
echo "Please enter your password and username! <br />";
include '../htmlforms/login.html';
exit();
}


// check if the user info validates the db
$sql = mysql_query("SELECT * FROM tra_users WHERE username='$username' AND password='$password' AND activated='yes'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;
$_SESSION['level'] = $level;
mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'");

header('Location: ../home.php');
}
} else {
echo "You could not be logged in! Either the username and password do not match or you have not validated your membership. Check your email to activate your name or make sure you have your username and password correct!<br />
Please try again!<br />";
include '../htmlforms/login.html';
}
?>
[/code]

and this is the home page.
[code]<?php
session_start();
include_once'includes/header.php';
include_once'includes/db.php';
?>
              <?php if(isset($username)){}else{?><tr>
            <td class="menu">::login:: </td>
          </tr><tr>
            <td bgcolor="#F0D5A2" class="tdbg"><?php include'htmlforms/login.html';?></td>
          </tr>
<?php   }?>
[/code]
Link to comment
Share on other sites

oh no the connection is no longer my problem.. my problem is the session is not passing to the next php..


as you can seen in home i got a if statement for someone who is signed in or is not.. but no matter if they sign in, the state stay false.. the session is not passin along to the next page as it should..
Link to comment
Share on other sites

Unless register_globals is on (in your php.ini file), which it likely isn't, you will need to specifically call the session variable "username" like $_SESSION['username'].  With register_globals off, $_SESSION['username'] is NOT the same as $username.

[code]<?php if($_SESSION['username']){}else{?>[/code]
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.