Dynamically creating URLS based on user input !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lunny
Forum Newbie
Posts: 13
Joined: Mon Feb 19, 2007 8:33 am

Dynamically creating URLS based on user input !

Post by lunny »

Hi,

I am looking to create pages on the fly or dynamically based on user input. For example if i have http://www.example.com and they visit this and enter 'bob' in a textfield and press submit they create http://www.example.com/bob.html . How would I go about this ? I am guessing I need to create a folder when submit is pressed in my website directory ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Avoid dynamically generating files. Aim for dynamically filling their request for the files. mod_rewrite can be used for this.
lunny
Forum Newbie
Posts: 13
Joined: Mon Feb 19, 2007 8:33 am

Post by lunny »

ah yes will read about mod-rewrite

But lets just say to ease my mind how would i dynamically create URLs ?
lunny
Forum Newbie
Posts: 13
Joined: Mon Feb 19, 2007 8:33 am

Post by lunny »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


When i try to do the following

Code: Select all

$filename = '.../public_html/newFile.php ';
$mytext = 'text';



fopen($filename, 'w+');
fwrite($filename, $mytext);
fclose($filename);
..

i get

Warning: fopen(../public_html/newFile.php ) [function.fopen]: failed to open stream: Permission denied in /public_html/test.php on line 19

Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/test.php on line 20

Warning: fclose(): supplied argument is not a valid stream resource in /public_html/test.php on line 21

How do I solve these problems with my permission


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

I'm no Guru, but that doesn't seem like a PHP problem.

I would check to see if the user running apache (usually "apache") has permission to write to the folder public_html. That could be the problem.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are probably going to have to open that directory by assigning it a permission of 666 or even 777. Either way, having writable directories on your server is insanely dangerous if your are not careful of what is going to be written to it.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

fopen($filename, 'w+');

the 'w+' should be "w+" (double quotes)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

scottayy wrote:fopen($filename, 'w+');

the 'w+' should be "w+" (double quotes)
They both result in the same string last I checked.
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

Everah wrote:You are probably going to have to open that directory by assigning it a permission of 666 or even 777. Either way, having writable directories on your server is insanely dangerous if your are not careful of what is going to be written to it.
Please correct me if I'm wrong, but I don't think that he needs to open the directory that much. If owner is apache and group is root (for example...) then 664 or 774 will suffice and that would be a bit more secure.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think you are right. But I have a thing with not opening up directories for writing from unknown sources. That is just me.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

for some reason when creating a new file to write to, PHP often suffers from this error. The solution in at least 30% of the cases I've come across it to touch(the.file) first - then everything works as advertised.
Post Reply