0

hai i have error in session_start();. i was refer our site but i will not fix that error. my second question is what is whitespace in php, how to clear that ?.

Note: This code working in localhost this is my code

<?php
  session_start();
  $message = "";
  if (count($_POST) > 0) {
      $conn = mysql_connect("198.33.225.54:3306", "test", "test");
      mysql_select_db("test", $conn);
      $result = mysql_query("SELECT * FROM candidate WHERE user_name='" . $_POST["userName"] . "' and pass_word = '" . $_POST["password"] . "'");
      $row    = mysql_fetch_array($result);
      if (is_array($row)) {
          $_SESSION["user_id"]   = $row['id'];
          $_SESSION["user_name"] = $row['user_name'];
      } else {
          $message = "<font color='#FF0000'>Invalid Username or Password!</font>";
      }
  }
  if (isset($_SESSION["user_id"])) {
      header("Location:profile.php");
  }
?> 
Raja
  • 600
  • 6
  • 15
Nisha Chinnapa
  • 97
  • 1
  • 2
  • 8

2 Answers2

0
  1. Make sure You start file with <? and do not put any signs before.
  2. Some text editors add UTF-8 marks that are invisible in Windows, but are recognized by linux system. Use Eclipse and set coding to UTF-8 in file properties.
  3. Whitespace is a space, tab, breakline or any other mark that is recognized by text editor and not presented to user.
  • Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at G:\PleskVhosts\globaledudeals.com\translatemasters\list.php:1) in G:\PleskVhosts\globaledudeals.com\translatemasters\list.php on line 2 – Nisha Chinnapa Apr 03 '15 at 09:34
0

1) Write ob_start(); at the top of your code,i.e., after <?php and before session_start();

Also, write ob_flush(); at the end of the code,i.e., before ?>

This will help you for the warning, Warning: session_start()....

2) Whitespace is any unwanted space in the code, especially before and after php tags <?php and ?>