1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help about Header in PHP

Discussion in 'PHP' started by life31, Nov 29, 2007.

  1. #1
    Can any one help me about how to get get the value of variables in the url bar so that i acess them using $_GET method

    Was trying to give a header aswell send the variables through url and acess them but it didnot help me. Not getting it right

    How do you specify the header.
    SEMrush
    What i tried was

    header("location:xyz.php?mess=".$message);

    But nor the header works neither the $message passes through url
     
    life31, Nov 29, 2007 IP
    SEMrush
  2. Kwaku

    Kwaku Well-Known Member

    Messages:
    1,218
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #2
    header("Location: xyz.php?mess=".$message); actually should work ; are you sure it doesn't?

    test1.php:

    <?
    $message="test";
    header("Location: test2.php?mess=".$message);
    exit;
    ?>

    test2.php:
    <?
    print_r($_GET);
    ?>

    gives me ; Array ( [mess] => test )

    Or am I not getting what you mean?

    If you really want it in your address bar (to have it appear there);

    function _redirect($link) {
    echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$link.'">';
    }

    _redirect("http://www.bla.com/xyz.php?mess=".$message);
    exit;
     
    Kwaku, Nov 29, 2007 IP
  3. life31

    life31 Active Member

    Messages:
    1,024
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #3
    I as getting an error as cannot send header information.


    I was trying usin to validate a form with if & else

    if($name==""){
    $message="please enter your name";
    header("Location: test2.php?mess=".$message);
    }

    else{
    if($address==""){
    $message1="please enter your address";
    header("Location: test2.php?mess=".$message1);

    else{
    echo "thankyou";
    }
    }


    Is that exit; what you use needed?
     
    life31, Nov 29, 2007 IP
  4. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #4
    you should define a value for $message and $message1

    like:

    $message='Welcome';
     
    YIAM, Nov 29, 2007 IP
  5. life31

    life31 Active Member

    Messages:
    1,024
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #5
    Ya i ment th same thing.

    specified the $message="please enter your name";

    $message1="please enter your address";
     
    life31, Nov 29, 2007 IP
  6. Kwaku

    Kwaku Well-Known Member

    Messages:
    1,218
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #6
    You need to send header information before sending ANYTHING else, and it is very good practice to ALWAYS(!!!) put exit; after a header("Location: because you might create very serious security problems if you don't. Most commercial and open source software have had security leaks because of this, most notably some well known hosting admin panels which allowed none authenticated users to log-in because the script was executed after header("Location: . An example (offtopic, though users might find it useful):


    <?

    if(!logged_on()) {
    header("Location: login.php");
    }

    do_something_only_a_logged_on_user_may_do();
    ?>
     
    Kwaku, Nov 29, 2007 IP
    life31 likes this.
  7. life31

    life31 Active Member

    Messages:
    1,024
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #7
    Ill try using exit;
    Any ways thnks for he help. Repped you.
     
    life31, Nov 29, 2007 IP
  8. life31

    life31 Active Member

    Messages:
    1,024
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #8
    Fine will try using exit;
    Anyways thanks for th help. Rep+
     
    life31, Nov 29, 2007 IP