www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: redirect using get['page'] file.php?page=xx

  1. #1
    Join Date
    Nov 2003
    Posts
    28

    redirect using get['page'] file.php?page=xx

    hi how could i do this using get()

    say have a page with 10 links on it

    l1
    l2
    l3
    ...
    l10

    and the php code in need is on page.php so
    each link has a href="page.php?page=lx

    x being 1 - 10 and that would take them to the respective page,

    i hope ive made what im trying to do clear and havnt confused anybody

    Thanks Alot

  2. #2
    Join Date
    Nov 2002
    Posts
    421
    If I understand what you want . . .

    $newpage = $_GET['page'];
    header("Location: $newpage.htm");

  3. #3
    Join Date
    Nov 2003
    Posts
    28
    ok thanks, and if no page in header =blank ie nothing, what would be displayed how could i get it to do a default page, say index.php?

    Thanks for your help

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    PHP Code:
    if(isset($_GET["page"]))
     { 
    $page $_GET["page"]; }
    else
     { 
    $page "index.php"; }

     
    header("Location: $page"); 
    [J]ona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  5. #5
    Join Date
    Nov 2003
    Posts
    28
    ok thanks jona last thing, so if link was page.php?page=games, this would try taking you to games but i want it to to games.php

    would i make this
    header("Location: $page");

    equal header("Location: $page.php"); ??

    Thanks again

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    PHP Code:
    if(isset($_GET["page"]))
     { 
    $page $_GET["page"] .".php"; }
    else
     { 
    $page "index.php"; }

    if(
    file_exists($page))
     {
      
    header("Location: $page");
     } 
    [J]ona
    Last edited by Jona; 03-25-2004 at 08:33 PM.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #7
    Join Date
    Nov 2002
    Posts
    421
    Originally posted by richiet85
    [B]header("Location: $page.php");[ /B]
    This should also work fine.

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Beach Bum
    This should also work fine.
    But you'll need to change $page = "index.php" to $page = "index" for it to work properly, and also have to use if(file_exists($page.".php")) to ensure the file being included actually exists.

    [J]ona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  9. #9
    Join Date
    Nov 2003
    Posts
    28
    ok thankis guys this is what i have so far

    PHP Code:

    if(isset($_GET["link"])) 
     { 
    $link $_GET["link"];."/" 
    else 
     { 
    header("Location: "http://www.google.com/"; } 

    if(isset($_GET["page"])) 
     { 
    $page $_GET["page"];."/" 
    else 
     { 
    $page ""; } 

    if(
    file_exists($link)) 
     { 
      
    header("Location: "sections/".$link.$page."index.html"); 
     } 
    is there anything wrong with this code?
    what i want to do now i thought i could jst adapt jona version to get double

    say the link was
    page.php?link=space&page=01

    this should generate a href="sections/space/01/index.html" am i correct? please say yes

    RR

  10. #10
    Join Date
    Jan 2004
    Posts
    72
    PHP Code:
    <?php
    if(isset($_GET["link"])) 
     { 
    $link $_GET["link"] . "/"; } 
    else 
     { 
    header("Location: "http://www.google.com/"; }

    if(isset($_GET["page"])) 
     { 
    $page $_GET["page"] . "/"; } 
    else 
     { 
    $page ""; } 

    if(
    file_exists($link)) 
     { 
      
    header("Location: sections/".$link.$page."index.html");
     }
    ?>
    Try that instead.

  11. #11
    Join Date
    Nov 2003
    Posts
    28
    i realised my mistake after posting thanks scott but now i dont get a parse error i think its working but the server is down as its not loading any files from this link, even if i go to hp it still doesnt work, yet ftp does, and so does this file loads, i dont know gotta test once i find out wtf happened to it and why sites arnt loading, thanks, let you know if it doesnt work, im sure it will tho, thanks guys

  12. #12
    Join Date
    Nov 2003
    Posts
    28
    nope doesnt work, go to page.php i directs me to google, if i go to say

    page.php?link=space&page=01

    i doesnt go anywhere should go to

    sections/space/01/index.html

    what version of php would i need to use this script just an idea why it doesnt work, or could be the coding is wrong? im confused becuase it looks like it should work, but doesnt

    Thanks for help again

  13. #13
    Join Date
    Nov 2003
    Posts
    28
    ok this is what i have so far works, jst doesnt redirect if you go to page.php, dont need to worry bout if say page=something that dont exist, tihs is what im using atm

    <?php

    if(isset($_GET["page"]))
    { $page = $_GET["page"] ."/"; }
    else
    { header("Location: http://www.google.com/"); }

    if(isset($_GET["link"]))
    { $link = $_GET["link"] ."/"; }
    else
    { header("Location: http://www.google.com/"); }

    header("Location: sections/".$page.$link."index.html");

    ?>

    ty

  14. #14
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I'm sorry, but frankly that was very difficult to understand. Is your problem solved?

    [J]ona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  15. #15
    Join Date
    Nov 2003
    Posts
    28
    ok sorry the above code is what i currently have saved in page.php, if you go directly to this page.php it doesnt redirect to www.google.com, thats all i need to sort. Thanks Jona

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