Create unique link (one time click) with expiration time [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to create unique links (one time click) for my newsletters.
Look the steps:
I will create a link, or can be a script that will create the link http://www.example.com/page.php?unique=email#email.com
My subscriber will receive a newsletter which contains this link.
They click/visit this newsletter/link.
If they want visit it again they can't, the link will be expired, and the subscriber will be redirected to other page http://www.example.com/expired.php
So is there any chance to create this? How can this be accomplished?
I have this code
<?php
include("variables.php");
$password = trim($_SERVER['QUERY_STRING']);
if($password == ADMIN_PASSWORD) {
// Create a new key
$new = uniqid('key',TRUE);
if(!is_dir('keys')) {
mkdir('keys');
$file = fopen('keys/.htaccess','w');
fwrite($file,"Order allow,deny\nDeny from all");
fclose($file);
}
$file = fopen('keys/keys','a');
fwrite($file,"{$new}\n");
fclose($file);
?>
This script is located in a file named generate.php and if I access this url ( http://www.example.com/generate.php?1234 - 1234 is the password to generate a unique ID) will generate a unique link like this http://www.example.com/page.php?key525e1200e3a5f9.19949496 that will be only 1 time available!
Now what I want is, to access http://www.example.com/generate.php?1234&s=email#email.com
And this this generate a unique link http://www.example.com/page.php?key525e1200e3a5f9.19949496&s=email#email.com
This is for a protected download page! I need to add the user email to the download page, and this to be generated by link. 's' is the variable that will be get by the download page using $_GET['s']
Understand what I mean?

I would do this using there email.
Then do a PHP page with the following statements.
Request the GET (in this case the email address) and check if it exists in database table (lets call this - hasvisited).
IF this exists then redirect to page you want.
If doesnt exist then...
1.) Add it to DB.
2.) display 1 time page.
When step 1 happens. it will stop the user from visiting again.
If you want to restrict this to a group of specific users - as the above solution people could theoritcally type anything to get past this...
I would create table with the users already and do an IF state on a column called 'visits' and if 1 or less allow and add +1 to visits column. if above 1 visit then redirect.
I hope this make sense - should also be fairly simple to implement using PHP, MySQL DB and simple IF statement.

Related

PHP Create temporary link to page/file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I am working on a website project, where you can login.
I want to make a system where you can request a file, but the link to the file should only be valid for a certain amount of time. After the certain amount of time the link should expire and stop working (maybe a show a 404 error).
-I am using php and MySQL database
Thank you!
BTW: I am new on this platform
Start with these 2 tables.
Whenever you upload file or manually add it, add an entry in the files table.
Whenever someone request a file, generate a link for it in links table like https://host/download.php?id=the_random_string which will point to the real file_id, with an expiry date.
files
id
name
physical_path
links
id
file_id
random_string
expiry
So now you should have a file download.php (pseudo code)
$str = $_REQUEST['id'];
$sql = "select file_id from links where random_string=$str AND expiry hasn't passed";
$file_id = $row->file_id;
$sql = "select physical_path from files where id = $file_id";
$physical_path = $row->physical_path;
do_download($physical_path);
You can accomplish that using two ways...
First Way
You can add timestamps on the URL where this URL is valid for a specific time (You must take care of changing this timestamp by the user) so, I recommend adding the timestamp as an arbitrary/inapprehensible string where the user can not change.
Second Way
You can add the timestamp in the database with each file and before accessing the file you must check the stored timestamp if was exceed the current timestamp or not.

How to dynamic generate pages in php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm doing a web app with PHP in which users have different number of tabs in the menu depending on a certain number of things, one user can have one tab in the menu where another user has ten.
I've managed to dynamically generate the menu items but now I don't know how to create files (pages) where the user gets redirected once he presses on any of the menu tabs.
All these files look the same the only thing that changes are the text, just some strings.
Summing up, what I want to do is:
Generate and destroy files automatically when the user has to consult something
How to link the menu tabs (href) to them automatically
The best would be to use a PHP page as template you could call it.
Lets say for example a user is logged in and clicks the view data page (data.php)
on your link you could have something like this:
and in data.php:
<?php
$USER_ID = htmlspecialchars($_GET["id"])
//SQL Request to get user priviledge and authentificate
//OR
//Check the cookie session for information
if (user_priviledge == 0)
{
//
//Show only data for 0 users
//
}elseif (user_priviledge == 1) {
//
//Show only data for 1 users
//
}
?>
This may not be the solution you wanted but your question wasn't very clear either so if you need any other information make sure to bring more precision.
The condition which are using for tab use same condition to show page. But add that condition in your text.Because your text is changing not page I think.
I this this might help you.
since all files will look the same and only variables will change, you can create one php file and just send the necessary data when a user clicks on the tab to assign to the variables in that page. You do not need to keep on creating custom pages for each and every tab.
Provide some code which you have written for this so that we can help you further

PHP - how to generate a URL on save like JSFiddle does? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to recreate something you might know from imgur or jsfiddle - you just type something or upload images, then you click "save" or "upload" and then you get a original link in form of imgur.com/smth or jsfiddle.net/smth. How is this done? I've created simple website where I can write notes and save them and it works perfectly well for myself, but I wanted to share it with some of my friends and I have absolutely no idea how can the "save" button attach their changes to new URL every time they press it? I know this is pretty basic but I couldn't find anything on the matter online and I really have no idea how to handle this issue, excepting I'll be writing their changes to different SQL rows.
Thanks for any clues :)
If you're trying to create something and let people edit it and keep the same link you could do it with PHP and mySQL.
I think the easiest way would be to have one page to create the initial note and one to update/view it. Once you create it the save button would add it to a database with a unique id of some kind like an auto increment number. To send the page you would use a link like www.somepage.com/info.php?id=1. The "id=1" part would be the unique id within the database. In info.php, you would need to use $get_["id"] and set that to equal the database id row and load the info from there. Then you could allow edits to that row from that page. You would have to set the save button to update the row.
To get something like somepage.com/smith, if you're on a linux server, you would use htaccess and mod_rewrite.
This is a really down and dirty gist of how you could do this, but it should send you in the right direction.

php - different design of webpage for logged in users [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I just have one question. I looked through one book and the Internet and unfortunately didn't find an concrete answer. So... I have a webpage where user can log in. If the user is logged in then the bar at the top of webpage is different(user sees his own photo, name etc.). I know how to use sessions&databases in this case, but I don't know how to make this two different websites. I mean.... in the home site of my whole webpage i can write sth like (in php):
if(isset($_SESSION["User"])) ..... .
But what then? I should somehow hide the html for unlogged user in "else" and part for logged user in "if" or should i create a whole new site for logged in users and redirect to this site if user is logged...? Please, help me.
It seems that you need to spend a little time looking into PHP deeper. My advice would be to learn about including PHP files in order to create a template system (so you would have a base PHP file with the HTML/PHP that is on every page (like a master page) that would include the code:
if(isset($_SESSION["User"]))
{
// Do code for logged in user...
}
else
{
// Do code for generic user...
}
Although that is a really rudimentary example, you could have a global variable if you need things on specific pages too. If you have a more specific question about implementing it, feel free to ask.
one cool thing that you can do in PHP is include html "inline". eg:
if(isset($_SESSION["User"]))
{
?>
<p>Welcome User! <?php echo $_SESSION["User"]; ?></p>
<?php
}
else
{
?>
<p>Please login to see all features...</p>
<?php
} ?>
You should first set the session variable's value(eg. $_SESSION['logged_user_id']) to some value as per your website. Then assuming that you have only one page, you will have to include many php codes at the place you wanted to display user image, Hello xyzuser etc content. You will have to use "if/else" statements to check if the session variable for some user is set or not. If the session variable is set then it will be using the if block statements where you can write code to display image of the user corresponding to e.g. that logged_user_id using your db. Otherwise it will use the else part that will display your default content.
You will have to perform "if/else" checks at each place where your content has a chance to change based on the user status i.e. use the "if" statement to check if the user is logged in or not if no user is logged in then it won't go to the "if" block statements and execute the "else" part for default display. Ok.

How to create a page using a form? php/html [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Similar to how you create a post in wordpress or even ask a question on this very website.
I want to know how to create a page by just filling out a form?
Here's what I know:
-I know how to make an html form
-I know how to place data in a database and take it out
-I know some php
What I don't know is how to to tie all of these things together. Please be as specific as possible and if you know of a tutorial on how to do this or you have the time to make a small example I would be very very grateful.
Thank you in advance for your time :-)
EDIT: To provide more details
I want to send data from a form (even a few text inputs would be enough) and for them to be placed in a page where I can display them.
And also that page should have an unique identifier so it gets stored similar to the questions on stack overflow where there is www.stackoverflow.com/posts/'identifiernumber'
And I would always to go back to that information provided I access the link which I assumed will be stored in the database.
Wordpress uses wysiwyg this is used to convert normal text into html code you can find jquery plugins for it.After user has entered the content of the page and hits submit. Wordpress directly stores the content in the database in HTML FORMAT . Now all it does is echo out the content stored in the database.
Now for the identifier , it should point out to the primary key of the database row where the content is stored. Wordpress stores a unique url as the identifier like the questions you asked is How to create a page using a form? php/html it will store it as how-to-create-a-page-using-a-form-php-html . This is then put in the href attribute of <a> tag , on click of this unique identifier it echo out the content of that row.
All you have to do now is make a form and textarea , apply the wysiwyg plugin on the textarea . Then onsubmit store the data in the database and also creating a unique identifier for it.
You question now is how to pass the identifier in the URL?
First you must know how to pass a variable in the URL and then capture it in the required place eg : www.yourwebsite.com?identifier=something and to make this a link on you website
Something
Once you have mastered this you can then study a concept called MOD REWRITE and in layman term for this is called clean URL or SEO URL . There are many blogs and methods of achieving this goal. You can google MOD REWRITE and SEO URL.
Create your website theme
on first page create form like you want
concept is like registration form and second page is edit profile
now what you stored in database from registration form
now echo in your edit profile form
for example username in database can be viewed in edit profile form
select * FROM registrationtable WHERE userid='$userid'
then store values in variables like for example
while ($query = mysql_fetch_array($request))
{
$username = $query['username'];
}
<input type="text" name="username" value="<?php echo $username; ?>"/>
p.s dont use mysql better options are mysqli and PDO

Categories