this is the problem-
my program is linked to another website. we arranged that the website would have a link to my program and pass along a parameter that holds an X value. I have many scripts and some of them need to use that value and some don't..so I'm looking for a way to save the parameter that is passed from the website somehow that any of my scripts can access it.
I thought of creating a file that defines it at first and then add require_once to all my scripts but then the file would be redefined each time a script calls it and plus it won't get the parameter sent from the website to use in the definition..

the website will have something like this-

<form method="post" action="myurl.php">
  <input type="hidden" name="x" value="1">
  <input type="submit" name="submit" value="to my site" />
</form>

try using session cookies

can u please give me an example? I don't know anything about using sessions or cookies

so before any of your html code you have to process the form's x value

<?php 
//youll want to verify that someone actually came to this page through the form so 
if (isset($_POST['x']) {

    $inToCookie = $_POST['x'];
    setcookie('x',$inToCookie,0);  //the x is the name, the $inToCookie is the value passed, and the 0 tells it to delete the cookie when the browser closes
}
?>
doctype....

then to extract that value at the begining of each page you would put a code like this :

<?php 
if (($_COOKIE['x']) != NULL ) {
 $myUsableVariable = $_COOKIE['x'];
}
?>

Keep in mind if there is security involved in this project of yours you will have to research best practices to secure the data you are transmitting.

thank you, I'll try this

one more thing to keep in mind, if the person did not get to your site through the form, the variable I referenced $myUsableVariable will be NULL and if you try to use it it wont work so you will have to verify that it exists with the type of data you are looking for. This will help with security and will help your site function the way it is supposed to.

yeah I guess I'll put all the scripts inside the if (($_COOKIE) != NULL ) if it's not set nothing would be displayed

I know you have to set cookies before the document declaration, I am not 100% on when you can call cookies other than before the document delcaration. This gets tricky because PHP is processed before the page is displayed by the server. The best thing it to check the variable for the contents inside, if you have an idea of what is going to be inside then you can put if statements to weed out the null and the "" values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.