SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    redirect by using url parameter info

    i'm trying to create a page that takes two url parameters,(I'll call it test.php), and then pushes the user to a specific page bases on the url parameter.

    recordid1=1
    recordid99=7.php

    recordid1 represents a contact id
    recordid99 is the page that the user will get submitted to.

    so a link anywhere in the site might look like this:

    testing.php?recordid1=1&recordid99=7.php

    the user doesn't need to see anything on the redirect page they just need to get redirected to 7.php and include the recordid1 url paramter

    is this possible? or is it better to use something other than javascript?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I think that this should work:

    Code:
    <script type="text/javascript">
     var queryString = location.search.substring(1);
     var variables = queryString.split('&');
     var urlVars = new Object();
     for(i = 0; i < variables.length; i++) {
       var eqChar = variables[i].indexOf('=');
       urlVars[variables[i].substring(0, eqChar)] = variables[i].substring(eqChar+1);
     }
     
     window.location.href = urlVars.recordid99;
    </script>
    /Erik

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > or is it better to use something other than javascript?

    just do the redirect with php:

    PHP Code:
    $url=$_SERVER['HTTP_HOST'].'/'.$pathTo.'7.php';
    header("Location: ".$url."?recordid=".$_GET['recordid']);
    exit(); 


Bookmarks

Posting Permissions

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