Hi, I need help I am developing a website where users can access their profiles from url with name of user
example http://www.example.com/john
can any body help me? how to do this in php
plz send email to <EMAIL SNIPPED>
Hi, I need help I am developing a website where users can access their profiles from url with name of user
example http://www.example.com/john
can any body help me? how to do this in php
plz send email to <EMAIL SNIPPED>
Yes you can do it by reading Apache server documentation
hey
i think i know what your getting at..
so you want users to click on a link with, say there name, and it to take you to there profile?
If thats what you want il try my best to help out HOWEVER i reckon it'l be a load simpler if you did it as a variable so its like
<?php
$query = "SELECT * FROM profiles";
while ($data = mysql_fetch_array($pro_sql, MYSQL_ASSOC)) {
echo "<a href='profile.php?profile=$data[id]' class='profile_link'>";
echo "<div id='text'>";
echo "<b>Name:</b><i> $data[full_name]</I>";
echo "<br><b>Age:</b><i> $data[age]</I>";
echo "</div>";
echo "</a>";
}
?>
This would echo out each individuals name and age that was in my database :D
And say in another table you had there profile information (hobbies...ect) you could simply collect it by the url.
so its
www.example.com?profile=john
$id = $_REQUEST['profile'];
if (empty ($id)) {
echo "Sorry no member found under this id <br> <a href='home.php'> Please click here </a>";
}
else {
$query_profile = "SELECT * FROM profiles WHERE id = $id";
$query_send = MYSQL_QUERY($query_profile) or die ("Couldnt collect prolife data");
$user_data = mysql_fetch_array($query_send, MYSQL_ASSOC);
and that could collect all the data from there profiles
you could just print it out by: echo $user_data[nickname];
hope this helps, theres not much difference between the /john and the variable but its a lot easier to do it like the above.
Is that what you were looking for?
Hi,
This is what happens in drupal where the url like example.com/index.php?id=john is automatically converted into example.com/john. This actually is done by the server itself. so as suggested above, you should read the apache documentation on how to do it. Also, since all the processing will be done by your index.php file only you will have to incorporate all your logic there only. You can also refer the drupal.org for more information. You can see such a thing in action at http://tutorialindia.com/. All the subsequent folders do not exist on the server. However, since all the file configuration was done by the CMS itself I will not be able to explain how to do.
Hope this helps!
sorry, i think i misunderstood what you meant. agree with patna. Read the apache docs for help with that, not that hard to do but it is a bit difficult to explain .
again sorry
drupal never change setting automatically. u set the clean url option in drupal which make the url clean means
http://xyz.com/?profile=jhon
to
http://xyz.com/profile/jhon
I do not see the reason with all the programming fuzz to create appropriate URL with the long way, if simple configuration would be much easier to work and maintain.
There are two ways that I am aware of to do this.
The first would be to use apache's mod_rewrite, which will basically take domain.com/username and actually reference the url domain.com/?uname={username}.
There is a lot of available information via google or the like.
The other option would be to create a .htaccess file and use the following mod_rewrite code.
How this method works it to put something like this into your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This will force everything that is not a direct link to an existing file or directory to go to index.php
on index.php you can do something along the lines of:
$urlVars = explode('/',_SERVER["REQUEST_URI"]);
print_r($urlVars);
You should see that you have captured all the parts of the url. Using this method you have a tad more control over how you handle the urls, and you can change the methods without having to write any crazy mod_rewrite structures to handle a variable setup
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.