Results 1 to 6 of 6

Thread: PHP Redirect

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    PHP Redirect

    I have a PHP page on my domain: http://dclamp.homtek.net/invite.php.

    i have it redirect to this page: http://www.rapidfriends.com/join_inv.php?member_id=94 only.

    I want it so that some one can put there ID in my domain and have it put it at the end. like this:

    They Visit: http://dclamp.homtek.net/invite.php?ID=91

    and it redirects to: http://www.rapidfriends.com/join_inv.php?member_id=91

    how do i do this?
    My usual boring signature: Something

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Redirect

    not sure what you're doing to redirect it, so you'll have to implement this yourself, but it should work fine.

    this goes into invite.php:

    PHP Code:
    //this is the base address to redirect to, minus the ID
      
    $redirect "http://www.rapidfriends.com/join_inv.php?member_id=";

      if(isset(
    $_GET['id']) && is_numeric($_GET['id'])){
        
    $redirect .= $_GET['id'];
      }

      
    //do the redirect stuff now to $redirect 
    was that what you were looking for?

    also, you might want to put the redirect stuff within the IF statement checking if the ID variable exists and is a number, that way if they open invite.php without '?id=#' in the URL it will do nothing.. or you could just make a default ID for it to redirect to.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Redirect

    Here is what i have. i got it from another Forum:
    PHP Code:
    <?php 
        $id 
    = (isset($_GET['ID'])) ? (int) $_GET['ID'] : 94
        
    header("Location: http://www.rapidfriends.com/join_inv.php?member_id=$id"); 
        echo 
    "<TITLE>Join RapidFriends Network</TITLE>";
        echo 
    "<A HREF='http://www.rapidfriends.com/join_inv.php?member_id=$id'>Click Here If Your Browser Does Not 
            Redirect You</A>"
    ;
        exit;
    ?>
    If it does not have an ID number i want it to echo "Please Enter a ID Number" with a textbox and submit button.

    how do i do that?
    My usual boring signature: Something

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Redirect

    this should work for you.
    PHP Code:
    <?php
      
    //this is the base address to redirect to, minus the ID 
      
    $redirect "http://www.rapidfriends.com/join_inv.php?member_id="

      
    $id = (isset($_GET['id'])) ? $_GET['id'] : "";

      if(
    $id != "" && is_numeric($_GET['id'])){ 
        
    $redirect .= $_GET['id']; 
    //    header("Location: " . $redirect);
        
    echo '<center><a href="' $redirect '">click here</a></center>';
      }else{
        if(
    $id != "" && !is_numeric($id))
          echo 
    "You must enter a numeric value<br><br>\n";
    ?>
    <form method="get">
      ID: <input type="text" name="id"><br><br>
      <input type="submit" value="Submit"
    </form>
    <? } ?>
    Like Archer? Check out some Sterling Archer quotes.

  5. #5
    Addicted Member
    Join Date
    Jan 2006
    Posts
    247

    Re: PHP Redirect

    I normally like to reserve my header commands for helpful things like sessions, cookies, and cache controls, so, I have developed a way to redirect without headers:

    PHP Code:
    <?
    function js_redirect($url="your_url", $seconds=your_time) { 
        echo "<script language=\"JavaScript\">\n"; 
        echo "<!-- hide from old browser\n\n"; 
         
        echo "function redirect() {\n"; 
        echo "window.location = \"" . $url . "\";\n"; 
        echo "}\n\n"; 

        echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n"; 

        echo "-->\n"; 
        echo "</script>\n";

        return true;
    }
    ?>
    Just set your seconds and URL at the top of the function, then use it as so:

    PHP Code:
    <?php
    js_redirect
    ();
    ?>



  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: PHP Redirect

    Quote Originally Posted by Seraphino
    I normally like to reserve my header commands for helpful things like sessions, cookies, and cache controls, so, I have developed a way to redirect without headers:
    I think now would be the perfect time to unlearn this nonsense. There's absolutely nothing wrong with using header() for redirects. On the contrary, it's the best technique by far, superior to using meta elements in the HTML and infinitely superior to using JavaScript to rewrite the browser URL, which is the most fragile method possible. (Just think of all the browsers with JS disabled.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width