开发者

Issue creating "custom" user URLs

I am running into the following issue:

Our members have a desire for personalized sites directly from our primary domain in the form of http://www.example.com/membername. I am looking at possibly solutions in two ways but neither are ideal (will be explained below).

Method 1 - ?Member=

In this method, I simply create a custom URL and store the information in the member's database profile. For example: if I want my "custom" URL to be jm4, for a consumer to visit my site, they must type in http://www.example.com开发者_运维百科?Member=jm4.

The site, of course, does a $_GET['Member'] to lookup the member information, stores the primary data in Session from the index page, then redirects to a homepage. The consumer no longer sees the membername in the URL but instead sees all the page names for www.example.com as if they simply visited the parent domain to start (each member's page has custom information however).

While this method works it presents the following problems:

  • The URL is not nearly as easy as /jm4 and any errors typing out the wildcard ?Members= will result in page error. Also, This method keeps that particular member's information in session (which is necessary browing from page to page on that particular member domain) and prevents somebody from simply typing http://www.example.com?Member=name2 to visit another site without clearing their session or closing the browser.

Method 2 - /membername

While the preferred method, currently the only way we know how to create is to manually generate an index file in a subfolder, redirect to the primary index then allow the consumer to view the member's personal site.

For example, if I visit www.example.com/jm4, I am hitting the /jm4 folder which contains index.php. Within this file simply contains:

<?php
session_start();
ob_start();

$_SESSION['AgentNumber'] = "779562";
header("Location: ../index.php");
exit;
?>

the primary index recognizes this with:

<?php
session_start();
ob_start();

if ($_SESSION['MemberNumber'] == NULL) {
     header("Location:ac/");
     exit;
}

$conn = mysql_connect("localhost", "USER", "PW");
mysql_select_db("DB",$conn);

$sql = "SELECT * FROM table WHERE MemberNumber = $_SESSION[MemberNumber]";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
    $_SESSION['MemberName'] = $newArray['MemberName'];
    $_SESSION['MemberPhone'] = $newArray['MemberPhone'];
    $_SESSION['MemberMobile'] = $newArray['MemberMobile'];
    $_SESSION['MemberFax'] = $newArray['MemberFax'];
    $_SESSION['MemberEmail'] = $newArray['MemberEmail'];
    $_SESSION['MemberAddress'] = $newArray['MemberAddress'];
    $_SESSION['MemberCity'] = $newArray['MemberCity'];
    $_SESSION['MemberState'] = $newArray['MemberState'];
    $_SESSION['MemberZip'] = $newArray['MemberZip'];
    $_SESSION['MemberAltName'] = $newArray['MemberAltName'];
}
mysql_close($conn);
header("Location: home/");
exit;
?>

We would certainly prefer to use the second method in terms of 'ease' for the member but keep running into the following issues:

  1. We are forced to manually create a sub-folder and unique index.php file for each new member we onboard
  2. While the above probably could be automated (when new member creates profile, automatically generate php file and folder) but this is more complicated and we don't want to have 3000 subfolders on the primary domain.

Has anybody run into similar issues? If so, how did you go about solving it? What would you recommend based on my details above? Any advice is appreciated.

Also - using as subdomain (membername.example.com) is not preferred because our current SSL does not allow for wildcards.

EDIT 1 - EXISTING .HTACCESS FILE My existing .htaccess file on the site looks like this for reference:

ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(.*)$ /?Member=$1 [L]


You can do your prefered method by just adding some lines to the .htaccess in your root directory:

This site should get you started Or this one


If you are using apache, then you could use mod_rewrite to change urls like http://host/membername to http://host/memberpage.php?name=membername.


You could use this in a .htaccess file for your second method. It will rewrite http://yoursite.com/membername to http://yoursite.com/?Member=membername

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /?Member=$1 [L]
</IfModule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜