redirect different pages to one page [duplicate] - php

This question already has an answer here:
Redirect any page passing certain variables
(1 answer)
Closed 8 years ago.
I'm putting a search engine on my site, and the search box appears on several different pages. The output looks like this: http://mysite.com/mypage.php?bluepart=search&keywords=dogs&go=Go I'm trying to do an .htaccess mod rewrite to where any page that passes these variables will get redirected to search_results.php. The bluepart=search and go=Go will always be the same, but keywords can be any number or words. Also, some of my pages are .html and some are .php, when I refer to any page that passes the variables.
How do you do this, what does the code look like?

If you haven't sent any data back yet, you can use the redirect header.
if( $_REQUEST['bluepart'] == 'search' && isset($_REQUEST['keywords']) )
header('Location: http://mysite.com/search_result.php?bluepart=search&keywords=' . $_REQUEST['keywords']);

Related

get data from URL without having variables [duplicate]

This question already has answers here:
Get the full URL in PHP
(27 answers)
Closed 7 years ago.
I don't know how can I get data from an url without having any sort of variable.
For example if the user comes to the website welcome.com and he starts adding to the url
EX: welcome.com/NewYork-NY/Driver
how can I save NewYork-NY and Driver when he/she hits enter ?
I need to save the data in order to list some content for the user and the only option for him to get to this content is if he goes to that URL manually, there is no button or option for him to chose between cities or categories.
The superglobal $_SERVER['PATH_INFO'] contains all the parts of the URL path after the script. So if the user goes to:
welcom.com/index.php/NewYork-NY/Driver
$_SERVER['PATH_INFO'] will contain /NewYork-NY/Driver.

Redirecting user to a webpage with PHP [duplicate]

This question already has answers here:
How do I make a redirect in PHP?
(34 answers)
Closed 8 years ago.
So I have an HTML webpage with a form on it. The form sends its data to a PHP file on the server.
After processing the form data with the PHP file, I want to redirect the user to another HTML webpage.
How would I do this?
This is usually done by PHP header function, like this:
header("Location: http://your-domain.com/your-page.php");
You can read more about it in PHP manual or from here.
Though this question is a duplicate. I'll answer it. You do it as follows:
header("Location: http://yourwebsite.com/otherpage.php");
In PHP you have to use below code snippet to redirect from one location to the other.
header("Location: page.php");

Is it possible to use $_POST from an anchor? [duplicate]

This question already has answers here:
How do you force a web browser to use POST when getting a url?
(11 answers)
Closed 8 years ago.
I'm working on a retail type website and I have the search bar so that when you search for something it shows up in a grid with all the results. Now, all the product names are going to be links that all lead to the same page (result.php) which is full of variables which are filled with the information of the product that was clicked. How would I go about doing something similar to
$name = $_POST['productname'];
but with an anchor tag instead of a text input so I can use it to pull the MySQL data to fill in the page. Is something like this possible?
Click
if(isset($_GET['variablename'])) {
echo $_GET['variablename'];
}
if you use query string in anchor tag you cannot use $_POST.

Reload previous link on click-event of back button of browser? [duplicate]

This question already has answers here:
How to detect the back button
(2 answers)
Closed 9 years ago.
i am developing one website in which main content is getting load by jquery ajax according to selected menu item.
on selecting any menu item, url get changed according to this pattern:
http://host/domain/index.php?pageid=page
here page refers to the page that i want to load into main content using ajax.
now in this case, i want to reload the previous page if user clicks on back button of browser.
can anyone help me out how could i achieve this?
If you do not change a url, then I'm afraid that is not possible.
Suppose you should better try to use window.history which provides onpopstate event when user clicks back button. But you will need to modify url in browser with history.pushState/history.replaceState functions. Possibly, you can add same url to history, so it will not be changed visually. And then take previous URL from your custom history array. But not sure if popstate will work if you place same url with pushState
But that will work in modern browsers only. To make it work in all browsers, you should better use some history plugin (for example this) which will also handle IE using hashtags

Pass PHP variable from one page to another and to another [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
pass value from page to another in PHP
For example, I have 3 pages. First page will be a regular HTML login page which will ask for username. Second page will get this username variable thru POST function and assign a php variable such as $username. Third page will take this $username variable and display it. How can this be done? I have done the first two pages but I need help with passing it to the third page.
Thanks!
Check the PHP documentation for sessions. There are many examples of how to do this.
http://www.php.net/manual/en/session.examples.basic.php
Use a $_SESSION superglobal:
http://us3.php.net/manual/en/reserved.variables.session.php
You'll need to use a session_start() function at the beginning of any page you want to maintain session data for. After that, you can just assign to and retrieve from $_SESSION['username'].

Categories