-1

I have a login system in my site. in which session starts when user login. when a user sign up his information is stored in userdb.php .now i want to store point of the user when he clicks link www.stackoverflow.com and save it to my database or userdb.php.and again display point. my sign up code are

<?php
if (session_id() == "")
{
   session_start();
}
$database = './usersdb.php';
$success_page = './Inside.php';
$error_message = "";
if (!file_exists($database))
{
   die('User database not found!');
   exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform')
{
   $newusername = $_POST['username'];
   $newemail = $_POST['email'];
   $newpassword = $_POST['password'];
   $confirmpassword = $_POST['confirmpassword'];
   $newfullname = $_POST['fullname'];
   $code = 'NA';
   if ($newpassword != $confirmpassword)
   {
      $error_message = 'Password and Confirm Password are not the same!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername))
   {
      $error_message = 'Username is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newpassword))
   {
      $error_message = 'Password is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$.' &]{1,50}$/", $newfullname))
   {
      $error_message = 'Fullname is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^.+@.+\..+$/", $newemail))
   {
      $error_message = 'Email is not a valid email address. Please check and try again.';
   }
   else
   if (isset($_POST['captcha'],$_SESSION['random_txt']) && md5($_POST['captcha']) == $_SESSION['random_txt'])
   {
      unset($_POST['captcha'],$_SESSION['random_txt']);
   }
   else
   {
      $error_message = 'The entered code was wrong.';
   }
   $items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
   foreach($items as $line)
   {
      list($username, $password, $email, $fullname) = explode('|', trim($line));
      if ($newusername == $username)
      {
         $error_message = 'Username already used. Please select another username.';
         break;
      }
   }
   if (empty($error_message))
   {
      $file = fopen($database, 'a');
      fwrite($file, $newusername);
      fwrite($file, '|');
      fwrite($file, md5($newpassword));
      fwrite($file, '|');
      fwrite($file, $newemail);
      fwrite($file, '|');
      fwrite($file, $newfullname);
      fwrite($file, '|1|');
      fwrite($file, $code);
      fwrite($file, "\r\n");
      fclose($file);
      $subject = 'Your new account';
      $message = 'A new account has been setup.';
      $message .= "\r\nUsername: ";
      $message .= $newusername;
      $message .= "\r\nPassword: ";
      $message .= $newpassword;
      $message .= "\r\n";
      $header  = "From: webmaster@yourwebsite.com"."\r\n";
      $header .= "Reply-To: webmaster@yourwebsite.com"."\r\n";
      $header .= "MIME-Version: 1.0"."\r\n";
      $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
      $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
      $header .= "X-Mailer: PHP v".phpversion();
      mail($newemail, $subject, $message, $header);
      header('Location: '.$success_page);
      exit;
   }
}
?>

Please help me.....

Pratik Yadav
  • 28
  • 1
  • 4

2 Answers2

0

To store values in session you can just use the below syntax

$_SESSION['Desired variable name'] = value;
Veerendra
  • 2,562
  • 2
  • 22
  • 39
0

You could try it by using ajax..if you want save points.. like you have a link

<a href="" id="stack-overflow">www.stackoverflow.com</a>
Now in your js file:
$('#stack-overflow').on('click', function() {
count = 1//how many points you want to assign
//send a ajax
$.ajax({
  url:'usersdb.php',
  type:'GET'
  dataType: 'json'
  data: {
   points: count,
      },
  success: function(resp){
  $('#stack-overflow').href='www.stackoverflow.com';
  //now triggered this link
  $('#stack-overflow').click();
  //or what ever msg you want to display
  });
  });

//Now u can get $_POST values in your usersdb.php and save it

if there is another issue the please confirm...and tell me what actually you want. Thanks.

SINGH
  • 397
  • 1
  • 4
  • 16