1

Here's a code:

 <?php
    require_once('./includes/connection.inc.php');
    session_start();

    // create database connection
    $connread = dbConnect('read', 'pdo');

    $connwrite = dbConnect('write', 'pdo');
    $komentari = 'SELECT * FROM komentariodobreni ORDER by komentarodobren_id DESC';

    $kontakt = 'SELECT poruka_id, ime, prezime, email, predmet, ordinacija, poruka,      DATE_FORMAT(datum, "%H:%i:%s %d. %b. %Y") 
     AS datum  FROM kontakt ORDER by poruka_id DESC';


    if (isset($_POST['slanje'])) {
    $potvrdiquery = "SELECT * FROM kontrola WHERE adminname='" . $_POST["adminname"] . "' and adminpassword = '". $_POST["adminpassword"]."'";
     $stmt = $connwrite->prepare($potvrdiquery )

    ;
      // bind the parameters and execute the statement  
      // execute and get number of affected rows
      $stmt->execute();
      $OK = $stmt->rowCount();


    foreach ($connread->query($potvrdiquery) as $row) {
    $_SESSION['adminid'] = $row['adminid'];
    $_SESSION["adminname"] = $row["adminname"];
    $_SESSION["adminpassword"] = $row["adminpassword"];
    } 
     header('Location: index.php');
    } 
?>

It works perfectly on my local, but when I upload it to Ipage or some other server it doesn't register session variables.

3 Answers3

2

Try rearranging session_start() like this:

<?php
  session_start();
  require_once('./includes/connection.inc.php');
  ...

and give it a try. Something may be happing (error or output) in connectoin.inc.php that is preventing session_start() from working correctly.

To help debug the problem add error output like this:

<?php
  session_start();
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  require_once('./includes/connection.inc.php');
  ...
John Hall
  • 78
  • 10
  • Okay, that would have prevented session_start() from working (if it occurred before session_start), but do the sessions work now? – John Hall Jan 23 '14 at 07:21
  • This link helped me to fix "header already sent" with session http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Mario Radomanana Jan 23 '14 at 07:24
  • Session doesn't work now and it's a full error.. Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosoraweb063/b2661/ipg.tipster365com/vizija/administrator/includes/headeradmin.html:102) in /hermes/bosoraweb063/b2661/ipg.tipster365com/vizija/administrator/index.php on line 8 – user3199298 Jan 23 '14 at 07:26
  • I changed my code to and now it gives me 500 internal server error. – user3199298 Jan 23 '14 at 07:43
  • I put ob_start(); ?> at the top and ob_flush(); ?> at the bottom of the page and this works me just fine now. – user3199298 Jan 23 '14 at 08:06
0

the page does not give you the default save path, you need to create one : or use root path to save any files or session_save_path

like this one : in the top of your code

session_save_path("/home/users/xxx/xxx/ipg.website/"); 
NOT :
session_save_path("/home/users/xxx/xxx/ipg.website/cgi-bin/tmp"); 

this path doesn't exist you need to create it.

Anton Balaniuc
  • 10,889
  • 1
  • 35
  • 53
Hakim Douib
  • 495
  • 1
  • 6
  • 13
0

Go to your server and open your php.ini file and find session.save_path word on your php.ini

you have got 3 results for this search like

session.save_path = "4;/hermes/phpsessions"

First two result comment (simply add ; first of line) and last one change path

session_save_path("/home/users/xxx/xxx/ipg.website/cgi-bin/tmp");

you have set your own server root path

My server is iPage so I have put my server session example, it's various to your server to server but the last path set as it is but set your own root path.