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 14 of 14
  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Refreshing using php

    Hi all,
    I am using a custom made script that im still making and i want to refresh to a page pulled from a mysql db but i want it to refresh a page that stored as a php variable.

    Any help welcome,

    Thanks
    Steven

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Well... technically... refreshing to a different page really isn't refreshing, it's redirecting.

    Have you tried just submitting a form using the destination URL in the "onpost"?

  • #3
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    No, i just want to redirect the user using a value pulled from a mysql database.

  • #4
    New Coder
    Join Date
    Apr 2006
    Location
    UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As long as nothing has been sent to the browser (no HTML, not even any blank spaces before the first <?php) then you can use the header() function to send a user to a different page.
    If you have the URL you want to send them to in a variable called $send_url, for example, then the code would be:
    PHP Code:
    <?php
    //NO BLANK SPACES OR HTML BEFORE FIRST TAG!

    //Code here...

    header("Location: ".$send_url);//Send them to $send_url
    ?>

  • #5
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    If something has been redirected to the browser you could use this function which uses HTML to redirect :
    PHP Code:
    function redirect($url$time){
                    echo 
    '<meta http-equiv="refresh" content="' $time '; url=' $url '" />';


  • #6
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    The thing is when i use a variable it says http://www.steven.com/tutorial/$url cannot be found.

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Paste your code.

    ~Phil~

  • #8
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?

    $user 
    "stevengi_tut";
    $password "cobra";
    $location "localhost";
    //only edit location if you have been told to do so.
    $db "stevengi_script";
    mysql_connect("$location""$user""$password");
    mysql_select_db("$db");

    // 1. Clean $_GET vars first 
    $tutorial = (int) $_GET['tutorial']; 
    $select mysql_query("SELECT * FROM tutorials WHERE id = '$tutorial' LIMIT 1");
    while(
    $row mysql_fetch_array($selectMYSQL_ASSOC)) {
    $url2 $row['url2'];
    }
            
    ?>

  • #9
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    There is no redirection code in there.

    ~Phil~

  • #10
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    well should this work? It doesnt.
    PHP Code:
    <?

    $time 
    "2";
    $user "stevengi_tut";
    $password "cobra";
    $location "localhost";
    //only edit location if you have been told to do so.
    $db "stevengi_script";
    mysql_connect("$location""$user""$password");
    mysql_select_db("$db");

    // 1. Clean $_GET vars first 
    $tutorial = (int) $_GET['tutorial']; 
    $select mysql_query("SELECT * FROM tutorials WHERE id = '$tutorial' LIMIT 1");
    while(
    $row mysql_fetch_array($selectMYSQL_ASSOC)) {
    $url2 $row['url2'];
    echo 
    '<meta http-equiv="refresh" content="2; url=. $url .">'
    }
            
    ?>

  • #11
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I get:
    http://www.stevengibbons.com/tutorial/.%20$url%20.

    The page cannot be found
    The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

    --------------------------------------------------------------------------------

    Please try the following:

    If you typed the page address in the Address bar, make sure that it is spelled correctly.

    Open the www.stevengibbons.com home page, and then look for links to the information you want.
    Click the Back button to try another link.
    Click Search to look for information on the Internet.



    HTTP 404 - File not found
    Internet Explorer

  • #12
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well, that is a silly way to do it, but if you insist on it, the line should read...

    echo '<meta http-equiv="refresh" content="2; url=' . $url . '">';

    The better way to do it would be:

    header("Location: " . $url);

    Also, your query says $url2, and your redirect line says $url. You need to decide which it is.

    ~Phil~

  • #13
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I have fixed both and its still not working and im getting the same error.

  • #14
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Paste new code.

    ~Phil~


  •  

    Posting Permissions

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