Same page, same codes, different names every time, how to ?

Discussion in 'PHP' started by leet, Nov 21, 2006.

  1. #1
    Let's say I have a page called ABC.php. I want this file's name to change everytime someone goes to the page randomly according to a keywords.txt. Is it possible to do this with PHP, how, or should I use .htaccess? If so, how? The code I'm using right now is like the following;

    $pages = file("kwbase.txt");
    $kw = array_rand($pages);
    $page = $pages[$kw];
    header("Location: $page");
    PHP:
    But this loads URLs, not keywords and also pretty slow. So I have to copy the page and rename it hundreds of times which would be a pain in the ass. I hope there is a way to make it easier :eek:
     
    leet, Nov 21, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    How many lines are in that file?

    I cant think of a faster way of doing it.

    You can combine the bottom 2 lines, but that's not going to make a huge difference.
     
    jestep, Nov 21, 2006 IP
  3. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I cannot imagine exactly what you are trying to accomplish. The biggest issue you face is that people access known URLs. This means that a link must exist to the page before someone would consider accessing it -- whether on another page, their favorites or in their imagination.

    Using .htaccess you can easily redirect queries for ABC.html to DEF.html, but the file needs to know how to do the redirect.

    Another option is to have .htaccess redirect all page queries to a script, which knows what to do, but that is still not the same as accessing ABC.html and getting XPF.html. Under this option, the page does not need to exist. It is constructed by the script as requested.

    .htaccess rewrite example:

    RewriteEngine on
    RewriteRule ^(.*)\.html$ /scripts/showstory.php?$1 [L]
    Code (markup):
    With this option you could create "linkify" a list of keywords as your pages are displayed to the visitor. If they click on the keyword, they are then transported to a page, which is constructed on the fly to provide whatever data you have available about that keyword, including whatever dynamic data you are also trying to generate.
     
    clancey, Nov 21, 2006 IP
  4. leet

    leet Notable Member

    Messages:
    3,423
    Likes Received:
    369
    Best Answers:
    0
    Trophy Points:
    250
    #4
    About 55-60 pages I guess.

    Well, actually the following .htaccess was doing what I wanted, but I dunno how to set it up with my new script;

    AddHandler application/x-httpd-php html
    AddHandler application/x-httpd-php htmOptions
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)-(.*)-(.*).html$ /search.php?q=$1+$2+$3
    RewriteRule (.*)-(.*).html /search.php?q=$1+$2
    RewriteRule (.*).html /search.php?q=$1
    PHP:
     
    leet, Nov 21, 2006 IP