Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Dynamic redirect header help

    Hi,

    Excuse me if I'm a little long winded explaining this....

    I have a site that will offer members a range of services including their own web site which they can point their customers to (on our site, for example: mysite.com/site/index.php?mem_id=1).

    So I have a choice of web design styles for the members, they can choose the style they want from a drop down in a form in their member area and save their style choice in the mysql db.

    I have a landing page (mysite.com/site/index.php?mem_id=1) which the member can direct their domain or friends to so they can see that members web page.

    I need the best solution (without putting a strain on the linux server) to redirect based on the mem_id and style_id so that the member web site appears and the site style the member has set.

    I had hoped this would work:

    header('Location: '.echo $resArray['mem_des']. '/index.php?mem_id='.$mem_id.'');

    but of course I have code before the header that pulls the member info and I know the header should come first. Perhaps I should put the pulled info into a variable and call it in the header somehow?

    Any code ideas you have would be great.

    Pie (worn out intermediate php coder).

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    EDIT ...

    I read your post wrong, so I'm changing my answer.

    Is the "profile" site information for your members saved in a table, like a members profile?

    When any person adds ?mem_id to the URL, it will save that in a SESSION.
    Then as the person navigates the site, they will be accessing the headers, banners, colors, fonts,
    from the member's profile ... because it can query your database with the mem_id session variable.

    So, after the session variable is set, you no longer need to have that variable added to the URL.
    Only the first time it's accessed does it need to know the mem_id.

    You could just as easily use a person's name too ... or a "username".


    .
    Last edited by mlseim; 01-06-2010 at 05:37 PM.

  • #3
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks......

    Re: Is the "profile" site information for your members saved in a table, like a members profile?...

    ...Yep, and it pulls the member info from this based on mem_id that's passed. But I am a little confused, what would the header redirect code look like? I'd like to try anything you can show me.

    Thanks mlseim.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    PHP Code:
    header('Location: '.$resArray['mem_des']. '/index.php?mem_id='.$mem_id); 
    That should work but that also depends on what the field mem_des holds.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    The very top of your "index.php" file, you will look for the URL variable,
    and also check for an existing session ...

    You would give them a link like this: mysite.com/site/index.php?mem_id=234
    PHP Code:
    <?php
    session_start
    (); // This is the first line, you'll be using PHP SESSIONS

    // Look for the URL variable
    if(isset($_GET['mem_id'])){
    $mem=$_GET['mem_id'];
    }

    // Check for an existing session ... if it's already started, then use the session instead.
    if(isset($_SESSION['MemberID'])){
    $mem=$_SESSION['MemberID'];
    }
    else{
    // The session has not been started, so set it and restart the page.
    $_SESSION['MemberID'] = $mem;
    header ("location: index.php");
    }

    // Now you have a session set, you can see the member's ID any time you want.

    // Say you have a banner or header that is named with the member's ID number,
    // Example:  header_234.php

    // Start the HTML output ...
    echo"
    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">
    "
    ;

    // include the correct header
    // or query your database here and pick out the correct header based on $mem (the user's id) ...
    $header "header_".$mem.".php";
    include(
    $header);

    // do the same for body

    // do the same for any other content

    // end your page ...
    echo"
    </html>
    "
    ;

    ?>

  • #6
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys with your help its working.


    Pie.

  • #7
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually this has thrown up another issue and that is if the member changes the web design styles, I need the page that may have been bookmarked by a visitor to check the design style in use and redirect so the visitor sees the web design style the member has set.

    For example if the aboutus.php was bookmarked by a visitor, but the member changed the style choice (which means files in a different folder) I thought it might be a straight forward if else statement with header redirect:
    <?php header('Location: '.$resArray['mem_des']. '/aboutus.php?mem_id='.$mem_id); ?>

    But I can't get my head around the way the code should be written.

    I guess the code needs to check current web design style setting (not just on the index page but also for the aboutus and contactus pages) then redirect so even if one web design style is bookmarked, the code checks and redirects.

    Here are certain styles they may be directed to:

    memsite/styleone_green/index.php?mem_id=1
    memsite/styleone_red/index.php?mem_id=1

    Any code you could show me would help. Thanks.

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    hmmm ... you're right.
    If the visitor bookmarks one of the other member's pages,
    it won't know the mem_id when they return because the session will be gone.

    You could use cookies instead of sessions, but people delete their cookies sometimes.

    The only way I can think of, is that each member has their own directory,
    so any bookmarks will always have that unique URL with the directory indicated.
    Example www.memsite.com/234/aboutus.php

    In fact, if each member were given their own directory, that would solve almost
    all of the other problems as well. A visitor would stay within the members' directory
    the whole time, yet the scripts in all those members' directories would be using the
    same database and other stylesheets and templates as needed.

    The member's own directory referenced by either their mem_id or actual username?

  • #9
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks mlseim, but I think giving a directory to however many members (and there could be many) would not be efficient. I was thinking more like this...

    If the visitor had bookmarked this page:

    memsite/styleone_green/aboutus.php?mem_id=1

    and visits that page, the code on this page would need to check the mysql db for mem_id=1 and the web design style that has been set. Then either display (using else if statement presumably) memsite/styleone_green/aboutus.php?mem_id=1 (if 'styleone_green' web design style is what has been set by the member), or redirect to for example memsite/styletwo_red/aboutus.php?mem_id=1 (if 'styletwo_red' web design style is what has been set by the member).

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Then you'll have to attach that mem_id variable to EVERY URL you have.

    And you're correct ... every page (script) would need to check the database
    to figure out which style to use.

    In most situations, a user logs-in and uses the site. You can easily offer the
    correct styles because you know who is logged-in. In your case, ANY visitor
    will want to display a particular "members pages" without logging in. So, you have
    to constantly know which member's page style to display because you have no
    idea who the visitor is. Either by using separate directories, attaching variables
    to the URL each time, or making the visitor pick the member's page before they
    can view them ... which would disable the feature of bookmarking. A user would
    have to re-pick the member's page each time.

    I still think giving each member their own directory is the best way. It would only
    have to contain the pages that can be bookmarked (index.php, aboutus.php, contactus.php, etc.)

  • #11
    Pie
    Pie is offline
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your ideas mlseim. Much appreciated.

    I think as my site is separated into xhtml valid content pages and design (css), I will make some further changes to the files and target just the css changes rather than my current web design styles in separate directories. That way it doesn't matter what is bookmarked it's only the css that will change, index, aboutus and contact pages remain the same.

    Any future designs will be just a matter of css changes.

    Thanks again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •