Need to convert the URL virtually in PHP

Discussion in 'PHP' started by yoursanjay, Jan 16, 2010.

  1. #1

    Hello,

    I have developed a program in PHP & MySQL and there is a membership section. After the member login the page goes to
    http://www.mydomain.com/member.php . All the functions are working properly. In my membership program user name of every user is unique. The issue is that at this moment I wish to show the URL of the member page after login as follows:
    http://www.mydomain.com/bluebell/member.php .
    Here bluebell is the user name. So, the main thing I need that the member.php page will be shown after the respective member's username (/member/) in the URL.

    Is there any procedure that the member.php page wiil open but in the URL the above format will be shown. As, the full project has already been completed and I am very confused if I have to change the codes a lot or not.

    I am not familiar with MOD rewrite function.

    Please suggest and if possible provide me a sample code of this type URL conversion.

    Thanks...

     
    yoursanjay, Jan 16, 2010 IP
  2. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i think this will be cool
    /member/usename
     
    astkboy2008, Jan 16, 2010 IP
  3. tom210

    tom210 Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Easiest way to do this is using mod rewrite in htaccess file
     
    tom210, Jan 16, 2010 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    if you want to do it on an application level, you can use parse_url, and then some logic to get the member name. Make sure to sanitise the url to protect against any injection attack.
     
    jestep, Jan 16, 2010 IP
  5. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you wanted to get around the mod_rewrite (or the parse_url technique that jestep suggested), you could do something similar to:

    http://www.mydomain.com/member.php?name=bluebell
    Code (markup):
    Or even if you wanted to use mod_rewrite with that, you could rewrite that url format above to this:

    http://www.mydomain.com/member/bluebell
    Code (markup):
    --------

    Now mentioning the parse_url concept, you still need to use mod_rewrite to make it work. (unless you did member.php/bluebell)
     
    Last edited: Jan 17, 2010
    CodedCaffeine, Jan 17, 2010 IP