$POST variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

$POST variables

Post by sebs »

I have to redirect a page and I need the variables from that page.How can I include them in the redirect page.I read there is a posibility to use a session on the server.Either way could you help me?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

sessions or use get like this

header("location: site.php?var=whatnot");
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

shiznatix wrote:sessions or use get like this

header("location: site.php?var=whatnot");
Could you be more specific?This is only working with GET?
could you explain to me how is this working.Sorry to bother you again.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

$var = $_POST['var'];
$other = $_POST['other'];

header("location: somepage.php?var=$var&other=$other");
that will send you to somepage.php and will send the variables $var and $other along with it. now those 2 variables will only be accessable by $_GET on the somepage.php, not by $_POST anymore. using a session you would do somting like

Code: Select all

session_start();

$_SESSION['var'] = $_POST['var'];
$_SESSION['other'] = $_POST['other'];

header("location: somepage.php");
then on somepage.php

Code: Select all

session_start();

echo $_SESSION['var'];//will echo what $_POST['var'] was originally
echo $_SESSION['other'];//will echo what $_POST['other'] was originally
understand?
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

Yes,thank you!
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

Sorry I asked stupid questions but based on your example I wrote:
<a href="<?php echo("moduli_contatto.php?name=$cname")?>"

and it's not working for the first two results,for the other 100 it works.All it's put in:
while($data=mysql_fetch_array($result)){
<table>
...
<a href="<?php echo("moduli_contatto.php?name=$cname")?>"
...
</table>

Is there a problem if the string are something like "A B C Plane"?
I think it has no sense
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sebs wrote:Is there a problem if the string are something like "A B C Plane"?
I think it has no sense
yes, there can be a problem. rawurlencode() can likely help you with it. Where does $cname come from?
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

$cname

Post by sebs »

$cname=$data[1];
company name from database nvarchar[255]
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

thanks

Post by sebs »

it works with rawurlencode(),thanks.It was really odd anyway.Why 100 work and the first one don't?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there are many characters that require escapement to work with URLs correctly..
Post Reply