Jump to content

Directory Name


timmah1

Recommended Posts

$_SERVER['PHP_SELF'] will give you the folder and script in reference to to the domain

I do not think there is a function to return just the folder you are in, but here is something you could use
[code]<?php
function directory($dir){
$folder = substr($dir, 0 ,strpos($dir, strrchr($dir, "/")));
return $folder;
}
echo directory($_SERVER['PHP_SELF']);
?>[/code]

Ray
Link to comment
Share on other sites

Great! Thanks.

Now that I have it stating the directory, how do I carry that value to an sql statement?

I keep getting errors, most likely have something backwards, but I'm really not sure.

Here's the code
[code]
$sql = "SELECT * FROM users WHERE username = '{directory($_SERVER[PHP_SELF]}'";
$result = mysql_query($sql);
while($row = mysql_fetch_array( $result )){
    echo $row[email];
echo $row['email'];
   
}
[/code]

I'm not getting the email value pulled out.

Anyone have an idea?

Thanks again
Link to comment
Share on other sites

you can do 2 things, put the value into a variable or come out of your sql statement.

[code]$dir = directory($_SERVER['PHP_SELF']);
$sql = "SELECT * FROM users WHERE username = '$dir'";[/code]
or
[code]$sql = "SELECT * FROM users WHERE username = '".directory($_SERVER['PHP_SELF'])."';[/code]

Ray
Link to comment
Share on other sites

I'm sorry to keep bothering you, because you have been awesome!


I'm only having one small problem, when the directory is selected, it's putting a "/" in front of it, that's why it can't pull the info from the database.

How do I get rid of the "/" in front of the $dir?
Link to comment
Share on other sites

ted_chou12,

Please don't 'hijack' threads.  You made a post relating to this yesterday which I replied to.

Did you even try what I suggested yesterday in your other post, you haven't updated it, so are we to assume you haven't?  If so, why are you still seeking solutions when you may already have what you need?  If you have and it didn't work, then please post back in the original thread ([url=http://www.phpfreaks.com/forums/index.php/topic,118583.0.html]problem with listing root directories (UN~SOLVED)[/url])

Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.