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.
Related
This question already has answers here:
Stop browsers asking to resend form data on refresh
(4 answers)
Closed 7 years ago.
I am using forms to retrieve data using post method. Once I do that, and retrieve data from database, if I want to refresh the page, my browser will give me alert window telling me it will have to resend data again. How would I go about making that window not appear?
On your form, you need to change the method="POST" to method="GET".
Also, you should alter the way you get the requests to "$_GET" and not "$_POST".
You will notice that the parameters are going to appear on the URL after submiting.
Note that this isn't recomended for forms, it's often used for search boxes.
It should be form action another page and completing inserting data and than redirect to form page
or after completing data send redirect with jsvascript code
like
window.location.href = window.location.pathname;
This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 9 years ago.
I read $_POST is empty after form submission topic and I wondered how to get the data from input without attribute name?
<input type="text" >
var_dump($_REQUEST)//empty
var_dump(file_get_contents('php://input')) //empty
Basically, the form should be specified its name. If not, you cannot get it from the server-side.
However, the form without name is also valid in HTML5. The reason is that you might sometimes want to use for form submission via AJAX or Javascript app. In many cases
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.
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'].
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']);