www.webdeveloper.com
Results 1 to 8 of 8

Thread: help with script

  1. #1
    Join Date
    Mar 2006
    Posts
    24

    help with script

    trying to create a script that will redirect user to a new webpage based on the user's browser preference.


    dont know if this script is right is the write way to write one


    <? php

    header ('location: http://www.yahoo.com/' http://www.msn.com/' http://www.ask.com/' ) ;

    ? >

    or

    <?

    header ( "location: $_post [location]"); exit;

    ?>

    thanks

  2. #2
    Join Date
    Jan 2005
    Location
    Illinois
    Posts
    815
    PHP Code:
    <?

    header
    ("Location: ".$_POST["location"]);

    ?>
    This will redirect to whatever value is posted with the name "location". I'm not sure if that's all you're looking for, if not, pleace clarify.

    --Steve
    Save The Shirts!
    Don't overuse exclamation marks!!!!!!

  3. #3
    Join Date
    Mar 2006
    Posts
    24
    how about redirecting users to more than one location

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    You can only redirect to one location. You can have the location be a variable (as in b.b.'s post), but it will be incumbent upon you to write the logic that sets that variable's value. Not knowing what you mean by "based on the user's browser preference", I can't really suggest any specifics.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2006
    Posts
    24
    this is what my html code looks like
    <html>
    <head>
    <title>

    </title>
    </head>
    <body>

    <form method= "post" Action="do_redirect.php">

    <p>send me to:

    <select name="location">

    <option value= "http://www.msn.com/">msn</option>

    <option value= "http://www.expedia.com/">expedia</option>

    <option value= "http://www.microsoft.com/">microsoft</option>

    </select>

    <p><input type="submit" name="submit" value="Go!"></p>

    </form>
    </body>
    </html>


    so i am tryin to creat a script that will direct users to each of the option values not sure if u can do that, but thts what i am tryin to do

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    do_redirect.php:
    PHP Code:
    <?php
    // set location if provided from form, else set it to default page:
    $location = (!empty($_POST['location'])) ? $_POST['location'] :
                
    "http://your.site.com/index.php";
    // go to that page:
    header("Location: $location");
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Mar 2006
    Posts
    24
    thnks

    this is what i get when i out put the script


    Warning: Cannot modify header information - headers already sent by (output started at C:\root\do_redirect.php:2) in C:\root\do_redirect.php on line 7


    dont know what that mean just started learn php like 2 days a go

  8. #8
    Join Date
    Mar 2006
    Posts
    24
    Thanks for the script its working fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles