自己网站的自定义个人资料 URL,已通过各种帖子..! [英] Custom profile URL for own site, been though various posts..!

查看:19
本文介绍了自己网站的自定义个人资料 URL,已通过各种帖子..!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过一些类似的帖子,Facebook Like 自定义个人资料 URL PHP

I've been through a few similar posts, Facebook Like Custom Profile URL PHP

自定义 URL/Apache URL 重写

但它仍然不清楚,实际的方法/过程不可用..伙计们,多一点指导会做很多..

But its still not clear, the actual method/process is not available.. Guys , little more guidance would do a lot..

我想在这里提出问题:

  1. 用户应该有机会决定他们的网址是什么,就像 fb、twitter 一样例如:www.facebook.com/harry.inaction

  1. Users should have a chance to decide what is their url, Just like in case of fb, twitter for example: www.facebook.com/harry.inaction

我为此使用了 linux、apache、mysql、php 环境.

I am using the linux, apache, mysql, php environment for this.

根据用户加入时自动创建的用户 ID 来识别用户

Users are identified based on their user id's which get created automatically when they join in

而且我在第一步就失败了,严重的是我不知道如何开始.

And I fail at the very first step, seriously I don't know get started.

谢谢

推荐答案

不可能提供任何细节作为答案,因为您必须构建您的这个系统,而且还有更多不是一种方法.设计决策需要根据您希望事物的工作方式以及您已经拥有的方式(它们必须以某种方式协同工作)来做出.

It's going to be impossible to put any details as an answer because you've got to build this system of yours and there's more than one way to do it. Design decisions will need to be made based on the way you want things to work and what you already have (they're going to have to work together in some way).

假设您已经有一个用于创建用户的系统(听起来像您这样做)并且您已经有一个用于查看个人资料的系统.您需要扩展此系统,以便在数据库的用户表中存储一个额外的my_vanity_url"字段.该字段必须是唯一的.当用户编辑他们的个人资料时,他们可以选择将其更改为他们想要的任何内容(为简单起见,将其仅限于字母、数字和破折号).

Say you've already got a system for creating users (and it sounds like you do) and you already have a system for viewing profiles. You'll need to extend this system so that you store an extra "my_vanity_url" field in your user table in your database. This field needs to be unique. When a user edits their profile, they have the option of changing this to whatever they want (limiting it to only letters and numbers and dashes for simplicity).

接下来,当你显示这个配置文件时,假设它是通过/profile.php,你的代码需要检查一些事情.

Next, when you display this profile, say it is via /profile.php, your code needs to check a few things.

  1. 首先它需要检查它是如何调用的,查看 $_SERVER['REQUEST_URI'] 你可以看到 /user/some-vanity-name/profile.php?u=1234.
  2. 如果是后者,则需要重定向浏览器,进行数据库查找以查看 user_id 1234 的用户是谁.
  3. 从该用户的数据库中拉出my_vanity_url"列并将浏览器重定向到/user/my_vanity_url_value(用该列的值替换my_vanity_url_value).
  1. First it needs to check how it's called, looking at $_SERVER['REQUEST_URI'] you can see either /user/some-vanity-name or /profile.php?u=1234.
  2. If it's the latter, you need to redirect the browser, do a database lookup to see who the user with user_id 1234 is.
  3. Pull the "my_vanity_url" column out of the database for this user and redirect the browser to /user/my_vanity_url_value (replacing my_vanity_url_value with the value of that column).

现在,如果您转到 http://your.domain.com/profile.php?u=1234,您的浏览器将被重定向,并且 URL 地址栏会显示 http://your.domian.com/user/my_name.

So now, if you go to http://your.domain.com/profile.php?u=1234, your browser gets redirected and the URL address bar will say http://your.domian.com/user/my_name.

接下来,您需要能够使用该唯一名称并将其转回旧的丑陋的个人资料页面.这里需要做两件事:

Next, you need to be able to take that unique name and turn it back into the old ugly looking profile page. Two things need to happen here:

  1. 您需要再次扩展您的 profile.php 以采用可选的虚名而不是 user_id
  2. 您需要使用 mod_rewrite 在内部将虚名路由到 /profile.php
  1. You need to extend your profile.php once more to take an optional vanity name as opposed to a user_id
  2. You need to use mod_rewrite to internally route vanity names to /profile.php

首先,您只需查找不同的 $_GET[] 参数,而不是针对 user_id 的任何参数.假设它被称为 name:所以看看 $_GET['name'],看看它是否存在,如果它确实在用户表中查找虚 url 名称为的用户$_GET['name'].返回该用户的个人资料.

For the first thing, you simply look for a different $_GET[] parameter instead of whatever it is for a user_id. Say it's called name: so look at $_GET['name'], see if it exists, if it does lookup the user in the user table whose vanity url name is $_GET['name']. Return the profile of that user.

第二件事,您只需要将其放在文档根目录中 htaccess 文件中的适当位置:

For the second thing, you just need to put this in the appropriate place in your htaccess file in your document root:

RewriteEngine On
RewriteRule ^/?user/([A-Za-z0-9-]+)/?$ /profile.php?name=$1 [L]

<小时>

这只是一个关于如何实现这样的东西的例子.它可能完全不适用于你所拥有的,但它应该让你知道你需要做什么.


This is just an example for how to implement something like this. It may be completely inapplicable for what you have, but it should give you an idea of what you need to do.

这篇关于自己网站的自定义个人资料 URL,已通过各种帖子..!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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