dpowt82802 2017-07-07 01:15
浏览 126

PHP - 用户链接

I have created a registration & login system, it is working properly. But, I only knew how to make a register & login system, I don't know how to make a link for every registered user

like : example.com/marwan
example.com/user/marwan

Here is my Register PHP Code :

<?php
error_reporting(0);
session_start();

if( isset($_SESSION['user_id']) ){
    header("Location: /");
}

require 'includes/database.php';

$message = '';

if(!empty($_POST['email']) && !empty($_POST['password'])):
    
    // Enter the new user in the database
    $sql = "INSERT INTO users (full_name, email, password, phone, country) VALUES (:full_name, :email, :password, :phone, :country)";
    $stmt = $conn->prepare($sql);

    $stmt->bindParam(':full_name', $_POST['full_name']);
    $stmt->bindParam(':email', $_POST['email']);
    $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
    $stmt->bindParam(':phone', $_POST['phone']);
    $stmt->bindParam(':country', $_POST['country']);

    if( $stmt->execute() ):
         header("Location: account-created.php");
    else:
        header("Location: failed.php");
    endif;

endif;

?>

And my Login code is :

<?php

session_start();

if( isset($_SESSION['user_id']) ){
    header("Location: /tregolapp/home");
}

require 'includes/database.php';

if(!empty($_POST['email']) && !empty($_POST['password'])):
    
    $records = $conn->prepare('SELECT id,email,password FROM users WHERE email = :email');
    $records->bindParam(':email', $_POST['email']);
    $records->execute();
    $results = $records->fetch(PDO::FETCH_ASSOC);

    $message = '';

    if(count($results) > 0 && password_verify($_POST['password'], $results['password']) ){

        $_SESSION['user_id'] = $results['id'];
        header("Location: /tregolapp/index.php");

    } else {
        header("Location: /tregolapp/failed");
    }

endif;

?>

Can someone help me please?

</div>
  • 写回答

1条回答 默认 最新

  • dpn4073 2017-07-07 02:50
    关注

    What is your purpose in giving each user their "own URL"?

    If you want each user to see their "own information" upon login, then after login go to a common "home page" while holding a session id. Use that id to pull "user specific" data from your database and display it on the "home page".

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度