使用/profile/name模板的PHP配置文件 [英] PHP Profiles using template of /profile/name

查看:231
本文介绍了使用/profile/name模板的PHP配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个需要配置文件系统的网站.

I am making a website that needs to have a profile system.

当前我已经设置好了,所以您转到/profile/namehere,配置文件将动态显示信息,但是,您必须手动复制粘贴这些配置文件并更改其名称才能工作.

Currently i have it setup so you go to /profile/namehere and the profile will show with the information dynamically, BUT ofcourse you have to manually copy paste these profiles and change the name for them to work.

我想要这样,以便在这种情况下提交表单时,您输入名称,然后按Submit,将其添加到我自己已经完成的数据库中,并自动创建一个配置文件.

I want it so that when a form is submitted in this case you enter name and press submit they are added to the database which I already have done myself and a profile is automatically made.

我对此进行了一些研究,并得出一个事实,我需要制作一个控制器或配置文件模板以将信息调用到其中,但是我已经做了一些这样的事情,只是我不确定并且无法找到在线上有关如何使用 /profile/namehere/

I have researched this a little and come up with the fact that I need to make a controller or profile template that will call the information into, but i have already sort of done this, it is just i am unsure and cannot find any documentation online of how to do it specifically with /profile/namehere/

非常感谢任何帮助或代码示例,非常感谢!

Any help would be extremely appreciated or code examples, thanks so much!

我正在使用的数据库是MYSQL,尽管当我处理它时将迁移到PDO,但是目前的配置文件可以在MYSQL中.我当前的页面代码如下所示:

The database i am using is MYSQL although i will be migrating to PDO when i get round to it, but the profiles for now can be in MYSQL. my current page code looks something like this:

标题和元标记通过配置文件/api显示. 页面内容回显为从数据库中选择的内容,我正在将$row['var'];select语句一起使用来访问数据库.

Title and meta tags are shown via config file / api. Page content is echoed for the things being selected from database i am using $row['var']; with the select statement to access database.

在此当前状态下,将配置文件复制并粘贴,并将名称更改为用户名,即已完成配置文件,我要这样做,因此当您提交表单以使用户成为名称时,它将自动创建可访问的配置文件在/profile/namehere/,而不是手动创建.

At this current state a profile is copied and pasted with the name changed to the users name and that is the profile done, i want it so when you submit form to make users name it will automatically create the profile which can be accessed at /profile/namehere/ rather than manual creation.

从本质上讲, -表格已提交 -用户访问次数/个人资料/名称 -抓取模板,并从数据库中动态调用信息. *

Essentially, - Form submitted - User visits /profile/name - Template is grabbed and information is called from database dynamically. *

推荐答案

您的问题有点宽泛.所以我会尽我所能回答.

You question is a bit broad. So I'll answer as mush as I can understand.

  1. 要访问/profile/user,您必须使用URL重写.您必须启用Apache的mod_rewrite(如果它是您的网络服务器).然后,您必须在.htaccess文件中定义规则.

  1. To access to /profile/user, you have to use URL-rewriting. You have to enable the mod_rewrite of Apache (if it's your webserver). Then you have to define rules in a .htaccess file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^profile/(\w+)$ profile.php?user=$1
</IfModule>

因此,浏览到http://host/profile/namehere将使用profile.php,而$_GET['user']将用"namehere"定义.

So, browsing to http://host/profile/namehere will use profile.php and $_GET['user'] will be defined with "namehere".

profile/namehere页面中显示信息(profile.php未经测试):

Display informations in profile/namehere page (profile.php untested):

<?php
if (!isset($_GET['user']))
{
    // Error: Fall in error 404, or display error, or ...
    header("HTTP/1.1 404 Not Found");
    exit(0);
}

$username = $_GET['user'];

// connect database using PDO
$pdo = new PDO('mysql:dbname=DBNAME;host=localhost' , 'DBUSER', 'DBPASS') ;

$sth = $pdo->prepare("select * from profile_table where username=:username") ;
if (!$sth) { /* Error */ die ; }
$sth->execute([':username' => $username]) ;
$result = $sth->fetch(PDO::FETCH_OBJ) ;
if (!$result) { /* Error */ die ; }

// display informations using template
header("Content-Type: text/html; charset=utf-8") ;
include("template.php") ;
exit();

  • 模板示例:

  • Template example :

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title><?php echo $result->name ?></title>
    </head>
    <body>
        <p><?php echo $result->info1 ?></p>
        <p><?php echo $result->info2 ?></p>
        <p><?php echo $result->info3 ?></p>
    </body>
    </html>
    

  • 这篇关于使用/profile/name模板的PHP配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆