FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


send variable from php tp php file





Talk2Tom11
I was wondering if there was some way that i would be able to send a variable from a php file to another php file.

for example... if i have $name, where the value for $name came from a html POST from the previous page. How would i transfer the value of $name to the next php page?

Sorry if my wording is a little confusing.
Roald
Code:
<?php
session_start();
$_SESSION['name'] = $name;
?>

On your other page you should put this above all your code:
Code:
<?php
session_start();
$name = $_SESSION['name'];
?>
Manofgames
or you could use cookies, but they aren't as reliable as users sometimes disable them.

Or you could use $_GET

//Vars before here, such as name

$endlinks = "name=$name&";

echo "<a href='thisisalinktoapage.php?".$endlinks."'>link</a>

Of course, that isn't that reliable, and requires you to have defined all the vars before you create the links.

I'd suggest sticking with sessions.
sonam
Yeah the session is the best solution. But I would like to little bit extend the Roald script with one line. In many situation and for security reason is very good praktice to unset ones used $_SESSION.

Code:
<?php
session_start();
$name = $_SESSION['name'];
unset($_SESSION['name']);
?>


Sonam
Roald
Why?
Related topics
Mail with PHP (Simple Tutorial)
PHP Test File
150 frih to make this SIMPLE script
How to upload a file via html-form and php?
php page flickering, maybe caused by flash item
Where is the php.ini file?
PHP Read File Help needed.
A Question about the PHP.INI file.
SOLVED::PHP upload_max_filesize
Passing a variable to multiple pages...sort of?
Limiting php file functions with .htaccess
PHP.ini and PHP session maxlifetime question
Uploading more than 2MB in PHP
consistently get different script errors when logged in
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.