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 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP symlinks - not sure what's happening

    I'm trying to code a page which will create a symbolic link to itself, so that when that link is clicked on it will open the same page as is currently displaying, but with a different URL. The results of the symlink operation are baffling me.

    PHP Code:
    <?php

    $referer 
    $_SERVER["HTTP_REFERER"];
    $current $_SERVER["PHP_SELF"];

    echo 
    "The current page we are on is: $current<br>";
    echo 
    "The page we came from was: $referer<br>";

    $next_doc substr(md5(rand(0,9999)),3,4).".php";

    echo 
    "The doc we are going to next is: $next_doc<br>";

    $status symlink($current$next_doc);
    if (
    false !== $status) {
       echo 
    "Created $next_doc - ready to link to it.<br>";
        } else {
       echo 
    "Failed to create $next_doc<br>";
    }

    echo 
    "<a href=\"$next_doc\">Link to new doc</a>";

    ?>
    When this is run, the output looks like this:

    Code:
    The current page we are on is: /test/test.php
    The page we came from was:
    The doc we are going to next is: e58c.php
    Created e58c.php - ready to link to it.
    Link to new doc
    That last line is a link, as intended, and it points where I intended it to; a randomly named file in the current directory.

    The file is created, it's the identical size of the current file, it has the same protections, everything looks like it should work fine, but all I get is a "page not found" error.

    I thought a symbolic link was supposed to be a way to access a file via a shortcut or alternate path. In my case, it appears to be making an exact duplicate of the file, even down to the having the same MD5SUM value. The only difference is that the new page won't load, even if typed in directly as a URL.

    Any clues what I'm doing wrong, or misunderstanding? I suspect there are multiple misunderstandings going on concurrently here!
    Last edited by RTrev; 04-01-2007 at 04:44 AM.
    Think slow, type fats

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I tried this
    PHP Code:
    $referer $_SERVER["HTTP_REFERER"];
    $current $_SERVER["PHP_SELF"];

    echo 
    "The current page we are on is: $current<br>";
    echo 
    "The page we came from was: $referer<br>";

    $next_doc substr(md5(rand(0,9999)),3,4).".php";

    echo 
    "The doc we are going to next is: $next_doc<br>";

    if (!
    symlink($current$next_doc)) {
        echo 
    "Failed to create $next_doc<br>";
    } else {
        echo 
    "Created $next_doc - ready to link to it.<br>";
    }

    echo 
    "<a href=\"$next_doc\">Link to new doc</a>"
    It created a "link" to the file, but when I try to access it, I get a Forbidden message since I have my server configured in that manner. But the code worked as expected. It shouldn't create a duplicate file. Are you on a linux or windoz box?

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi iLLin,

    I'm on a Linux system, hosted by 1&1. Your mention of the server configuration reminded me of an .htaccess option of +FollowSymLinks but I found it was already turned on in my .htaccess. I tried turning it off, but still the same problem.

    So, the code is okay.. I just need to figure out if I can get the server to allow it to work..

    Thanks!

    Bob

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    A symbolic link should have the same MD5 checksum as the original file, so it should look to all external calls (like the internal php stat() calls) as if it were the linked file, try a call to is_link() or linkinfo() to see if the file is really a symbolic link or not.

    Then try chmodding the link to say 0775 or 0777 to see if that makes it visible (remember the link is owned by PHP or the webserver)

    as a last resort, exec the unix call <?exec('ln -s file.txt file_link.txt');?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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