Results 1 to 9 of 9

Thread: help in meta refresh tag

  1. #1
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy help in meta refresh tag

    hi
    i need to kno if meta refresh tag can be stopped automatically after a certain amount of time..i want my page to be refreshed after every 10 sec ten times after which the page should be redirected to another page..
    can some1 pls help..
    it'll be appreciated a lot..
    thanks ain advance..suk

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There is no talking between the pages. Each page is independant. To make it change on different loads (as in having a new behavior on the reload), you would need to implement some code that would keep track of it. I think the best idea would be to use PHP. Javascript might work, but that's hard to make it talk between pages. You could also use cookies with either, but I don't know if that's needed.

    Here are two solutions:

    PHP Code:
    <?php
    $n 
    $_GET['n']-1;
    if (!isset(
    $_GET['n'])) {$n=10;} //10=number of refreshes
    if ($n 1) {$url 'http://this.com/other.htm';} //page to redirect to at end
    else {$url 'http://this.com/this.php?n='.$n;}
    echo 
    '<meta http-equiv="refresh" content="10;url='.$url.'">'//10=seconds for each refresh
    ?>

    //OR...

    <?php
    $n 
    $_COOKIE['reload']-1;
    if (!isset(
    $_COOKIE['reload'])) {$n=10;}
    setcookie('reload',$n,time()+15); //see note below
    if ($n 1) {$url 'http://this.com/other.htm';}
    else {
    $url 'http://this.com/this.php';}
    echo 
    '<meta http-equiv="refresh" content="10;url='.$url.'">';
    ?>

    The 15 second (after current time) expiration on the cookie
    allows for more than 10 seconds, but it will expire to help
    prevent reloading the page starting partway through the cycle.
    Set this about 5 seconds longer than the refresh delay (currently 10).
    Hope this helps.

    The cookie solution requires cookies enabled; the first version will have a variable in the address bar. Both require PHP installed/enabled on the server (independant of the user), and also may have issues (different for each) with refreshing the pages, etc. in the middle of the cycle.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't think you can do that with meta refresh. Every ten seconds, sure. But, there is no way to pass along to the next load a count of how many times this is taking place. Javascript can do that though, put this script in the head of your page:

    Code:
    <script type="text/javascript">
    function get(key_str) {
    var query = window.location.search.substr(1);
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
    var pair = pairs[i].split("=");
    if(unescape(pair[0]) == key_str)
    return unescape(pair[1]);
    }
    return '0';
    }
    if(get('ld')*1<101)
    setTimeout("window.location.replace(window.location.href.split('?')[0]+'?ld='+[get('ld')*1+10])", 10000);
    else
    window.location.replace('http://www.dynamicdrive.com/');
    </script>
    You probably should also include for non-javascript enabled browsers a meta refresh tag with the final destination:

    HTML Code:
    <meta http-equiv="refresh" content="100;url=http://www.dynamicdrive.com/">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks..
    but let me explain my problem further..
    i am doin this for an online exam.
    my page called random.php has to list questions from database every10 sec.these questions are generated by random numbers
    $sql=mysql_query("SELECT * FROM question WHERE id='$random_digit'");
    every 10 sec the is to be refreshed and new random num generated and thus new query gets executed.after 10 such queries being executed the page shud be redirected to a page upload.php

    where do i place the code? i am posting my code so far..if only u cud help me..
    sorry for the trouble n thanks for the help..


    <?php
    $n = $_GET['n']-1;
    if (!isset($_GET['n'])) {$n=10;} //10=number of refreshes
    if ($n < 1) {$url = 'http://this.com/uploadmain.php';} //page to redirect to at end
    else {$url = 'http://this.com/this.php?n='.$n;}
    echo '<meta http-equiv="refresh" content="5;url='.$url.'">'; //10=seconds for each refresh
    include 'db.php';
    $maximum=mysql_query("select MAX(id) as max from question");
    $chk = mysql_num_rows($maximum);
    $u = mysql_fetch_array($maximum);
    $max=$u['max'];
    //echo "maximum=" . $max;
    $minimum=mysql_query("select MIN(id) as min from question");
    $chk1 = mysql_num_rows($minimum);
    $r = mysql_fetch_array($minimum);
    $min=$r['min'];
    //echo "minimum=" . $min. "<br>";
    $random_digit=rand($min,$max);
    echo $random_digit;

    $sql=mysql_query("SELECT * FROM question WHERE id='$random_digit'");

    $count=mysql_num_rows($sql);
    if ($count>0)
    $valid=true;
    if ($valid)
    {
    echo "<table width='95%' border='2'>
    <tr>
    <th>QUESTION</th>
    <th>#</th>
    <th>OPTION 1</th>
    <th>#</th>
    <th>OPTION 2</th>
    <th>#</th>
    <th>OPTION 3</th>
    <th>#</th>
    <th>OPTION 4</th>
    </tr>";
    for ( $counter = 1; $counter <= 10; $counter += 1)
    {
    while($row = mysql_fetch_array($sql))
    {
    echo "<tr>";?>
    <?
    echo "<td>" .$row['quest'] . "</td>" ."<br>";
    ?>
    <td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
    <?
    echo "<td>" . $row['opt1'] . "</td>" . "<br>";?>
    <td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
    <? echo "<td>" . $row['opt2'] . "</td>" . "<br>";?>
    <td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
    <? echo "<td>" . $row['opt3'] . "</td>" . "<br>";?>
    <td align="center"> <input type="radio" name="group1" id="<?=$row[id]?>" value="<?=$row[id]?>" /> </td>
    <? echo "<td>" . $row['opt4'] . "</td>";
    echo "</tr>";
    }
    }
    echo "</table>";
    }
    ?>

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This code outputs a meta tag. As with any meta tag, it must be placed in the head section, not in the body.
    Use two seperate bits of PHP.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ya i think i would be more comfortable with using php..but this thing is not workin..mayb the placement of my code is wrong or somethin...can ya look into the code i hv posted n lemme kno whts wrong...
    plsss
    thanks

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    We were posting out of order (due to time writing posts), so I edited my post above. It has the info you need, I believe.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    its not working!!!! i dont know where i am goin wrong now....

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Do you have a link to your page so we can see it?

    Simply put, an html document looks like this:
    <html>
    <head>
    HEADERS, etc. HERE (...the meta tag)
    </head>
    <body>
    CONTENT HERE
    </body>
    </html>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •