how do i get a variable from a regular ol url?

Thread Solved

Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

how do i get a variable from a regular ol url?

 
0
  #1
May 25th, 2009
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?
Last edited by Ezzaral; Jun 11th, 2009 at 2:36 pm. Reason: Changed to non-promotional url.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

Re: how do i get a variable from a regular ol url?

 
0
  #2
May 25th, 2009
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.
Last edited by danishbacker; May 25th, 2009 at 3:11 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,479
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: how do i get a variable from a regular ol url?

 
0
  #3
May 25th, 2009
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.
  1. Example - real url:
  2. site.com/index.php?username=cwarn23&id=blog
  3. Fake url:
  4. 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.
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,639
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: how do i get a variable from a regular ol url?

 
0
  #4
May 25th, 2009
Here is sample code for you.

file1.php
======
  1. <?php
  2. $no=$_REQUEST["no"];
  3. $name=$_REQUEST["name"];
  4.  
  5. echo "values - $no and $name";
  6. ?>
  7.  
  8. <br/>First Method
  9.  
  10. <form method="post" action="file1.php">
  11. No <input type="text" name="no"/>
  12. Name <input type="text" name="name"/>
  13. <br/><input type="submit" namd="cmd" value="Submit"/>
  14. </form>
  15.  
  16. <br/>Second Method
  17. <a href="file1.php?no=100&name=Mr.X">Send</a>
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: how do i get a variable from a regular ol url?

 
0
  #5
May 25th, 2009
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.
  1. RewriteEngine On
  2. 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.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 150
Reputation: sDJh is an unknown quantity at this point 
Solved Threads: 13
sDJh sDJh is offline Offline
Junior Poster

Re: how do i get a variable from a regular ol url?

 
0
  #6
May 25th, 2009
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:

  1. $uri=$REQUEST_URI;
  2. $tmp=explode("/",$uri);
  3. 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: how do i get a variable from a regular ol url?

 
0
  #7
May 25th, 2009
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).
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: how do i get a variable from a regular ol url?

 
0
  #8
May 25th, 2009
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...
  1. $uri=$REQUEST_URI;
  2. $tmp=explode("/",$uri);
  3. 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
Last edited by Ezzaral; Jun 11th, 2009 at 2:38 pm. Reason: Changed to non-promotional url.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: how do i get a variable from a regular ol url?

 
0
  #9
May 25th, 2009
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.
  1. $tmp=explode("/",$REQUEST_URI);
  2. $specific_user = $tmp[count($tmp)-2];
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 281
Reputation: SKANK!!!!! is an unknown quantity at this point 
Solved Threads: 2
SKANK!!!!! SKANK!!!!! is offline Offline
Posting Whiz in Training

Re: how do i get a variable from a regular ol url?

 
0
  #10
May 25th, 2009
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.
Last edited by SKANK!!!!!; May 25th, 2009 at 9:20 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC