im trying to get the username of the personal profile.
the url is example.com/theusername/index.php
the "theusername" i want to make into a variable.
How do i do that? i want the variable to be called "theusername"
so how do i make that into a variable? does anyone know?
with php
cause i want to plug each individual variabl in to the rest of the code so its unique and can show the users information of the profile being viewed. i dont know any other way?
does anyone else?
there will be more than one profile obviously.(with different usernames ex. example.com/difusername)
or is there a simpler way to plug in the users information to be written on the page?

Recommended Answers

All 10 Replies

Actually i didnt get u completely.
Anyway im just trying to help you
you can get username in many ways like using url (GET method), by creating session, cokkies etc or by getting it from database.
I prefer get or session to solve this.

If you are little more specific im sure there will be many more to help you.

I think what you are looking for is .htaccess files which is part of the apachie rewrite module. With .htaccess files, you can make fake urls that on the server side rewrite to the real file.

Example - real url:
site.com/index.php?username=cwarn23&id=blog
Fake url:
site.com/cwarn23/blog/

I would provide some code but I just need to know your real url is including what goes after the ? symbol.

Here is sample code for you.

file1.php
======

<?php
     $no=$_REQUEST["no"];
     $name=$_REQUEST["name"];

     echo "values - $no and $name";
?>

<br/>First Method

<form method="post" action="file1.php">
  No <input type="text" name="no"/>
  Name <input type="text" name="name"/>
  <br/><input type="submit" namd="cmd" value="Submit"/>
</form>

<br/>Second Method
 <a href="file1.php?no=100&name=Mr.X">Send</a>

It looks like you need htaccess code. This will make a rule on your webserver to call a server file (I'll call it user.php) with details from your url.

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

With this code in user.php username would be a GET variable you could use. Also, I would suggest making the URL's /user/username/ instead because lets say a user called themself index.php. Then this code would redirect that to their page. There is a way around this but I would require me to know every page on your site. It's just easier to use the /user/username structure.

I can't add anything to the stuff that is said about the .htaccess. But I got you a bit different.

You have an index file in a folder and you now need the name of the folder. This can be done as follows:

$uri=$REQUEST_URI;
$tmp=explode("/",$uri);
echo $tmp[$tmp.length()-2];

$REQUEST_URI returns the URL of your script including all folders relativ to root directory of your files. You can then find the folder where index.php is in.

Hope that helps.


PS When you try to do something similar to FB, where you can access a user via facebook.com/username I would do it as well as said before.

That is true sDJh, but wouldn't this mean that spank would have to create a folder and index.php for every user the registers? Still though, I like your solution (My other plan was using almost exactly your idea except the URL would be /user.php/username but that wasn't exactly what was required).

ok . i already have the registration script making the username the person choses as their own directory which is for me right now because my name is thissucks
example.com/thissucks
i also made an index file in each which is the profile.
i kind of understand the code...

$uri=$REQUEST_URI;
$tmp=explode("/",$uri);
echo $tmp[$tmp.length()-2];

but i dont know how to use it.
i need to be able to have a variable.

which has to be called $specific_user

and this variable has to CHANGE for every profile that is being viewd
example: on example.com/thissucks (or example.com/thissucks/index.php)
$specific_user has to equal the word thissucks

example: on example.com/heywhats-up (or example.com/heywhats-up/index.php)
$specific_user has to equal the word heywhats-up

so how do i get $specific_user to change for every profile bein viewed ?

cause i have to use $specific_user to look up the information in the mysql database so the specific user's info will be on their profile..

??? does anyone get what i dont know what todo?


&&&&
i used the above code just put it in the test file right with php tags around it and i got this error:

Fatal error: Call to undefined function length() in /home/peace/public_html/test1.php on line 14

Here is your code for the specific user variable. You must understand that for each user you need to create a new folder with an index.php containing the same code each time.

$tmp=explode("/",$REQUEST_URI);
$specific_user =  $tmp[count($tmp)-2];

ok so i put that code on the page and echoed the variable but nothing came up?
yeah i am fwriting the the page be the exact same code each time someone completes registration.

$pizza = $_SERVER['REQUEST_URI'];
$pieces = explode("/", $pizza);
echo [B]$pieces[1][/B];

this seems to work for me.
thanks for suggesting explode and request uri i looked it up finally and figured it out. it echos just the username of the url http://www.example.com/theusernamesXXX/
and for http://www.example.com/thusernsmehszxxxx/index.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.