Closed Thread Icon

Topic awaiting preservation: PHP Strip (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26940" title="Pages that link to Topic awaiting preservation: PHP Strip (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP Strip <span class="small">(Page 1 of 1)</span>\

 
Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-01-2005 14:04

Hi there

I would like to know how to strip data from a form field, then go to a URL depending on the data

ie: Field filled in with: myname@mydomain.com
take data before & incl. @ and replace with http://www.
take info after @ and place after http://www.
then go to final result (http://www. mydomain.com)

is this possible?

Thanking all you smart people in advance


I try to take just one day at a time but lately several days have attacked me at once !

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-01-2005 14:41

Sure... you'll need either php->substr and php->strpos or php->preg_match to extract the domain name,
and then do a redirect as described in How can I redirect a page with PHP?.

so long,

->Tyberius Prime

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-01-2005 14:51

It should be fairly easy to do using some REGEX. Here comes a code snippet that does it in JavaScript :

code:
var	result = fieldValue.match( /@(.*$)/ )
if( result )
	alert( "http://www."+ result[1] )

Hope that helps,
Beside, what do you want to do in fact ?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-01-2005 18:11

well... except that he asked for php and you answered in javascript, nicely done poi!

(if you do a document.location.href = "http://www." + resultnt"; instead of alert(...) it'll actually redirect you there.)

Blacknight
Paranoid (IV) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 11-01-2005 18:29

TP noticed the link in resultnt ?? it goes to page 1 of the asylum

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-01-2005 18:36

I was too lazy to save the file in a folder mapped in my httpconf pressing F12 in UltraEdit was mucho faster for a quick and dirty test.

Anyway I still wonder in which case one would want to redirect to the domain name of an email address.
To tell you the truth, my exact test was :

code:
function process( formHandle )
{
	var	result = formHandle.elements['email'].value.match( /@(.*$)/ )
	if( result )
		document.body.innerHTML += "<img src='http://www."+ result[1] +"/favicon.ico' /> &nbsp; "
}

Which suddenly made me wonder why email clients don't use some kind of favatars.

Blacknight: That's because TP did not enclosed his code in the [ code ] UBB tags, hence when he wrote [ 1 ], the grail 'mis'-interpreted it as a [ threadId ] UBB tag



(Edited by poi on 11-01-2005 18:39)

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-02-2005 11:34

Thanks for the replies - much appreciated

Theres a form field called "email" that the guy types in his email address - presses go and his web domain opens in a new window

so would this work??

FORM.PHP

code:
<form post=domain.php>

     <input type=text name=email size=20 class=small>&nbsp;<input type=submit value=go name=go>

</form>




DOMAIN.PHP

code:
<?php
# Accept HTTP POST variables
extract ($_POST);

?>

<?php

function process( formHandle )
   {
	var result = formHandle.elements['email'].value.match( /@(.*$)/ )
	if( result )
	document.body.innerHTML += "<img src='http://www."+ result[1] +"/favicon.ico' /> &nbsp; "
   }

?>



I try to take just one day at a time but lately several days have attacked me at once !


Edit: Oh and TP - Mind lending me one of your nuts so that I can be half the "he" you expect me to be?

(Edited by Minkies on 11-02-2005 11:44)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-02-2005 11:58

Sorry, but as TP and I said, the code snippets I've posted are in JavaScript. NOT in PHP. You'll have to play/fiddle/learn with it and the links TP gave you to turn them into PHP.

Like an old sage said, or was it a Mad Sci., I'd rather learn you how to fish than giving you a fish.

Whatever, to do a redirection in php, you simply have to do :

code:
header( "Location: ". $newUrl );
exit();



Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-02-2005 12:36

Oh - oops - sorry about that

(Edited by Minkies on 11-02-2005 12:37)

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-02-2005 12:36

ok to be honest... i create graphics - and know next to nothing about code

I was asked by my boss if it would be possible to create a form that would strip out anything before & incl the @ sign and replace it with http://webmail. and then include whatever was after the @ sign at the end of the replaced section

ie: iamamonkey@thezoo.com becomes http://webmail.thezoo.com and gets redirected to the result

We have a few clients that wouldn't know what domain name to fill in the field and so decided to use the email address instead (and who doesn't know their own email address?)

I'm used to posting in the Photoshop Forum (Cube Tut) and so figured I could ask for help on this side when I noticed there was a scripting forum.

I asked a friend and he suggested the explode function in PHP - but that makes less sense to me.

Anyways... Thanks all... I'll try figure it out using the responses

I try to take just one day at a time but lately several days have attacked me at once !

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-02-2005 12:56

If you are sure your clients have JavaScript enabled, you can say good bye to sever side scripting and use my code ( with the little modification stated by TP ), almost as is.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 11-02-2005 14:43

Plenty of good info here for what you need. Personally, I would go with TP's initial suggestions using substr and strpos in PHP - mainly because I'm not comfortable working in javascript.

Sounds like a good time let your boss know that he needs to either a) get someone who does the code work, or b) get you trained to do it =)

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-10-2005 11:54

Okie dokie

So this is what I got... It works to strip the host and username

now all i need to do is redirect it to the domain

code:
<?php
# Accept HTTP POST variables
extract ($_POST);

?>

<?php
# Get input e-mail address
$email = "$email";

# Seperate e-mail address into user- and host names
list ($user,$host) = explode ("@",$email);

# Display output
echo ("User: ".$user);
echo ("<br>");
echo ("Host: ".$host);
?>



I try to take just one day at a time but lately several days have attacked me at once !

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-10-2005 12:02

Okay - I redirected it to the domain took me a while to figure out but its working

woohoo - thanks guys


code:
<?php
# Accept HTTP POST variables
extract ($_POST);

?>

<?php
# Get input e-mail address
$email = "$email";

# Seperate e-mail address into user- and host names
list ($user,$host) = explode ("@",$email);

# Display output
echo ("User: ".$user);
echo ("<br>");
echo ("Host: ".$host);

# Redirect browser to host
header("Location: http://webmail.$host");
exit;
?>



I try to take just one day at a time but lately several days have attacked me at once !

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-10-2005 14:55

Hi again... well it works on my machine but doesn't seem to work on the server.
Something about Globals being off... how would i be able to fix this?

I have pasted the error in bold below


Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/enyuka.co.za/httpdocs/email.php:6) in /home/httpd/vhosts/enyuka.co.za/httpdocs/email.php on line 14

the 14th line being
header("Location: http://webmail.$host");

code:
<?php
# Accept HTTP POST variables
extract ($_POST);
?>

<?php
# Get input e-mail address
$email = "$email";

# Seperate e-mail address into user- and host names
list ($user,$host) = explode ("@",$email);

# Redirect browser to host
header("Location: http://webmail.$host");
exit;

# Display output
echo ("User: ".$user);
echo ("<br>");
echo ("Host: ".$host);
?>



I try to take just one day at a time but lately several days have attacked me at once !

(Edited by Minkies on 11-10-2005 14:56)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-10-2005 15:28

You can't output any text to the browser before sending headers, that includes the space between the first closing php tag and the second opening tag.

Change:
extract ($_POST);

?>

<?php
# Get input e-mail address

to:

extract ($_POST);
# Get input e-mail address



.:[ Never resist a perfect moment ]:.

DmS
Maniac (V) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 11-10-2005 16:01

Hi, this is probably the problem here:
extract ($_POST);

I'd do these mods:

code:
<?php
// Get input e-mail address
$email = $_POST['email'];

//validate email here, thiws just checks that it's not empty
if($email != '')
{

// Seperate e-mail address into user- and host names
list ($user,$host) = explode ("@",$email);

// Redirect browser to host
header("Location: http://webmail.$host");
exit;
}
else
{
print('No email adress provided');
}
?>


(note that I'm supposing that you only get the email through $_POST...)
I don't think it's the register_globals = off
that causes your problem since you use extract(), just in case I took email directly from $_POST which is the proper way.

Next, you really, really should validate that you are getting a proper email adress before you proceed in the script!
You can find tons of tutorials on this if you google on "validate email in php"

Then, the error message you got is because something has been sent to the page before you try to redirect through header()

That might be an error msg from your script or the odd commenting you do, // is the proper way for single line comments /* */ for multilines.

Try this and see how it works.
/Dan

{cell 260} {Blog}
-{"Theories without facts are just religions...?}-

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-21-2005 14:58

Hi there - me again

i know i'm being stupid but i've done the validate email thing which seems to work

thing is when its submitted from the site it keeps printing the "No email address provided" piece.

what am i doing wrong that it works on my machine and not on the server (I'm using xammplite on my pc)


code:
<?php
# Accept HTTP POST variables
extract ($_POST);

//validate email here, this just checks that it's not empty
$email = "$email";
if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
   echo "'$email' is a valid email!";

// Separate e-mail address into user- and host names
list ($user,$host) = explode ("@",$email);

// Redirect browser to host
header("Location: http://webmail.$host");
exit;
}
else
{
print('No email address provided');
}
?>



I try to take just one day at a time but lately several days have attacked me at once !

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-21-2005 18:33

It's not really clear here but a couple of things

First this line:

$email = "$email";

doesnt' really do anything except make sure $email is set to something.

Using isset($email) is a better check to see if this is being set. I'd first check to see that $email is being set, then check to see if it's valid this will give you a better indication of where your validation is breaking.

Also I'd take out the redirect and just echo the $email variable to see what you're getting in.



.:[ Never resist a perfect moment ]:.

Minkies
Bipolar (III) Inmate

From: Johannesburg, Gauteng, South Africa
Insane since: Jan 2001

posted posted 11-24-2005 08:29

i am such an a-hole!!

I forgot to put method=post on the original form

i am so sorry to have bothered you guys with this - honest

really appreciate all the help

I try to take just one day at a time but lately several days have attacked me at once !

« BackwardsOnwards »

Show Forum Drop Down Menu