PHP - 用户链接

时间:2017-07-07 01:15:50

标签: javascript php .htaccess url friendly-url

我创建了一个注册&登录系统,它正常工作。 但是,我只知道如何制作寄存器&登录系统,我不知道如何为每个注册用户建立链接

像: example.com/marwan
example.com/user/marwan

这是我的注册PHP代码:

<?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;

?>

我的登录代码是:

<?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;

?>

有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

您为每位用户提供“自己的网址”的目的是什么?

如果您希望每个用户在登录时看到他们的“自己的信息”,那么在登录后,在持有会话ID的同时转到共同的“主页”。使用该ID从数据库中提取“特定于用户”的数据并将其显示在“主页”上。