SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    automatical redirecting to another web page

    The following would-be code doesn't work correctly, but it will show what I want.
    Code:
    would-be code
    
    if (1 == 1) {    redirecting to YES.PHP;} 
    else {    redirecting to NO.PHP;}  
    
    
    result
    
    displaying YES.PHP
    How can I write for making it to redirect automatically to YES.PHP?

  2. #2
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you have 2 different options. One would be using php header function as long as you are not outputting any data to the browser yet.
    PHP Code:
    if ($_GET['answer']=='Yes') {
        
    header('Location: http://www.sitepoint.com');
        exit;
    } else {
        
    header('Location: http://www.google.com');
        exit;

    Or you can use the html meta tag.

    PHP Code:
    if ($_GET['answer']=='Yes') {
        echo 
    '<meta http-equiv="refresh" content="0;url=http://www.sitepoint.com">';
        exit;
    } else {
        echo 
    '<meta http-equiv="refresh" content="0;url=http://www.google.com">';
        exit;

    Now any time you go to yourpage.php?answer=Yes you will be redirected to Sitepoint. Any other variation of answer or no answer you will be redirected to google.

    Hope this helps.
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers


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
  •