Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header Location not working in Php [duplicate]

The following statement doesn't seem to work. I am not getting any error messages either.

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

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

Is there a way to figure out what could be wrong?

like image 252
sheetal_158 Avatar asked Apr 26 '16 22:04

sheetal_158


3 Answers

change this:

+$query

to this:

.$query

Because:

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

Also, the path you are sending seems to be incorrect. The parameters inside the header function should be a complete web address, for example starting with http:

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

While your answer is using a local file path: "Location: /home/shaliu/Projects/Nominatim...".

like image 167
Webeng Avatar answered Oct 09 '22 14:10

Webeng


Please try:

You can use:

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

Or if your search.php file is on root directory:

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

It may help you.

like image 38
Ramayan Prasad Avatar answered Oct 09 '22 16:10

Ramayan Prasad


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);

Please make Your path correct for file

like image 1
shivani parmar Avatar answered Oct 09 '22 14:10

shivani parmar