LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2005, 10:33 AM   #1
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Rep: Reputation: 15
noob php question


if i want a variable to = the name of the folder the script is placed in, how would i write that?

script is in : /var/www/html/userz/joe/

and i want the username to be 'joe'


any help offered is appreciated.

i thought the code below would work but it didnt



PHP Code:
$username '/var/www/html/userz/ . dirname'

Last edited by verbatim; 04-30-2005 at 12:39 PM.
 
Old 04-30-2005, 11:26 AM   #2
xrado
Member
 
Registered: Dec 2004
Distribution: Zenwalk/Slackware
Posts: 98

Rep: Reputation: 15
can you rephrase your question...
 
Old 04-30-2005, 12:38 PM   #3
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
i have a php script with a $username variable in it .

i would like for username to reflect the pathto the folder the script is in.

i thought the code below would work but it didnt

PHP Code:
$username '/var/www/html/userz/ . dirname'
 
Old 04-30-2005, 12:54 PM   #4
xrado
Member
 
Registered: Dec 2004
Distribution: Zenwalk/Slackware
Posts: 98

Rep: Reputation: 15
do you mean $PHP_SELF

$PHP_SELF variable contain the path to script you are running

what is this dot doing in your string?

still dont understant what you are trying to do
 
Old 04-30-2005, 01:22 PM   #5
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
sorry for explaining it wrong.

what i meant to say was, if thephp file is in a folder called 'joe'

how can i make a script that says $username = this folder

so that if the folder is 'joe' - $username = joe
will appear.

or if the folder the script is in is melissa
$username = melissa
 
Old 04-30-2005, 06:17 PM   #6
ilhbutshm
Member
 
Registered: Jul 2003
Location: Europe
Distribution: Slackware 10.2
Posts: 104

Rep: Reputation: 15
I guess this is it:
PHP Code:
<?php

    $public_path 
$_SERVER["REQUEST_URI"];
    
$public_path substr($public_path1);
    
    
$array explode("/"$public_path);
    
    
$num_elemnt count($array);
    
    
$num_elemnt $num_elemnt 2;
    
    
$username $array[$num_elemnt];
    echo 
'USERNAME: '.$username;

?>
You'll probably want to make a function out of this... (;

Last edited by ilhbutshm; 04-30-2005 at 06:19 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help!!! desperate noob in Apache/php/MySQL (Triad) backroger Linux - Newbie 1 12-15-2004 06:27 AM
Help!!! desperate noob in Apache/php/MySQL (Triad) backroger Linux - Software 0 12-11-2004 07:37 AM
Complete noob question from a noob noob_hampster Linux - Software 2 09-04-2003 12:03 AM
noob php question centr0 Programming 3 05-12-2003 03:46 PM
nooB ?, install: apache, PHP, postgreSQL and wine mrMahann Linux - Software 4 08-28-2002 12:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration