Jump to content

I want to start a website that users can register and login. and after logging in I want users to be able to submit input-fields that I specify and get all the users login details (to know which user submitted the form to the database) only registered users, and none registered users can't get to the submission input fields.

 

how do I start this where to search?? most of the Youtube videos only do a register and login tutorial without counting how to give certain features to the logged-in users. 

The language I want to use is PHP.

Thanks,

AMD Ryzen 1700x

Asus Crosshair VI Hero

GTX 1070

16gb RAM 2333Mhz

500gb Samsung SSD

Windows 10 & Linux

 

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/
Share on other sites

Link to post
Share on other sites

Logging in, register and posting inputs are literally all the same thing the only different is how the handle the requests. 

 

I suggest you learn php rather than learn what you want to do in it from what I remember w3schools has a good php and MySQL tutorials. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/#findComment-10427395
Share on other sites

Link to post
Share on other sites

Advice to watch some good series of tutorials that teaches various things about PHP, then once you've learned some of the basic you probably find ways to do this without anyone teaching you a specific solution :)

I've used Lynda which is paid, but found it very good.

 

Anyways if you have video's that explains Login and Register parts i assume you are a bit familiar with PHP Sessions

They get normally used to let a user login, and when a user successfully authenticated then you write like the username to the session.

 

Assuming you still do crappy code like we all that you can simply do as follow.

 

Above the page before you load anything else. you put a IF statement which checks if a $_SESSION["username"] is active and not NULL.

If it is null then simply redirect to a login page

 

 

Lets say you've got a Admin page, then in the top op the page paste the code or include a php file with the code

Example

 

//Always start a sessions when working with authentication.
session_start();
//If username is not set
if(!$_SESSION['username']) {
  //Redirect to login.php
  header("location:login.php"); 
  die(); 
}

 

Quote or mention me if not feel ignored 

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/#findComment-10436172
Share on other sites

Link to post
Share on other sites

login in page, just stole my login page uses bootstrap
 

<form action="api.php" method="POST" class="form-horizontal">
<!-- username -->
  <div class="form-group">
      <label for="title" class="col-sm-3 control-label">Username</label>
      <div class="col-sm-6">
          <input type="text" name="username" class="form-control">
      </div>
  </div>
                <!-- upassword -->
  <div class="form-group">
    <label for="password" class="col-sm-3 control-label">Password</label>
    <div class="col-sm-6">
      <input type="password" name="password" class="form-control">
    </div>
  </div>
  <!-- Add Post Button -->
  <div class="form-group">
    <div class="col-sm-offset-3 col-sm-6">
      <button type="submit" name='login' class="btn btn-default">
        <i class="fa fa-plus">login</i>
      </button>
    </div>
  </div>
</form>


api.php

//start a session
session_start();
<?php
// class handles DB connection and queries
class db {
  private static $handle;
  public static function connect($host, $username, $password, $db){
  self::$handle = new PDO("mysql:host={$host};dbname={$db}", $username, $password);
  self::$handle->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
  }
  public static function query($sql, $args=null){
  $sth = self::$handle->prepare($sql);
  $sth->execute($args);
  return $sth;
  }
}
//class handles login
class login
{
  public static function log($username, $password){
    $login = db::query("SELECT * FROM users WHERE username=:u LIMIT 1", array(":u" => $username));
    if($login->rowCount() > 0){
      $row = $login->fetch(PDO::FETCH_ASSOC);
      if(password_verify($password, $row['password']))
        $_SESSION['username'] = $row['username'];
        return true;
      }else{
        return false;
      }
  }
}
//connect to DB
db::connect("127.0.0.1", "username", "password", "database");

//check if login form was passed
if(isset($_POST['login'])){
  $username = $_POST['username'];
  $password = $_POST['password'];
  $check = login::log($username, $password);
  if($check){
    header( 'Location: index.php' );
    die();
  }else{
    echo '<strong>Error!</strong> Login details are incorrect.';
  }
  header( 'Location: login.php' );
}


then use @Cruorzy code on protected pages

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/#findComment-10436304
Share on other sites

Link to post
Share on other sites

16 hours ago, Cruorzy said:

Advice to watch some good series of tutorials that teaches various things about PHP, then once you've learned some of the basic you probably find ways to do this without anyone teaching you a specific solution :)

I've used Lynda which is paid, but found it very good.

 

Anyways if you have video's that explains Login and Register parts i assume you are a bit familiar with PHP Sessions

They get normally used to let a user login, and when a user successfully authenticated then you write like the username to the session.

 

Assuming you still do crappy code like we all that you can simply do as follow.

 

Above the page before you load anything else. you put a IF statement which checks if a $_SESSION["username"] is active and not NULL.

If it is null then simply redirect to a login page

 

 

Lets say you've got a Admin page, then in the top op the page paste the code or include a php file with the code

Example

 


//Always start a sessions when working with authentication.
session_start();
//If username is not set
if(!$_SESSION['username']) {
  //Redirect to login.php
  header("location:login.php"); 
  die(); 
}

 

Thanks for responding yes I'm a little bit familiar with all the stuff but I still don't know how to use it. is there any way to contact you through chat of Skype. I would really appreciate it.

 

Thanks again.

AMD Ryzen 1700x

Asus Crosshair VI Hero

GTX 1070

16gb RAM 2333Mhz

500gb Samsung SSD

Windows 10 & Linux

 

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/#findComment-10439066
Share on other sites

Link to post
Share on other sites

9 hours ago, Pavilion said:

Thanks for responding yes I'm a little bit familiar with all the stuff but I still don't know how to use it. is there any way to contact you through chat of Skype. I would really appreciate it.

 

Thanks again.

You can always ask on discord,

Just PM

Quote or mention me if not feel ignored 

Link to comment
https://linustechtips.com/topic/834211-where-to-start-php/#findComment-10440062
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×