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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a little help with redirect

    i am very unfamiliar with web page design. i need a script that will do the following.
    --------------------------
    *redirect to a different page every X seconds
    *redirects in a targeted frame and repeats redirecting to a different url every X seconds
    *never repeats a url
    *reads the target url's from a text file
    **EXAMPLE: redirects to "http://webaddress/folder/?id="+"000000" with "000000" being the data from the text file
    ***end address being "http://webaddress/folder/?id=000000"
    *has a selection box to pick how many seconds before redirect

    Any body know of something like this or could write a quick script? if you could i'd appreciate it and if not thats cool too.

  • #2
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    you'll be best off with a server-side language to do the text reading but this will work too.

    Code:
     
    var urls;
    var redirectInterval = 5;
    var targetFrameIndex = 0;
    var cur_url = 0;
    var sourceFileUrl = "config/urllist.txt";
     
    function doRedirect(){
    window.frames[targetFrameIndex].document.location = urls[cur_url];
    cur_url = (cur_url + 1) % urls.length;
    }
     
    function processTextFile(){
        if(this.readyState == 4 && this.status == 200){
            urls = split(this.responseText, "\n");
            setInterval("doRedirect()", redirectInterval*1000);
        }
    }
     
    function setup(){
        var xhr = new (window.XMLHttpRequest?XMLHttpRequest():ActiveXObject("MSXML.XMLHTTP"));
        xhr.open("get", sourceFileUrl, true);
        xhr.onreadystatechange = processTextFile;
        xhr.send("");
    }
     
    window.onload = setup;
    most everything should be on target, the setting of the url for the frame though i'm not 100% on (usually don't work with frames). just make sure you don't end up making your frame go outside of your domain, if you do, you won't be able to access the document property of the frame, giving an error & terminating the script.

    file format would be like:
    Code:
    
    
    just seperate them by pressing the enter key
    Last edited by mjlorbet; 04-25-2008 at 01:50 AM.
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the help. maybe you can help me with the whole project. i'm using a text file as a database to log profile url's such as myspace and i want it to automatically go through a list of url's randomly and not repeat any.the text file database is updated with html and php and i got most of that working except i dont know how i can prevent duplicate entries. its all source code for different projects that i've stripped of features and modified. here's what i got do far
    ----------------------------------------------------------------
    index.php
    ==================================================
    <?php
    require_once('common.php');

    if (isset($_POST['submitBtn'])){
    // Get user input
    $username = isset($_POST['username']) ? $_POST['username'] : '';

    // Try to register the user
    $error = registerUser($username);
    }
    ?>

    <SCRIPT language=Javascript>
    <!--
    function isNumberKey(evt)
    {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
    }
    //-->
    </SCRIPT>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Simple Id</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="main">
    <?php if ((!isset($_POST['submitBtn'])) || ($error != '')) {?>
    <div class="caption">Register Id</div>
    <div id="icon">&nbsp;</div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="registerform">
    <table width="100%">
    <tr><td>Id:</td><td> <input class="text" name="username" type="text" onkeypress="return isNumberKey(event)" /></td></tr>
    <tr><td colspan="2" align="center"><input class="text" type="submit" name="submitBtn" value="Register" /></td></tr>
    </table>
    </form>

    <?php
    }
    if (isset($_POST['submitBtn'])){

    ?>
    <div class="caption">Result:</div>
    <div id="icon2">&nbsp;</div>
    <div id="result">
    <table width="100%"><tr><td><br/>
    <?php
    if ($error == '') {
    echo " User id was registered successfully!<br/><br/>";
    echo ' <a href="index.php">You can submit another id here.</a>';

    }
    else echo $error;

    ?>
    <br/><br/><br/></td></tr></table>
    </div>
    <?php
    }
    ?>

    </body>
    ==================================================
    common.php
    ==================================================
    <?php


    function registerUser($user){
    $errorText = '';
    if (strlen($user) < 6) $errorText = "Id must be six digits long.";



    // Check user existance
    $pfile = fopen("id.txt","a+");
    rewind($pfile);

    while (!feof($pfile)) {
    $line = fgets($pfile);
    $tmp = explode(" ", $line);
    if ($tmp[0] == $user) {
    $errorText = "That user id is already registered!";
    break;
    }
    }

    // If everything is OK -> store user data
    if ($errorText == ''){


    fwrite($pfile, "\r\n$user");
    }

    fclose($pfile);


    return $errorText;
    }


    ?>
    ======================================================
    which outputs the the text file id.txt which could look something like this
    ======================================================
    259762
    349537
    284697
    ======================================================
    thanks ahead of time
    (this script is to boost profile views, to use if you would register your id and open the refreshing script in a new window and let it run. you would be boosting other people's page views as they boost yours)

  • #4
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    hrm, this looks interesting... um, maybe just attach the files, there's a lot a lot of information in that post, could wrap the different regions inside code blocks too, it's just not readable (sorry :s)
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • #5
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here's the entire script, just unzip it wherever php is installed. if this doesn't help i've added you to msn if that would be easier Simple Id.zip


  •  

    Posting Permissions

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