2

I want to pass a variable through header. In my system the user stays on the profile page and click on a link to fill and submit a form. When the form is submitted the page redirect to the profile page. When I the profile page displayed the member id has lost, so it don't display the member details. What I want to do is pass the member id when redirecting happens.

function redirect_to($location = NULL){
    if($location != NULL){
        header("Location:{$location}");
        exit;
    }
}


redirect_to('member_profile.php');

what I am trying to do is this

redirect_to('member_profile.php?id=$mselcted_memberI');
1
  • 1
    And why can't you do what you're trying to do? Did you try using " instead of '? Commented Dec 28, 2013 at 20:54

1 Answer 1

2

You are using single quotes ' which will make it a literal string, instead, concatenate that using a . instead

redirect_to('member_profile.php?id='.$mselcted_memberI);

Also, you don't require braces {} here

header("Location:$location");
Sign up to request clarification or add additional context in comments.

3 Comments

@user3138830 than you are doing something weird
Braces make code more readable. I always use braces when placing vars into strings.
@Jari Depends, I only use them when dealing with arrays $var['blah']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.