Need little help wt PHP

Discussion in 'PHP' started by ignas2526, Aug 19, 2008.

  1. #1
    Hello,
    the thing i trying to do is to add to index.php file code what will check for cookie and depending on it will redirect:
    if (isset($_COOKIE["welcomepage"]))
      header("Location: ./index.php?welcome"); 
    else
      header("Location: ./index.php?mainpage"); 
    if ($_SERVER["QUERY_STRING"] == "welcome"){
      setcookie("welcomepage", "view", time()+43200);
    echo "Welcome!.";
    }
    PHP:
    but what causes "Redirect Loop", because all other pages are in same index.php , ore included. my goal is to make page what will look like all is in one index.php and all other pages will be index.php?something , cuz not all pages will be really in index.php, whey will be included.
    So any ideas how to fix what problem?
     
    ignas2526, Aug 19, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    why not changing ?mainpage to ?page=mainpage, so you can check if $_GET['page'] is used before you do a redirect!

    for example
    
    if (!isset($_COOKIE["welcomepage"]))
    {
        // display first screen and add cookie
        setcookie("welcomepage", "view", time()+43200);
        echo 'hello world';
    }
    else
    {
        switch ($_SERVER['QUERY_STRING'])
        {
            case "welcome":
            break;
            
            default:
            break;
        }
    }
    
    Code (markup):
     
    EricBruggema, Aug 19, 2008 IP
  3. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, all works fine, thanks!
    But if user will just view index.php...
    because all in $_SERVER['QUERY_STRING']
    if i add redirect, it will cause redirect loop, because what code i will add will be everywhere!
    Any ideas?
     
    ignas2526, Aug 19, 2008 IP
  4. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nevermind, forgot about default: in switching...
    Thanks for help.
     
    ignas2526, Aug 19, 2008 IP
  5. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    oki... a small tip... try using htaccess to get nice seo friendly urls :D
     
    imphpguru, Aug 19, 2008 IP
  6. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for tip imphpguru, but in nvm in htaccess construction, what is "seo friendly urls"???
     
    ignas2526, Aug 19, 2008 IP
  7. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    well basically, SEO Friendly URLs are, something like instead of

    xxx.com/index.php?page=xxx

    They will be

    xxx.com/page/xxx

    An example that I have used is at freebetsgalore.com. Have a look at the urls. All those pages dont actually exist, but it appears in the urls as if they are actual pages / directories.
     
    imphpguru, Aug 19, 2008 IP
  8. LaZyBuM™

    LaZyBuM™ Peon

    Messages:
    183
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    use index.php?page=xxx instead of index.php?xxx lol :D
     
    LaZyBuM™, Aug 19, 2008 IP
  9. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    damit, and why is better to use index.php?page=xxx instead of index.php?xxx ???
    you mean longer urls are better?
     
    ignas2526, Aug 20, 2008 IP
  10. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #10
    Eh! Not really that... see page=xxx is available through $_GET['page'] while for ?xxx, you will have to iterate through teh $_GET varaible. This is the standard method used by most of the programmers :)


     
    imphpguru, Aug 22, 2008 IP