header ( ' Location .... with variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ladbroke
    New Member
    • Apr 2006
    • 1

    header ( ' Location .... with variable

    Hiya,

    got a little prob with the syntax for
    header ( ' Location .... with variable).
    Usually examples are given with a complete URL, like:

    ..... header( 'Location: login/testsite/start.php' );

    I'd like to use particular read out data from my database (URL)
    (variable $result).


    ..... header( 'Location: $result' ); ?????

    $result is not a string but an array
    see below in code: $result=mysql_f etch_array($sql request);

    Thanx in anticipation!



    Code

    <?php

    session_start ();

    if(isset($_POST['password'])

    AND
    strcmp(trim($_P OST['password']),'') != 0 )


    $dbID=mysql_con nect ('localhost', 'root') or die(mysql_error ());

    mysql_select_db ('login', $dbID)or die(mysql_error ());

    $sqlZiel="SELEC T destination FROM passwordrequest WHERE password = '101TR'";

    //'101TR' (example)

    $sqlrequest=mys ql_query($sqlde stination)or die(mysql_error ());

    $Ergebnis=mysql _fetch_array($s qlrequest);

    mysql_close();

    //print_r ($result);

    if(isset($resul t))

    {

    header("Locatio n: ($result)");

    //header( 'Location: testsite/start.php' );

    exit();
    }

    else

    {

    header( 'Location: http://localhost/login/IDfailure.php' );

    exit();
    }


    ?>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    try
    [CODE=php]header('locatio n: ' . $result[0]);
    # or
    header('locatio n: ' . $result['destination']);[/CODE]

    please use [ CODE ] tags when posting code

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Single quotes will not parse variables unless they are concatenated, like the above post shows. Double quotes, however, will parse variables without having to concatenate them.

      Comment

      Working...