Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Transfer Variables To Another Php Script
Rating 3 V
kvarnerexpress
post Dec 25 2005, 02:20 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



Hello,
I've one registration page where the users fills in their information, is it possible to trasnfer the things the fill in on the registration page to another script that does someting and returnes something to the first page like true/false and then the registration gives an error messange if the other php script returned false?

Something like the script "activates" another script that does something and returnes the result back to the original script.

Best Regards
Go to the top of the page
 
+Quote Post
beeseven
post Dec 26 2005, 09:59 PM
Post #2


Privileged Member
*********

Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



Could you use a class? I'm not very experienced with classes in PHP, but would this work for your purposes?

(your first script)
CODE
include helperclass.php;
$result = Helper::activate($var1, $var2, ..., $varN);

(helperclass.php)
CODE
class Helper {
    function activate($var1, $var2, ..., $varN) {
         if(...)
              return true;
         else
              return false;
    }
    function otherStuff($var1, $var2, ..., $varN) {
         ...
    }
}
Go to the top of the page
 
+Quote Post
Tyssen
post Dec 26 2005, 11:15 PM
Post #3



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



QUOTE(kvarnerexpress @ Dec 26 2005, 12:20 AM)
Something like the script "activates" another script that does something and returnes the result back to the original script.

Sounds like you're talking about a form that submits to itself. Basically, the values will be captured by using the $_POST['formElementName'] and then you check to see if the form has been submitted already with if ($_SERVER['REQUEST_METHOD'] == "POST"). If it hasn't been submitted yet, you display the form, if it has you display something else.
Go to the top of the page
 
+Quote Post
adly3000
post Jan 31 2006, 05:57 PM
Post #4


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



i think that registering a session variables is easier, you can save the entered data from the user into a session variable then in any page you should write:
CODE
session_start();

then all the session variable will be defined.
Go to the top of the page
 
+Quote Post
Spectre
post Feb 1 2006, 04:23 AM
Post #5


Privileged Member
*********

Group: Members
Posts: 873
Joined: 30-July 04
Member No.: 246



I would suggest simply including (via 'include()') the script from wherever the form is sending its data ('action="page"'), as has more or less already been mentioned.

Depending on the method you instruct the form to use - ie. POST or GET - data entered in the form will be stored in either the $_POST or $_GET arrays respectively once it is submitted. So if you were to include() your script from the page that receives the data, the two abovementioned variables would be accessible.
Go to the top of the page
 
+Quote Post
adly3000
post Feb 1 2006, 08:20 PM
Post #6


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



$_post and $_get recieves the data entered in the last page which contains the form, but what do you have to do if you need it later?!
i think using $_session is better?
Go to the top of the page
 
+Quote Post
Spectre
post Feb 2 2006, 09:51 AM
Post #7


Privileged Member
*********

Group: Members
Posts: 873
Joined: 30-July 04
Member No.: 246



Using sessions is not always an option. Nor is it always desired. I try to avoid using cookie or session data wherever I can, and only ever do so if there is absolutely no other option.

PHP often appends the session ID to URLs where it has no other option for 'remembering' the session owner, meaning a link to, say, '/file.php' may become '/file.php?PHPSESSID=(some 32 byte MD5 hashed string)'. This is not only problematic when someone bookmarks or links to a certain page on your website, inadvertedly including the session ID, but also when search engines attempt to crawl your site. I seem to vaguely remember Google advising against the usage of sessions where possible due to the latter reason.

If you need to use data later, I would suggest storing it in a database (even a flatfile will do the trick where no other option is available). Remember that any files include()ed will have access to all variables declared on a global scope (such as $_POST), meaning that if the form submits data to 'page.php', and 'page.php' references 'script.php' via include() or require(), script.php will be able to access and manipulate the data received. If the information is not 'valuable' (for lack fo a better word) enough to store in a database, then you probably don't need to remember it outside of immediate processing anyway.
Go to the top of the page
 
+Quote Post
iGuest
post Dec 28 2007, 06:32 AM
Post #8


Hail Caesar!
*********************

Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



How to transfer variable from one page to another in php?
Transfer Variables To Another Php Script

I am going to make a login page. After my login I want to print username in in another page. How will I do?

-Imtiaz Alam Khan
Go to the top of the page
 
+Quote Post
gamescoper
post Dec 31 2007, 11:19 AM
Post #9


Newbie [Level 2]
**

Group: Members
Posts: 27
Joined: 8-April 07
Member No.: 41,287



well as mentioned above you can use $_POST or $_GET or $_SESSION or $_COOKIE but each method has its pros and cons for example cookies can be created by the user manually and so can infiltrate your system
Go to the top of the page
 
+