-2

this is a repost becuase i figured out how to post my code. please dont get mad admins! It seems that sessions work when I set them for an instant, and then they are destroyed. Here is my phpinfo page, can anyone see the problem? I don't have access to the phpini file. Can you check my cookie settings and tell me if I can use those instead? http://cksgrill.net/phpinfo.php

[code]

<!DOCTYPE html>
<script src="/javascript/header.js"></script>
<?

session_set_cookie_params(3000); 
session_start();
ob_start();
ini_set('session.gc_maxlifetime', 6 * 60 * 60);
$session_expiration = time() + 3600 * 24 * 2;
if((($_POST['name'])and($_POST['password']))or(($_POST['name']!="")and($_POST['password']!="")))
{
    $_SESSION['name']=$_POST['name'];
    $_SESSION['password']=$_POST['password'];
    echo $_SESSION['name'];
    echo $_POST['name'];
    echo $_SESSION['password'];
    echo $_POST['password'];
}


// redifine variables for different server
require_once "mysqlconfig.php";  
require_once "textprep.php";  

// connect to database
global $connection;
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); 
if (!$connection)
{
    die("Database connection failed: " . mysql_error());
}

// select database
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select)
{
    die("Database selection failed: " . mysql_error());
}

//check if logged in
$result = mysql_query("SELECT * FROM admin");
if (!$result)
{
    die("Database query failed: " . mysql_error());
}

// get table names as mysql feedback
$i=0;
while ($row = mysql_fetch_array($result)) 
{
    $name[$i]=$row['name'];
    $password[$i]=$row['password'];
    $rank[$i]=$row['rank'];

    //echo "\$name[$i]=".$row['name'];
    //echo "\$password[$i]=".$row['password'];
    //echo "\$rank[$i]=".$row['rank'];

    $i++;
}

//check if logged in
$log=false;
for($j=0;$j<$i;$j++)
{
    //echo "<p>(".$name[$j]."==".$_SESSION['name'].")and(".$password[$j]."==".$_SESSION['password'].")</p>";
    if(($name[$j]==$_SESSION['name'])and($password[$j]==$_SESSION['password']))
    {
        $log=true;
        echo logged." ".$log;
    }
}
if($log==true)
{
[/code]
  • `session_start();` must be before any output – bansi Nov 28 '13 at 06:31
  • `session.gc_maxlifetime` is not a good way.You can find more on this post http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes?lq=1 – 웃웃웃웃웃 Nov 28 '13 at 06:31
  • You asked this just 40 minutes ago. Spamming [so] with the same question will get you a question ban. See [help centre](http://stackoverflow.com/help/no-one-answers) –  Nov 28 '13 at 06:31
  • i know im sorry but people stoped answering because i didnt post my code. i am trying 4 different things suggested by people which is why i have session.gc_maxlifetime. im grasping at straws here please help! – user3044508 Nov 28 '13 at 06:40

1 Answers1

0

you have to start session before anything output

session_start();
Developerium
  • 7,155
  • 5
  • 36
  • 56