PHP - Generate A Unique Url For Each New Email That Expires After A Given Time
I'm not sure I'm in the right place, but I'm looking to create a unique URL that links to the same page every time I send an email after a form is submitted on my website and have it expire after 15 days. After expiring, the link would redirect to a default page. I'm still a beginner and realize this is probably going to be a tough task, but any resources or direction provided would be much appreciated.
Thanks for the help in advance! Similar TutorialsI have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } hi, im trying to create a website and only now started thinking about the security part(noob mistake). say for example i have home.php page and an index.php page. index.php is where users would sign up/log in. the login and sign up processes are all done but i was thinking of creating a unique id of some sort for when the user logs in. or something like this site (forum.phpfreaks) when we sign in, you are signed but the url stays the same = forums.phpfreaks.com. like if we were signed out we will be permanantly signed out and typing in forums.phpfreaks.com would just land us at the main page where we need to sign in.
right now ,my home.php can be accessed with or without logging in even with sessions.
hope im making sense, thanks in advanced!
**haha that rhymed.
i tried adding:
<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?> in the index.php:
<?php ob_start(); session_start(); if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['pass']; require "connection.php"; $emails = mysqli_real_escape_string($con, $email); $query = "SELECT id, name, email, password, salt FROM users WHERE email = '$emails';"; $result = mysqli_query($con, $query); if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again. { echo "<script>alert(\"User does not exist!\")</script>"; } $userData = mysqli_fetch_array($result, MYSQLI_ASSOC); $hash = hash('sha256', $userData['salt'] . hash('sha256', $password) ); if($hash != $userData['password']) { echo "<script>alert(\"Incorrect Password!\")</script>"; }else{ session_regenerate_id(); $_SESSION['sess_user_id'] = $userData['id']; $_SESSION['sess_name'] = $userData['name']; session_write_close(); header('Location: home.php?user='); } } ob_flush(); ?> <!DOCTYPE html> <form name="login" method="post" action="<?php echo $_SERVER[PHP_SELF] . '?name=' . $userData['name'];?>">but i got access forbidden! Edited by noobdood, 19 May 2014 - 10:05 PM. My table looks like this.. `guns_id` int(255) NOT NULL auto_increment, `guns_name` varchar(255) collate latin1_general_ci NOT NULL, `guns_price` int(255) NOT NULL, PRIMARY KEY (`guns_id`) I want to add a product key that is unique through out the whole database as I have other products other than guns aswell. Hi Looking to create an ID which only contains alpha-numeric (no special chars). I looked to generate random bytes and then encode in base64 but base64 contains = + /. The below seems to do it but not sure if bin2hex can return non alpha numeric? bin2hex(openssl_random_pseudo_bytes(18)); Edited December 18, 2018 by mds1256 How to generate a unique random number in php??? Any one who can help me? I am looking to generate a random number for every user contribution as a title of the contribution. I could simply check the database each time with a query and generate a number which does not equal to any of the entries of the database. But I imagine this as inefficient and it could become slow if the database is big in my opinion. Also I'd have to contain all the numbers of the database somewhere to manage the "not equals to", in an array or something similar but that can end up as a giant one. Excuse the layman's speech I am new to this. Any suggestions how this can be solved efficiently without straining the resources too much? You can explain it linguistically and do not have to provide me any scripts, I will figure it out. hi!, is it possible to use rand() to generate unique number that will be saved in a database as a primary key? Since i dont want to have numbers like 00001 incrementing on the table. They dont look like real account numbers... i need something like 45642 or 95452 and the like. thanks in advance. Hey guys. I need to know how to get a time that is constant. What I want to achieve: I need to make a clock on my website showing only one time (HH:MM:SS), wherever the page is requested from. And I need to use this "time" in calculations, like finding the time difference between two time values stored in my MYSQL Databases. I hope that I am clear with my question. Thanks for any help in advance! Hi, I'm quite new to PHP so please forgive me if this is a bit simple! I have a form on my website, which uses PHP to generate an email to me, the recipient. It works, but there are two new modifications I need help with. First of all, I want the PHP to generate a 'thank you' email to the person who has submitted the email. Please could somebody show me the code, and where to add it? Secondly, I want the email to come through to me from the email address of the person submitting the form (i.e. replacing the donotreply email address currently). Again, could somebody please show me how to do that? Many thanks in advance Here's the code: <?php // Website Contact Form Generator // http://www.tele-pro.co.uk/scripts/contact_form/ // This script is free to use as long as you // retain the credit link // get posted data into local variables $EmailFrom = "donotreply@simplyskillsgroup.co.uk"; $EmailTo = "robin@trillodigital.co.uk"; $Subject = "Simply Skills Franchise Application"; $name = Trim(stripslashes($_POST['name'])); $surname = Trim(stripslashes($_POST['surname'])); $telephone = Trim(stripslashes($_POST['telephone'])); $email = Trim(stripslashes($_POST['email'])); $dob = Trim(stripslashes($_POST['dob'])); $add1 = Trim(stripslashes($_POST['add1'])); $add2 = Trim(stripslashes($_POST['add2'])); $add3 = Trim(stripslashes($_POST['add3'])); $town = Trim(stripslashes($_POST['town'])); $postcode = Trim(stripslashes($_POST['postcode'])); $where = Trim(stripslashes($_POST['where'])); $employment = Trim(stripslashes($_POST['employment'])); $trade = Trim(stripslashes($_POST['trade'])); $drive = Trim(stripslashes($_POST['drive'])); $crb = Trim(stripslashes($_POST['crb'])); $firstaid = Trim(stripslashes($_POST['firstaid'])); $protect = Trim(stripslashes($_POST['protect'])); $convict = Trim(stripslashes($_POST['convict'])); $coach = Trim(stripslashes($_POST['coach'])); $other = Trim(stripslashes($_POST['other'])); $faca = Trim(stripslashes($_POST['faca'])); $other2 = Trim(stripslashes($_POST['other2'])); $other3 = Trim(stripslashes($_POST['other3'])); $hear = Trim(stripslashes($_POST['hear'])); $confirm = Trim(stripslashes($_POST['confirm'])); // validation $validationOK=true; if (Trim($email)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/error.html\">"; exit; } // prepare email body text $Body = ""; $Body .= "PERSONAL DETAILS"; $Body .= "\n"; $Body .= "\n"; $Body .= "First Name: "; $Body .= $name; $Body .= "\n"; $Body .= "\n"; $Body .= "Surname: "; $Body .= $surname; $Body .= "\n"; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $telephone; $Body .= "\n"; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "\n"; $Body .= "Date of Birth: "; $Body .= $dob; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 1: "; $Body .= $add1; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 2: "; $Body .= $add2; $Body .= "\n"; $Body .= "\n"; $Body .= "Address Line 3: "; $Body .= $add3; $Body .= "\n"; $Body .= "\n"; $Body .= "Town or City: "; $Body .= $town; $Body .= "\n"; $Body .= "\n"; $Body .= "Post Code: "; $Body .= $postcode; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "FRANCHISE DETAILS"; $Body .= "\n"; $Body .= "\n"; $Body .= "Where in the United Kingdom would you like to operate a Simply Skills franchise: "; $Body .= $where; $Body .= "\n"; $Body .= "\n"; $Body .= "Your current employment or business: "; $Body .= $employment; $Body .= "\n"; $Body .= "\n"; $Body .= "In a position to trade within: "; $Body .= $trade; $Body .= "\n"; $Body .= "\n"; $Body .= "Driving licence: "; $Body .= $drive; $Body .= "\n"; $Body .= "\n"; $Body .= "Enhanced CRB disclosure (within 3 years): "; $Body .= $crb; $Body .= "\n"; $Body .= "\n"; $Body .= "Current first-aid qualification (within 3 years): "; $Body .= $firstaid; $Body .= "\n"; $Body .= "\n"; $Body .= "Child protection training (within 3 years): "; $Body .= $protect; $Body .= "\n"; $Body .= "\n"; $Body .= "Any convictions that would affect your ability to work within schools: "; $Body .= $convict; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "EXPERIENCE"; $Body .= "\n"; $Body .= "\n"; $Body .= "Highest football coaching qualification: "; $Body .= $coach; $Body .= "\n"; $Body .= "\n"; $Body .= "Other football coaching qualifications: "; $Body .= $other; $Body .= "\n"; $Body .= "\n"; $Body .= "Member of the Football Association Coaches Association: "; $Body .= $faca; $Body .= "\n"; $Body .= "\n"; $Body .= "Other sports/disciplines you are qualified to deliver: "; $Body .= $other2; $Body .= "\n"; $Body .= "\n"; $Body .= "Personal qualities and experience that you feel is beneficial to operating a Simply Skills franchise: "; $Body .= $other3; $Body .= "\n"; $Body .= "\n"; $Body .= "\n"; $Body .= "How did you hear about Simply Skills: "; $Body .= $hear; $Body .= "\n"; $Body .= "\n"; $Body .= "Confirm all information provided is correct: "; $Body .= $confirm; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/thankyou.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://clientzone.trillodigital.co.uk/simplyskills/error.html\">"; } ?> Hello........ Currently i am struggling with php script....... can any one tell me or guide me how to code Automatically generating random number with in the range of 19 to 90 and the number has to change with in 24 hours time duration......... It's urgent........ Thanks in advance..... Rooban.S I'm having a problem with getting the timestamp to attach to the filename. Currently when it's uploaded in the database it says $timestamp in front of the filename instead of the time. Scroll down towards the bottom of the code to see it. Thanks for your help! $username = $_GET['username']; $item_id = $_GET['id']; define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/".'$timestamp'.$_FILES["thumb"]["name"] ); mysql_connect("localhost", "root", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $timestamp = time(); $item_image = '"$timestamp"'.$_FILES['thumb']['name']; $sql="UPDATE product SET thumb='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=311239.0 My intended goal is to have it see if the post allows comments and if it does then check to make sure the date_comments_expires is NOT before the passed day. I'm not quite sure how to finish this if statement. Any help? Code: [Select] if ($mainNews[0]['allow_comments'] == 'Yes' AND $mainNews[0]['date_comments_expire'] == ) { Is there a script I can use to receive an sms each time a message is sent to my email? Hello and looking for some help please.. I have already read this : http://www.phpfreaks.com/forums/index.php?topic=120619.0 What I am after to do, is to after a successful Paypal payment from paypal, generate a link in a wordpress site (or external even) that will expire after 3 days to a video. I hope that makes sense please? Thanks in advance, Jim i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } |