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

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

问题描述

我浏览过一些类似的帖子,
Facebook Like Custom个人资料网址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

一步,我认真

谢谢

推荐答案

不可能提供任何细节作为答案,因为您必须构建您自己的系统,并且有多种方法可以做到这一点。设计决策将需要根据您希望事情的工作方式和已经拥有的东西(他们将必须以某种方式一起工作)做出。

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 ,您的浏览器是ts重定向,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'] ,看看它是否存在,是否存在在用户表中查找别名网址为 $ _ 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.

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

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