Header location not working in php

The following statement does not seem to work. I also do not receive error messages.

header("Location: /home/shaliu/Projects/Nominatim/website/search.php?q="+$query); 

I am using file_put_contents () in the search.php file.

Is there any way to find out what might be wrong?

+7
php header location
source share
11 answers

change this:

 +$query 

:

 .$query 

Because:

+ is the concatenation operator for JavaScript, where . - concatenation argument for php

Also, the path you are sending seems wrong. The parameters inside the header function must be the full web address, for example, starting with http :

 header('Location: http://www.example.com/'); 

So far, your answer uses the local file path: "Location: /home/shaliu/Projects/Nominatim..." .

+12
source share

Try:

You can use:

header("Location: http://www.example.com/search.php?q=".$query); exit();

Or if your search.php file is in the root directory:

header("Location: /search.php?q=".$query); exit();

It can help you.

+2
source share

put error_reporting (E_ALL);

use relative path.

change this with

  header("Location: /home/shaliu/Projects/Nominatim/website/search.php?q="+$query); 

In php for concatenation use ".", "+" Is used in javascript not in php

 header("Location: /home/shaliu/Projects/Nominatim/website/search.php?q=".$query); 

Make the correct path for the file

+1
source share

After fixing + to . as @Webeng said earlier.

If you visit your page by typing /home/shaliu/Projects/Nominatim/website/index.php in your browser, the headers will not work at all, because you are not in the web context, but in the local browsing context.

If you visit it through http://localhost/Nominatim/index.php , you will get to the web context, but your header will not work, because you are technically sending a redirect to the path http://localhost/home/shaliu/Projects/Nominatim/website/search.php , which probably does not exist in this place. Instead, you should change it to: /search.php if your website/ folder is linked to http://localhost/ or something suitable depends on your environement configuration.

+1
source share

you can try this. I hope this helps

 header('Location: http://www.example.com/search.php?q='.$query); 
0
source share

header () is used to send HTTP headers ( http://php.net/manual/en/function.header.php ). It looks like you are trying to access a php file using the local file path rather than http (web address). "/home/shaliu/Projects/Nominatim/website/search.php" should be accessible over the Internet and this web address should be used in the header () (see @Purushotham's answer).

0
source share

header("Location:https://www.example.com/search.php?q='<?php echo $get_id; ?>'");

Please try this php code. if you use the title in the first title and php location then the question mark of your search will get an identifier.

0
source share

If you use

 /home/shaliu/Projects/Nominatim/website/search.php 

In this case, your location begins with /, which means that the home folder (directory) must be inside the server’s root folder. For example, as a local server, if we consider XAMPP, the home folder should be inside C: \ xampp \ htdocs (in the general case), and if we consider WAMP, then the home folder should be inside the www-folder.

If your home folder is inside the folder where your current page is located, you should use

 home/shaliu/Projects/Nominatim/website/search.php 

No / (slash required).

Secondly, you need to replace +. to concatenate a string.

SO, if your home folder is inside the server root directory, you should go with

 header("Location: /home/shaliu/Projects/Nominatim/website/search.php?q=".$query); 

Otherwise you must go with

 header("Location: home/shaliu/Projects/Nominatim/website/search.php?q=".$query); 
0
source share

Try this code with the "if file exists" test:

if(is_file("/home/shaliu/Projects/Nominatim/website/search.php")) { header("Location: /home/shaliu/Projects/Nominatim/website/search.php?q=".$query); } else { echo "Error!"; }

Remember: in php use for concatenation . (@shivani parmar)

Remember: if the header call is called after any HTML element, php returns an error!

0
source share

You need to replace the plus ( + ) with a period ( . ) To concatenate the string.

Try it.

 header('Location: http://www.example.com/search.php?q='.$query); 
0
source share

Besides the obvious concatenation problem that has already been pointed out, it looks like this path /home/shaliu/Projects/Nominatim/website/search.php is a *NIX path; given the pattern /home/<user> that starts with.

If so, and you are trying to open the file outside the root of the web server, then most likely this is a permission problem. Moving your search.php to a location accessible to the web server process and running chmod / chown in the file that you are trying to open the web server process can sort you. In addition, you may need to indicate which OS you are using, in case you also need to run chcon .

Oh, I would make this comment, but it seems I don't have the necessary reputation to add comments.

0
source share

All Articles