FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP, FORM HELP





Relentless
Hi, I am using frihosts ability to protect folders.

And I have protected more than one for diffrent people to acces with there own area in.

All I want is to have a php script that i enter a username and it goes to the URL of that user.

Bacically.


e.g. Joe bloggs comes along. His protected folder which only he has the pword 2 is www.mydomain.frih.net/joes/

but i want a webpage which has a text field on it and they enter there username (joe) and it goes to www.mydomain.frih.net/joes/

Same with e.g. sam types in her username (sam) goes to www.mydomain.frih.net/sams/

but thats all i want i dnt want a paswrd entry they can do that on demand when www.mydomain.frih.net/thierPasswordedAreaLoads/

wb thanks daniel
sonam
If I good understand you want to redirect each user on their site where he/she will use own password for login?

Code:
<?php
$username = @$_POST['username'];
if($username != "") {
$redirect = "http://biba/" . $username . "s/"; //last "s" I insert following your logic
header("Location:$redirect");
exit;
} else {
echo '<form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>';
}
?>


Note: this script is unprotected from inserting wrong username. For example, if someone write "image" script will redirect him/her in "images" folder.

BTW this is wrong forum for PHP questoins. Next time post in PHP forum and you will get faster response.

Sonam
Relentless
Thank you.

I Guess I just copy and paste this into a new php documnet and edit the bit where you said "I insert following your logic header" Question

Thank you
Relentless
Its not working.

please note i have a folder called ClientsArea and i am putting this php document into it under index.php.

And also in the folder I have Dan, ect...

when i looked at the form it was going to http://biba.

The folder the index.php is in is http://www.Dan.Frih.Net/ClientsArea/

And in there are protected folders like e.g Dan.

So all i want this form to do is add to the URL what i type in. e.g if i type in pancake i want the URl to goto http://www.dan.frih.net/ClientsArea/pancake

Hope sombody can help. I know this is in the wrong place. Shell I move it?
sonam
Hi,
I didn't know where is your clients (in first post you are give me only examples) but now I can help you more. Everything is in this line:
Code:
$redirect = "http://biba/" . $username . "s/";


I am tested script in biba folder and I din't change it because I think you will understant what is for changing.

OK, change biba in www.Dan.Frih.Net/ClientsArea/ and remove s/ if you don't need it.

Code:
$redirect = "http://www.Dan.Frih.Net/ClientsArea/" . $username;


Sonam
Relentless
no it is not working still.

this is what I get back.

Code:
Warning: Cannot modify header information - headers already sent by (output started at /home/relentle/domains/dan.frih.net/public_html/ClientsArea/index.php:6) in /home/relentle/domains/dan.frih.net/public_html/ClientsArea/index.php on line 99


What do I do?

here is its location: http://dan.frih.net/ClientsArea/index.php

The folder i am trying to visit is "Dan" (case sentitive)

Thank dan
SlowWalkere
Make sure that the code snippet is at the very top of the file.

When you use the 'redirect' function, php redirects the browser to a new website. The catch is that it bugs out if any output has already been sent to the user.

What you want to do is separate the...
Code:
if ($username != "") {
    $redirect = ...
    header("Location:$redirect");
    exit;  }


snippet of code and place it at the very top. Then put the form information at the bottom of the file, where it belongs in the html.

The form doesn't need to be in the if/else statement. If a username has been entered, the page will redirect (and never even process the form echo). If there is no username, the page will ignore your redirect and display the form.

Hope that helps,
- Walkere[/code]
Relentless
Ok,
Well hate to say this but it's not working. This is what I have uploaded.

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Clients Area - login</title>
</head>
<?php
$username = @$_POST['username'];
if ($username != "") {
    $redirect = "http://dan.frih.net/ClientsArea/" . $username;
    header("Location:$redirect");
    exit;  }
} else {
echo '';
}
?>
<body>
<form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


Now the code above fails to work.

but this code below does work when its on pasted Into a .php document

Code:
<?php
$username = @$_POST['username'];
if($username != "") {
$redirect = "" . $username . ""; //last "s" I insert following your logic
header("Location:$redirect");
exit;
} else {
echo '<form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>';
}
?>


The code above is EXACTLY how it is writen on my server and works.

But I dont want a text field in the top left corner lol

can you help?
Thanks
Dan
sonam
OK, script is not working because you are start html page. Insert on very top of your page (be carefull, one blank before <?php can return error) this part:

Code:
<?php
$username = @$_POST['username'];
if($username != "") {
$redirect = "http://www.Dan.Frih.Net/ClientsArea/" . $username;
header("Location:$redirect");
exit;
}
?>


and somewhere in your page this form:

Code:
<form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>


If someone write wrong username he/she will get HTTP 404 - File not found

Sonam
Relentless
Thank You so much.

It works Very Happy

How many Frih$ you want?

Dan
sonam
Never mind, enjoy! Wink

Sonam
asim
the script worked fine, i tested it on my sever, thanks.... i was also searching something like this.
asim
Hi Sonam,

im in trouble, the code was working fine but now Say's:
Quote:
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\newbie\login.php:10) in C:\wamp\www\newbie\login.php on line 14


the code is

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Welcome to my website!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      
    </head>
    <body>
   <p>
<?php
$username = @$_POST['username'];
if($username != "") {
$redirect = "http://localhost/newbie/" . $username;
header("Location:$redirect");
exit;
}
?>
</p>
<p>     
        <form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>
</p>
</body>
</html>

Please Help
sonam
Hi, you dindn't read all post carefully. You must put PHP code on very top of your page. If browser print out anything you will get error.

Code:
<?php
$username = @$_POST['username'];
if($username != "") {
$redirect = "http://localhost/newbie/" . $username;
header("Location:$redirect");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Welcome to my website!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       
    </head>
    <body>
<p>     
        <form name="form1" method="post" action=""><input type="text" name="username">
  <input type="submit" name="Submit" value="Submit">
</form>
</p>
</body>
</html>


Sonam
Related topics
PHP Form Generator
Uplaoding images using php form :::: Help needed
Php form.
Anyone care to help me with a simple PHP Form ?
PHP Form Sending problem
I need a complex php/flash form... 250FRIH$
anyone know of a good php form processer script
PHP Form Question
A Little PHP GD Help...
PHP Form Processing Problem
Help with php email
800$ frih for grab, php form small correction - urgent
php project help needed please
Form handling in php is a pain in the neck
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.