Web Hosting Talk







View Full Version : Question for the PHP Pros


jmc67
12-14-2003, 12:12 AM
Although this isn't directed at hosting persay, I thought I'd ask anyway. If this is inapropriate, then the mods know what to do.
I have a script that sends ringtones, images, screensaver and games to pcs-vision phones. Now the script at this time only allows 10 digit numbers and email addresses to @sprintpcs.com only. What I would like to do and can't seem to do is to also allow @messaging.sprintpcs.com to be used as well. Any other email is not allowed. Below is a partial code. Any clue on how I can also add messaging.sprintpcs.com to this?


$GLOBALS['Email Match'] = '/@sprintpcs\\.com/i';
$GLOBALS['Email Match Message'] = 'You can only email addresses at ' .
'sprintpcs.com with this uploader.';





// Treat as email address. Remove stuff that could be bad. Be strict.
$sendto = preg_replace('/[^@a-zA-Z0-9\.\-_]/', '', $sendto);
$type = 'email address';
if (! preg_match('/[^@]+@[^@]+/', $sendto))
Bail("The email address \"$sendto\" is invalid.");
if (isset($GLOBALS['Email Match']) &&
! preg_match($GLOBALS['Email Match'], $sendto))
Bail($GLOBALS['Email Match Message']);

platinum
12-14-2003, 12:52 AM
why don't you just use a drop down menu with those two "extensions" in it, and only let the user enter their phone number.

Don't have to bother checking too much or play guessing games then.

Quick untested idea:

<?
if($_POST['submit']){

$number = $_POST['number'];
$emailext = $_POST['emailext'];
$validext = array("@sprintpcs.com", "@messaging.sprintpcs.com");

if(strlen($number) == 10 && is_numeric($number) && in_array($emailext, $validext)){
//do whatever
}
}
?>

<form action="" method="POST">
Number:<br />
<input type="text" name="number" /><br />
<select name="emailext">
<option>@sprintpcs.com</option>
<option>@messaging.sprintpcs.com</option>
</select><br />
<input type="submit" name="submit" value="submit" />
</form>

jmc67
12-14-2003, 01:35 AM
Good idea but the dropdown funtion cannot be implemented. First the script is setup to send via sprintpcs shortmail or via email depending whether the user types in a 10 digit number or an email address. Right now with the above code, the user has the option of the 10 digit number or username@sprintpcs.com. But there is also @messaging.sprintpcs.com that users can use as well. If I remove this then any email will work but want to restrict to only this type of email to avoid abuse.

Burhan
12-14-2003, 06:21 AM
You can modify the regex to check for messaging.sprintpcs.com. Untested, but should work :

$GLOBALS['Messaging'] = "|[messaging|]@sprintpcs\.com|i";


Is there something that I'm missing? :)

jmc67
12-15-2003, 03:29 PM
The lines in red was added and it worked.

$GLOBALS['Email Match'] = '/@sprintpcs\\.com/i';
$GLOBALS['Email Match1'] = '/@messaging.sprintpcs\\.com/i';
$GLOBALS['Email Match Message'] = 'You can only email addresses at ' .
'sprintpcs.com or messaging.sprintpcs.com with this uploader.';



// Treat as email address. Remove stuff that could be bad. Be strict.
$sendto = preg_replace('/[^@a-zA-Z0-9\.\-_]/', '', $sendto);
$type = 'email address';
if (! preg_match('/[^@]+@[^@]+/', $sendto))
Bail("The email address \"$sendto\" is invalid.");

if (isset($GLOBALS['Email Match']) &&
! preg_match($GLOBALS['Email Match'], $sendto) && ! preg_match($GLOBALS['Email Match1'], $sendto))
Bail($GLOBALS['Email Match Message']);