Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    redirect to page using PHP

    Greetings

    how can I redirect my page to another using PHP? Using Javascript I can do this using the code window.location='mypage.php'. How can I do this using PHP??

    Thank you very much

    Sérgio

  • #2
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    PHP Code:
    <?php header("Location: [url]http://www.dniwebdesign.ca.tt[/url]"); ?>
    This should get what you were looking for.
    Last edited by dniwebdesign; 01-10-2004 at 07:17 PM.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Just fixing up the code above
    PHP Code:
    <?php 
    header
    ("Location: http://www.yourdomain.com/nextpage.php"); 
    ?>
    This must be above any lines of code which output anything to the browser, ie html

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    That's what I put. What happened to my code?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You forgot to uncheck that checkbox "Automatically parse URLs" beneath the reply textarea.
    De gustibus non est disputandum.

  • #6
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    oops
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One of my codingprinciples is "Code once, run forever".

    If you want to redirect to another page like you asked
    Using Javascript I can do this using the code window.location='mypage.php'. How can I do this using PHP??
    then you can better use the servervariables to automatically fill in the domain and path to the directory. Like

    PHP Code:
    header('Location: http://'.$_SERVER['HTTP_HOST']
                    .
    dirname($_SERVER['PHP_SELF'])
                    .
    '/mypage.php'); 
    If it's to a page in your site, but in another server, then you can still use the $_SERVER['HTTP_HOST'] , but after that, you need to enter the path, from the sites root on. Like
    PHP Code:
    header('Location: http://'.$_SERVER['HTTP_HOST']
                    .
    '/includes/images/mypage.php'); 

  • #8
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Minnesota
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When i was first using php i had trouble with header location because i failed to learn that you cannot output any html, text, or anything like that before you use header("Location: page.php");

  • #9
    New Coder
    Join Date
    Jan 2003
    Location
    Tulsa, OK
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are redirection immediately on a page then Header works fine. If you want to do a redirect anywhere else on the page I suggest using meta tags.
    Code:
    <meta http-equiv="refresh" content="15; url=http://www.url.com/file.php?antics=sure">
    Word.


  •  

    Posting Permissions

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