title: How to login with a socket
body: <p>I have a site lets call it <strong>phones.names.xol.com</strong>.
  Using the website I have the problem to login</p>
  <blockquote>
  <p>There I have create a <strong>database</strong> with a name <strong>backe</strong>.The password
  is <strong>1234</strong>. (It is ok to share the password ). On that database(backe) I have a table name
  it <strong>users</strong>. My socket is <strong>'home/tiger/mysql/run/mysql.sock'.</strong></p>
  </blockquote>
  <p>Using localhost - all works fine</p>
  <blockquote>
  <p>I have create on <strong>localhost</strong> , a database name backe with a table name users.The user is root ,password empty.I can login in that page with not a problem.</p>
  </blockquote>
  <p>This is the connection.php.It is located inside a file named b,so b/connection.php</p>
  <pre><code> &lt;?php
      
      
      $host='phones.names.xol.com';
      $db = 'backe';
      
      
      $user='root';
      $pass='1234';
      
      
      
      if(gethostname()=='phones.names.xol.com') {
          $mysqli = new mysqli($host, $user, $pass, $db,null,'home/tiger/mysql/run/mysql.sock');
      } else {
              $mysqli = new mysqli($host, $user, $pass, $db);
      }
      
      if ($mysqli-&gt;connect_errno) {
          echo &quot;Failed to connect to MySQL: (&quot; . 
          $mysqli-&gt;connect_errno . &quot;) &quot; . $mysqli-&gt;connect_error;
      }
  
  
  // Check connection
      if (!$mysqli) {
        die(&quot;Connection failed: &quot; . mysqli_connect_error());
      }{
      echo &quot;Connected successfully to database&quot;;
      }
      
      
      
      
      
      
      function check_login($mysqli)
  
  {
  
  if(isset($_SESSION['user_id']))
  {
  
  $id = $_SESSION['user_id'];
  $query = &quot;select * from users where user_id = '$id' limit 1&quot;;
  $result = mysqli_query($mysqli,$query);
  
  if($result &amp;&amp; mysqli_num_rows($result) &gt; 0){
  $user_data = mysqli_fetch_assoc($result);
  return $user_data;
  
  
  
  }
  
  
  } 
  }
  function random_num($length){
      $text = &quot; &quot;;
      if($length &lt; 5 ){
          $length = 5;
      }
      $len = rand(4,$length);
      for ($i=0; $i &lt; $len; $i++){
          $text .= rand(0,9);
          
  }
  return $text;
  }
      
      ?&gt;
  </code></pre>
  <p>In the login.php .I give the basic parts of codes I have</p>
  <pre><code>&lt;?php
  
  
  
  
  
  session_start();
  include(&quot;b/connection.php&quot;);
  
  if($_SERVER['REQUEST_METHOD'] == &quot;POST&quot;)
  {
      
      //something was posted
      $user_name = $_POST['user_name'];
      $password = $_POST['password'];
      if(!empty($user_name) &amp;&amp; !empty($password) &amp;&amp; !is_numeric($user_name))
      {
          
      $user_id = random_num(20);  
          $query = &quot;insert into users ( user_id,user_name,password) values ('$user_id','$user_name','$password')&quot;;
      
      mysqli_query($mysqli, $query);
      header(&quot;Location: index.html&quot;);
      die;
      }
      else{
          echo &quot;Please enter some valid information!&quot;;
      }
      
  }
  
  
  
  
  
  
  ?&gt; 
  </code></pre>
  <blockquote>
  <p>and this is the form of that code as</p>
  </blockquote>
  <pre><code>&lt;form method=&quot;post&quot; &gt;
  Username: &lt;input type=&quot;text&quot; name=&quot;user_name&quot;/&gt;
  &lt;br/&gt;
  Password: &lt;input type=&quot;password&quot; name=&quot;password&quot; /&gt;
  &lt;br/&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Login&quot;/&gt;&lt;br&gt;&lt;br&gt;
  
  
  &lt;/form&gt;
  </code></pre>
  <p>How can I make it work on a link ( lets say https:\www.phones.names.xol.com) as it works on localhost?I have been trying for hours to do it but I didn't managed to.The database are good the problem is I think in b/connection.php.</p>