| | |
how do i get a variable from a regular ol url?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 281
Reputation:
Solved Threads: 2
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?
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?
Last edited by Ezzaral; Jun 11th, 2009 at 2:36 pm. Reason: Changed to non-promotional url.
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.
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.
Last edited by danishbacker; May 25th, 2009 at 3:11 am.
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.
I would provide some code but I just need to know your real url is including what goes after the ? symbol.
PHP Syntax (Toggle Plain Text)
Example - real url: site.com/index.php?username=cwarn23&id=blog Fake url: site.com/cwarn23/blog/
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Here is sample code for you.
file1.php
======
file1.php
======
PHP Syntax (Toggle Plain Text)
<?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>
Failure is not fatal, but failure to change might be. - John Wooden
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.
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.
PHP Syntax (Toggle Plain Text)
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.
Last edited by FlashCreations; May 25th, 2009 at 11:38 am.
•
•
Join Date: Aug 2005
Posts: 150
Reputation:
Solved Threads: 13
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:
$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.
You have an index file in a folder and you now need the name of the folder. This can be done as follows:
PHP Syntax (Toggle Plain Text)
$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).
•
•
Join Date: Apr 2009
Posts: 281
Reputation:
Solved Threads: 2
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...
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
example.com/thissucks
i also made an index file in each which is the profile.
i kind of understand the code...
PHP Syntax (Toggle Plain Text)
$uri=$REQUEST_URI; $tmp=explode("/",$uri); echo $tmp[$tmp.length()-2];
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
Last edited by Ezzaral; Jun 11th, 2009 at 2:38 pm. Reason: Changed to non-promotional url.
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.
PHP Syntax (Toggle Plain Text)
$tmp=explode("/",$REQUEST_URI); $specific_user = $tmp[count($tmp)-2];
![]() |
Similar Threads
- Why server variable "http_referer" is empty first time? (ASP)
- For loop not bringing variable back properly (Shell Scripting)
- How to return a php variable, to a html file which can be use in html file as javascr (PHP)
- PHP Variable in mySQL query (PHP)
- Boot up problem (Windows NT / 2000 / XP)
- define variable (C)
- Variables in the URL - and how to get them (HTML and CSS)
- php url code? (PHP)
- setting variable using url (JavaScript / DHTML / AJAX)
- setting variable using url (ASP)
Other Threads in the PHP Forum
- Previous Thread: OsCommerce: I cannot add products via the admin console
- Next Thread: editing
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube






