0

I have 3 files index.php, search.php, test.php

test.php contains a script just for execution doesn't display anything I want user to automatically redirect (without delay, without displaying anything) from test.php (after execution of test.php) to where they came from

like this

index.php -> test.php ---> index.php

search.php?q=searchterm -> test.php ---> search.php?q=searchterm

I'm new to php so help anyone

2 Answers 2

1

Any "redirect" is implemented by sending HTTP request. You have to make sure that no output was before sending headers.

    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: '.$location);

where $location = 'http://yoursite.com/destination.php'; for example. You can also send headers with GET or POST parameters if you want. See php POST variable with headers

Sign up to request clarification or add additional context in comments.

2 Comments

that would not work it redirects to only single page (if I entered index.php doesn't matter where the user came from it just redirect to index.php) I need redirection to the previous page (if came from index.php then redirect to index.php, if came from search.php then redirect to search.php) header ('Location: '.$location); works but I need conditional redirect
Then use $location = $_SERVER['HTTP_REFERER']; but make sure it's not empty
0

use header( "refresh:3;url=any page you want" );

1 Comment

You should describe more clearly how to solve the problem, and please format code appropriately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.