Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - alex

Pages: 1 2 [3] 4 5 6
31
Source Code / Re: php mail script not working
« on: May 14, 2010, 01:56:16 PM »
Code: [Select]
$to      = "customer_support@1900tr.com";
$subject = $_REQUEST["subject"];
$body = $_REQUEST["body"];
$email = $_REQUEST["email"];
$name = $_REQUEST["name"];

$dodgy_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
                ,"bcc:"
);

function is_valid_email($email) {
  return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}

function contains_bad_str($str_to_test) {
  $bad_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
,"Content-Transfer-Encoding:"
                ,"bcc:"
,"cc:"
,"to:"
  );
 
  foreach($bad_strings as $bad_string) {
    if(eregi($bad_string, strtolower($str_to_test))) {
      echo "$bad_string found. Suspected injection attempt - mail not being sent.";
      exit;
    }
  }
}

function contains_newlines($str_to_test) {
   if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
     echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent.";
     exit;
   }
}

if($_SERVER['REQUEST_METHOD'] != "POST"){
   echo("Unauthorized attempt to access page.");
   exit;
}

if (!is_valid_email($email)) {
  echo 'Invalid email submitted - mail not being sent.';
  exit;
}

contains_bad_str($email);
contains_bad_str($subject);
contains_bad_str($body);//replace body with $body

contains_newlines($email);
contains_newlines($subject);

$body = $body . " From: " . $name;
$headers='MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= "From: $email" . "\r\n";
mail ($to, $subject, $body, $headers);
echo "Thanks for submitting.";

32
LinkBase 2.0. / Re: Language Files
« on: May 13, 2010, 12:14:01 PM »
Arabic Lang file by newgalah

33
LinkBase 2.0. / Re: Arabic Lang file
« on: May 13, 2010, 12:11:44 PM »
Thank you for translation.  :) :) :)

34
Applications / PHP Cookies and Sessions Tutorials
« on: May 10, 2010, 06:31:09 AM »
index.php
Code: [Select]
<?php @session_start();
if(isset(
$_POST['Submit']))
{
setcookie("cookieuser"$_POST['username'], time()+3600); 
setcookie("cookiepass"$_POST['password'], time()+3600);
print_r ($_COOKIE);
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
print_r ($_SESSION);
echo
"<a href=\"members.php\">members</a>";
}else{
if(isset(
$_SESSION['username']) && isset($_SESSION['password'])){
echo 
$_SESSION['username'] . "-" $_SESSION['password'] ;
}else{
echo
"<strong style=\"color:red\">no session</strong>";
echo
" <a href=\"members.php\">members</a>";
}
?>

<form method="post" action="index.php">
<input type="text" name="username" ><br>
<input type="text" name="password" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>


members.php
Code: [Select]
<?php @session_start(); 
if(isset(
$_COOKIE['cookieuser']) && isset($_COOKIE['cookiepass'])){
$_SESSION['username'] = $_COOKIE['cookieuser'];
$_SESSION['password'] = $_COOKIE['cookiepass'];
echo
"cool " $_SESSION['username'];
echo
" <a href=\"destroysession.php\">destroysession</a>";
}else{
echo
"no session ";
echo
"<a href=\"index.php\">login</a>";
die();
}
?>

<h1>members area</h1>

destroysession.php
Code: [Select]
<?php @session_start(); 
print_r ($_COOKIE);
setcookie("cookieuser"""time()-3600); 
setcookie("cookiepass"""time()-3600);

if(isset(
$_SESSION['username']) && isset($_SESSION['password'])){
unset(
$_SESSION['username']);
unset(
$_SESSION['password']);
}else{
echo
"<strong>no session</strong> ";
}
$_SESSION = array();
session_destroy();
echo
"<a href=\"index.php\"> index.php</a>";   
?>



35
php Basic Functions / setcookie
« on: May 10, 2010, 04:58:49 AM »
Code: [Select]
<?php
setcookie
("cookieuser""username"time()+3600); 
setcookie("cookiepass""password"time()+3600); 
print_r ($_COOKIE);
?>


Delete cookies
Code: [Select]
<?php
setcookie 
("cookieuser"""time() - 3600);
setcookie ("cookiepass"""time() - 3600);
print_r ($_COOKIE);
?>




36
Applications / Upload and Resize an Image with PHP
« on: May 10, 2010, 04:55:32 AM »
Code: [Select]
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension substr(strrchr($current_image, ), 1);
if ((
$extension!= "jpg") && ($extension != "jpeg"))  
{
die(
'Unknown extension');
}
$time date("fYhis");
$new_image $time "." $extension;
$destination="uploads/".$new_image;
$action copy($_FILES['image']['tmp_name'], $destination);

if (!
$action
{
die(
'File copy failed');
}else{
echo 
"File copy successful";
}

//resize//

$create imagecreatefromjpeg($destination);
$currwidth imagesx($create); 
$currheight imagesy($create);
$ccreate ImageCreateTrueColor(50,50);

imagecopyresampled($ccreate$create00005050
$currwidth$currheight); 
imagejpeg($ccreate"thumbs/".$new_image);
imagedestroy($ccreate); 
imagedestroy($create); 

}else{
?>

<form method="post" enctype="multipart/form-data" action="submit.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>


37
Applications / Upload Image With PHP 2
« on: May 10, 2010, 04:54:10 AM »
Code: [Select]
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension substr(strrchr($current_image'.'), 1);
if ((
$extension!= "jpg") && ($extension != "jpeg"
&& (
$extension != "gif")
&& (
$extension != "png"))  
{
die(
'Unknown extension');
}
$time date("fYhis");
$new_image $time "." $extension;
$destination="uploads/".$new_image;
$action copy($_FILES['image']['tmp_name'], $destination);
if (!
$action
{
die(
'File copy failed');
}else{
echo 
"File copy successful";
}
}else{
?>

<form method="post" enctype="multipart/form-data" action="submit.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>


38
php Basic Functions / fwrite
« on: April 26, 2010, 09:42:54 AM »
Code: [Select]
<?php
$file 
"text.txt";
@
$fh fopen($file'w') or die("can't open file");
$data "PHP is an open-source server-side scripting language.";
fwrite($fh$data);
fclose($fh);
echo 
"OK";
?>


Example:
Code: [Select]
<?php
if(isset($_POST['submit']))
{
$file "config.php";
@
$fh fopen($file'w') or die("can't open file");

$host $_POST['localhost'];
$name $_POST['dbname'];
$user $_POST['dbuser'];
$pass $_POST['dbpass'];

$data "<?php
\$localhost='$host';
\$dbname='$name';
\$dbuser='$user';
\$dbpass='$pass';
?>
";
fwrite($fh, $data);
fclose($fh);
echo "OK";
}else{
?>
<form action="index.php" method="POST">
localhost:<input type=text name="localhost"<br>
dbname:<input type=text name="dbname"<br>
dbuser:<input type=text name="dbuser"<br>
dbpass:<input type=text name="dbpass"<br>
<input type="submit" name="submit" value="Submit">
</form>   
<?php
}
?>


39
php Basic Functions / PHP $_SESSION
« on: April 24, 2010, 10:18:04 AM »
PHP $_SESSION

index.php

Code: [Select]
<?php session_start();
$numero rand(100999);
$_SESSION['rand'] = $numero;
echo 
$_SESSION['rand']; 
?>

<br><a href="session.php">session.php</a>

session.php

Code: [Select]
<?php session_start();
echo 
$_SESSION['rand'];
?>

<br><a href="destroy.php">destroy.php</a>

destroy.php

Code: [Select]
<?php session_start();
echo 
$_SESSION['rand'];
session_destroy();
?>

<br><a href="index.php">index.php</a>


40
php Basic Functions / str_replace
« on: April 24, 2010, 08:46:03 AM »
str_replace

Code: [Select]
<?php
$content 
'PHP 1 2 3';
$str = array('1','2','3');
$replace = array('is an open-source','server-side','scripting language');
$output str_replace ($str,$replace,$content);
echo 
$output;
?>


41
php Basic Functions / PHP $_POST Function
« on: April 24, 2010, 12:57:46 AM »
PHP $_POST Function

index.php

Code: [Select]
<form action="post.php" method="post">
<input type="text" name="link"><br>
<input type="text" name="category"><br>
<input type="submit" value="Submit">

post.php

Code: [Select]
<?php
$link 
$_POST["link"];
$category $_POST["category"];
echo 
$link;
echo 
'<br>';
echo 
$category;
?>



42
php Basic Functions / PHP $_GET Function
« on: April 24, 2010, 12:55:59 AM »
index.php
Code: [Select]
<a href="get.php?id=link&cid=category">Get ID</a>
get.php
Code: [Select]
<?php
$id 
$_GET["id"];
$cid $_GET["cid"];
echo 
$id;
echo 
'<br>';
echo 
$cid;
?>


43
Form Elements / Images In Textarea
« on: March 27, 2010, 05:42:21 AM »
CSS
Code: [Select]
#sfeed {
              width:355px;
      border:#ccc solid 1px;
      background:#fff url(images/text_signature.png) no-repeat top left;
              padding-left:44px;
              font-family:"trebuchet ms";
              font-size:13px;
              color:#555;
             
}

PHP File
Code: [Select]
<form>
<p><textarea name="#" id="sfeed"  rows="3" cols="25"></textarea></p>
</form>


44
Form Elements / PHP Form Validation
« on: March 02, 2010, 02:06:18 AM »
Code: [Select]
<?php
if(isset($_POST['submit']))
{
$mail $_POST['mail'];
$subject $_POST['subject'];
$msg $_POST['msg'];
$headers 'From: System <noreply@example.com>';
$name=array($mail,$subject,$msg);
foreach (
$name as $name
{
if (
ereg("^\<",$name)) {
echo 
"<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (
ereg("^\[",$name)) {
echo 
"<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (
ereg("^\$",$name)) {
echo 
"<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (
strlen($name) < 3) {
echo 
"<center>Field must be at least 3 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>"
;  
 Die();
}
if (
strlen($name) > 120) {
echo 
"<center>Max Characters in Field: 120
<a href=\"javascript:history.go(-1)\">Go Back</a></center>"
;  
 Die();
}
}
mail($mail$subject$msg,$headers);
echo 
"O.K.";
}else{
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function validationEmail(maForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(maForm.mail.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
</script>
</head>
<form name="maForm" action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST" onSubmit="return validationEmail(this)">
<input type=text name="mail" value="e-Mail"><br>
<input type=text name="subject" value="e-Mail subject"><br>
<input type=text name="msg" value="e-Mail message"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>


45
LinkBase 2.0. / Re: Download LinkBase 2.0.
« on: February 20, 2010, 03:05:31 PM »
Quote
how do you modify it so people dont have to register to add a url?

new addurl.php file :)


Pages: 1 2 [3] 4 5 6