I want to send a feedback message from one page to another without using input elements via POST method. Is that possible? Or is there other way around?
What i want is applying a value from one page to another page's variable.
i.e.: Sending "Yaba Daba Doo" string from 1.php to 2.php's variable, named $info.
1.php:
<?php
$info = "Yaba Daba Doo";
?>
2.php
<?php
$variable=$_POST['info'];
echo "The message is:".variable;
?>
How can i pass info variable to 2.php using POST method, without input elements?
You can use session variable to store data on server and access across the pages of your application.
If you want a secure way to send this variable you can use session so that end user can not see it
An example
page1.php
session_start();
$_SESSION['mes']=$info;
page2.php
session_start();
echo $_SESSION['mes'];
And the another way is to pass variable in GET which I will not recommend user can see the value of your input variable
Use a session to store your data, then when ever you want to store is call upon the $_SESSION global.
Here is more info about sessions:
php.net
W3schools
Tutorial
you can use php curl to make a post request to 2.php from 1.php
Related
I currently have some php code on a form action, and it is being updated to the form's next page with
<?php echo $_POST['var here']; ?>
and it is working, but I noticed when Im trying to refresh the page it asks to confirm resubmission. When I resubmit it works in that tab in which it was sumbitted, but in another new tab it does not show the displayed php post variables. I even took it the next step by seeing that when I open the 2nd page after the form action has been submitted the php post variables are gone...
Help!
Thanks!
When you submit a form with <form method="post" /> it does a post request to the server, thus populating $_POST. When you open the link in a new tab it is no longer a post request but a get request. That is why you'll see nothing in $_POST.
$_POST — usually from forms
$_GET - from values on the URL (the query string myscript.php?myvar=Joe)
You can find plenty of resource about it. You can start here
If you want to keep the values you can save them to the session:
<?php
session_start(); // should be at the top of your php
if (isset($_POST['var'])) {
$_SESSION['var'] = $_POST['var'];
}
$myvar = isset($_SESSION['var']) ? $_SESSION['var'] : "no var";
echo $myvar;
Now the value is stored in the session so you can visit the page in a new tab and it will still be there.
This sounds like desired behavior. The $_POST variable should only be filled when the post action is created. If you're looking to store variables across pages you could store it in either the $_SESSION var in PHP or deal with the front end $_COOKIE business. If you're always going to be rendering pages from the backend then $_SESSION is the way to go. It's never too late to read up on cookies and sessions.
The skinny of it is that you're going to want to do something like this:
<?php
session_start();
if ($_POST['var']) {
$_SESSION['var'] = $_POST['var'];
}
echo $_SESSION['var'] ?: $defaultValue;
Then you'll notice that the message changes only when you post and won't exist before then.
I have three forms - payment.php , payment1.php and paydb.php . payment.php contains the front end form.payment1.php contains the back end of the form of payment.php. whereas we are shifting to paydb.php from payment1.php. Now I'm filling the form by entering member number in payment.php which is retrieved in a variable $member_no in payment1.php .Now I want to get the value of member_no in paydb.php . How to do that ?
After receiving $member_no in payment1.php redirect to paybd.php with a get array
using
header('Location: http://www.example.com/paydb.php?member_no=$member_no');
then receive $_GET['member_no'] number and assign to a variable
example:
$member_no = $_GET['member_no']
The first thing is make sure you are not passing sensitive information where the public can see it. Such as in a URL.
As soon as you get the member's number... store it in a session variable.
You can probably do this when they log in.
session_start();
$_SESSION['member_no'] = $member_no;
OR on the first payment page (assuming 'member_no' is the name of the form element being passed) like this...
$_SESSION['member_no'] = $_POST['member_no'];
Now that session will persist as long as the visitor has their browser open and you don't have to worry about passing it from page to page.
You can use that session on any subsequent page simply by calling it.
<?php echo $_SESSION['member_no'] ?>
Without showing this information to the public.
ALWAYS make sure you place this at the top of any page where you want to use session variables.
if (!isset($_SESSION)) {
session_start();
}
I have such a loop:
for($i=0;$i<count($dersler);$i++)
{
echo $dersler[$i].', ';
}
I want to run this loop on another page by capturing $dersler variable from another page. How can I manage it?
Thank you.
You could pass the variable as a query parameter and access it again using the $_GET superglobal. An other option is posting the variable to the page using a form, and accessing it through $_POST.
But the solutions mentioned above require sending the value to the client side where it could be modified. If this is not desired, you could use a session to store a value serverside, between requests from the same client. Take a look at the session documentation: http://www.php.net/manual/en/book.session.php.
You can store $dersler in a session.
on the first page :
session_start();
$_SESSION['dersler'] = $dersler;
and on the other page :
session_start();
$desler = $_SESSION['dersler'];
for($i=0;$i<count($dersler);$i++){
echo $dersler[$i].', ';
}
I'm trying to send the value of this php get_field variable from a wordpress Archive page.
get_field('supplier_email_address', 'product_brand_' . $term->term_id );
to another sendmessage.php page which is never accessed other than with the of JS to send a form. The variable I need filled is called:
$sendto="value";
How can I achieve this?
EDIT: Apparently this requires more information.
Use session variables.
First of all every page you want to use sessions on needs to have the function session_start(); declared at the top of every page. You then can use the session superglobal to store things.
Pg1.php:
<?php
session_start();
$_SESSION['variable_name'] = 'string';
?>
Pg2.php:
<?php
session_start();
echo $_SESSION['variable_name'];
?>
Pg2.php will show: some string
Either POST your value so your second page can retrieve it in the $_POST array, or include it in the URL path so your second page can $_GET it.
Without more info, we can't really help you any more than that.
I was wondering how I can pass a URL to another web page using PHP. I know if I were to use an HTML form I could have a hidden field with the value being the URL I want to get.
How can I pass the URL along to another page without using a form?
If the page is your own, you could use a session variable.
More details here: http://www.w3schools.com/php/php_sessions.asp
You can use $_SESSION, or a cookie.
PHP has a server global variable which includes a referrer variable.
$_SERVER['HTTP_REFERER']
http://php.net/manual/en/reserved.variables.server.php
You can echo this and it will output the page which the user came from.
You could pass it using a get query,which is in a way form data, so i won't go into it
OR a session variable. On the sender page
session_start();
$_SESSION['url']="http://site.com"
and on the receiver
session_start();
$url=$_SESSION['url'];
unset($_SESSION['url'])l
You can initiate sessions.
Put session_start(); at the top of every page (normally by including a header or function). The session_start(); needs to come before any HTML output.
Then on your referring page, you can save values into the session array:
$_SESSION['URL'] = "myurl.com";
On your second page, you can reference it just like any other variable:
echo $_SESSION['URL'];
Link
somepage.php would then receive the URL in the variable $_GET['url'].