Jump to content
Sign in to follow this  
seblondres

http_build_query GET URL

Recommended Posts

Hi,

 

I'm trying to build a url in the php file below from a url in the browser.

 

URL in the browser: http:/test1.com/directory.php?city=london

 

then I like to get the city and add it at the end of the url in the php file below so it looks like that: http://www.test2.com/directory/london

 

so far I go this but I can only access http://www.test2.com/directory/

<?php$city = $_GET['city'];$fields = array('city' => $city);$url = "http://www.test2.com/directory/". http_build_query($fields, '');?>

Thanks for your help,

 

Share this post


Link to post
Share on other sites

Where is the variable $url being used?

Share this post


Link to post
Share on other sites

Thanks for your answers:

 

The variable $url would be used to scrape this page for example: http://www.test2.com/directory/london-greenwich

 

Here is how it should works:

1. I'm on the index page and I have a link http:/test1.com/directory.php?city=london-greenwich

2. When I click on the link above I'm redirected to directory.php which contain the php file above with the variable $city = $_GET['city'];

3. With this variable $city = $_GET['city']; I should be able to get "london-greenwich"

4. Then I want to add that piece of url "london-greenwich" to $url = "http://www.test2.com/directory/"

5. So I can build the following url $url = "http://www.test2.com/directory/london-greenwich"

 

Thanks,

Edited by seb_london

Share this post


Link to post
Share on other sites

http_build_query() does not do what you want.

 

All you need to do is append the value to the URL:

$url = "http://www.test2.com/directory/". $_GET['city'];

I asked what you're planning to do with the variable $url, because from this point on I have no idea what you want.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...