1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is It Possible To Use fwrite To Insert PHP Variables?

Discussion in 'PHP & Perl' started by gimme4free, Jan 5, 2009.

  1. gimme4free

    gimme4free Executive VIP Premium Member

    Oct 22, 2008
    Likes Received:
    Easier to explain with example:

    index.php - This has a form on it with one field ($URL).

    I want $URL to be submitted to test.php

    Test.php contents eg.

    Hi, thanks for visiting, your site is $URL

    Obviously this is not what I will be using it for but just an example.

    So Test.php will already have the text and fwrite will LOOK for the variable and overwrite it. Also if possible does anyone know how to have a default value as well? So there can be a default value that can be overwritten and all URL's can also be overwritten in the future as well so it will not actually remove the $URL variable?
  2. Barbacamanitu

    Barbacamanitu Jr. VIP Jr. VIP Premium Member

    May 8, 2008
    Likes Received:
    $myvar = $_POST['myvar'];
    if ($myvar=='') {
    $myvar='Default value';
    echo 'The variable is '.$myvar;
    That is totally off the top of my head, but it should work.
    It gets the post variable (value of form on first page), and saves it in a variable. If the variable equals '', that means no value was given, and to set a default value.

    Hope that helps.