This question may have been asked before but I couldn;t really find it.
What I want to do is, websites like pastebin.com, even stackoverflow, these generate new webpages based on user input showing that data from what I can understand.
I want to make it like that. User enters something, and he is given a permalink to share that information.
How to do this using PHP ?
EDIT: Here is an example
Like, I want it that
instead of having something like www.example.com/view.php?id=123
I want it like
www.example.com/view/123
This is impossible to be done with PHP, you can do this with .htaccess's url rewriting.
a good article about this can be found at: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
In this site , work some ajax function, when you add some data in textarea and click submit, called function , that saved current data in db, and return some json data , and then show you in some format.
Simply done like this:
Create a index.php containing a input field where the user inputs their data.
Post data to the server and create a random string which will be the users permalink.
Then insert the random string and data into a database.
In the index.php file say that if any uri is added after your domain like example.com/
it checks against the database if this code exists in db, and returns the result to the visitor.
Related
I have some php code like following lines of code when clicking on the image it goes to different departments.
Departments.php?DepartmentsID=6?&CampusID=1
which shows in url when click on it.
How I can easily encrpt it so that it doesnot show in url same is the case with downloading some file.
download.php?filename=abc.pdf?
how i can disable or encrpt the code so that i didn't show up in url.
thanks
want to hide varibles that as passing through html link
as far as I understand you want to pass some kind of token as the link and not something readable like the filename or an id to your site to handle the request. (the user only sees tokens and nothing else)
so clicking on a link gives you something like Departments.php?action=907fgash6f8906a6asf6g...
If you want something like that you would need some kind of database to store your tokens so your code knows what to do on a given token.
Or you could use actual encryption which you would have to decrypt and of course keep your key hidden and secure.
I don't understand why you need to do all this. If you can give more insight on why you want to do this there might be a better solution
In your PHP form change or set the method as method = "POST".
You're using the URI as a GET parameter which is where you are receiving such complications. You can choose a more MVC related method to approach this:
www.example.com/6/1
The above example represents the Department ID as 6 and the Campus ID as 1 using a router. I suggest using AltoRouter.
$router = new AltoRouter();
$router->map('GET|POST', '/[i:d]/[i:c]', function($department, $campus) {
echo "Department $department on Campus $campus.";
// Add your code logic
}, 'Name of route');
$router_match = $router->match();
if($router_match && is_callable($router_match['target'])) {
call_user_func_array($router_match['target'], $router_match['params']);
exit();
}
// Some 404 stuff.
This can be used for mutli-mapping meaning you can change the download link to whatever you like, for example just unique file ID's that the end user must know to access it and on top of that, it could be a RBAC file before the download so only X users can download / view certain topics.
This repeats some of the info answered by others:
use POST, this only removes the ability to read the data in query URL but is still in clear text.
Ensure SSL is enabled for transport encryption
Use encryption at the message layer, the actual text itself can be encrypted if you so desire
Extra note, if the data is that sensitive and is stored at REST say in a DB, you may want to encrypt it there as well.
Basically "defense in depth" is the approach, there is never a silver bullet
I am using a plugin that uses unique user ids (uuid) to let visitors access some information. They receive this information by email. The whole system is based on wordpress.
This works great, if the visitor opens the direct page with a url containing the query string, for example:
https://www.example.com/user_site/?uuid=237237
As soon, as the user opens the link and navigates to another page, and then maybe to its user_site, the query string is lost. Its shown in this example:
History of opened urls:
https://www.example.com/user_site/?uuid=237237
https://www.example.com/another_site - bad, the query string is lost
https://www.example.com/user_site - no access, who even is this guy?!
How can I change this and pass (or parse) the query string while the user stays on the site? Or can I even cache it? I can use php, .htaccess javascript or jQuery to achieve this.
How the history should be:
https://www.example.com/user_site/?uuid=237237
https://www.example.com/another_site/?uuid=237237 - good, still know who you are
https://www.example.com/user_site/?uuid=237237 - great, come in
Try this : var sections = window.location.split('=')
I'm trying to create unique urls for user's of a site I'm designing. Basically I want the url to look like this:
http://www.example.com/page.php?user_id=3
Or whatever user_id they are assigned. Basically I want user to be able to go to that url and it generates the page with the info (first name, last name, etc.) of the user from the row in the MySQL table with that user id number. I know that creating the URL would be done by $_GET but this is sort of backwards from that. I want them to be able to go to the URL and the pages gets the variables from the URL.
Sorry if this is basic, I'm having trouble searching for an answer because it always gives me the answer on how to submit a form TO the URL not FROM the URL. Thanks for all the help.
$user_id = $_GET['user_id'];
you could use this to get the variable.And then search the database for the matching id and get get all the details.
Since you want to contain all the details in you form.You could keep adding the other elements like this.
http://www.example.com/page.php?user_id=3&first_name=Max&last_name=Payne
Using $_GET[which element you want the value of]
Accessing the get variables on the page is really simple!.In your case as you want to access the user id,you can get from $_GET['user_id'] and fire the respective query to fetch the user details to populate the page.For more reference you could check here
http://php.net/manual/en/reserved.variables.get.php
I have a form that a user fills out, which submits information to my mysql database. On submission, my php code creates a url based on form data that was submitted and a unique ID. Rather than having a new webpage populate my web directory based off of the generated url, I would like to point that url to something similar to a "profile" page.
So my php creates a link after a user has submitted the form that looks like this: http://localhost/State=ALCity=SeattleEvent=eventSubject=titleID=135
This link gets stored inside my table along with the data that was submitted by the user. I've read that storing a url inside a table isn't practical, however for my purposes the table data will expire and get deleted within a certain amount of time.
In short, I'd like to be able to have a user click the link which will pull up data that was submitted. Can I grab data from the url to pull that information up for the user? Or will I need to change my setup that's already implemented? I can explain further if needed :)
If I get you right, this is a classic case for the mod_rewrite extension of Apache (since you mentioned .htaccess, I think you use Apache as webserver). With this mod, you can filter parts of the url and send it to your php script as normal $_GET parameters.
You will need something like this in your .htaccess (just out of my mind)
RewriteEngine on
RewriteRule ^State=([a-zA-Z0-9]+)=SeattleEvent=([a-zA-Z0-9]+)=titleID=([0-9]+)$ profile.php?state=$1&event=$2&id=$3
What this is actually doing, is that the Apache checks if the current requested url match the regular expression of this rule. If that is the case, it will call the profile.php and pass the "dynamic" part of the url as $_GET parameter (using the backreferences).
For further information, I recommence the official mod_rewrite documentation, the mod_rewrite guide and this nice tutorial.
I didn't know how to ask professional so if topic is wrong, please correct it.
My problem is quite complicated. I was training on symfony webpage how to generate form and then send this data to another page.
But now i would like do something different. I would like create page xyzSuccess.php.
Then generate 29 links on this page. Each links would have its own number.
Each link would redirect to the same page. For example numberSuccess.php. After that, this site would give me data of the number which i clicked.
I will show the example :)
Page xyzSuccess.php have links, the third one is http://localhost:8080/web/number?nr=3
I click on it and i go to numberSuccess.php, the page give me number 3
After the page got number, also take from any datafile information under that number 3 ( i don't know, maybe any file wchich can store symfony / array somewhere?.)
I dont know how to do this, i don't want use any database eq. *sql
So far i created only page xyz.php which use php for loop. I see that action.class.php would work with it if i would use submit button, but i really dont have any idea how make this working with links. And... that problem with storing data :( maybe create file in lib/form ?
corrected the link to page (deleted success which used only in templates), guy under is right :)
First of all, you're talking about URL's like /web/numberSuccess... That probably means you've misconfigured the root. Also see this question, asked today.
Then it's common to give your actions names like number, and then in you're actions file you have the executeNumber action, which then renders the numberSuccess template. So you shouldn't include the Success in the action name/URL.
Then, your question:
What I would do, if you don't want to use a database:
Create a file links.txt in your /data directory, and on every line create an url, followed by a space and then the title of your link.
In your list action open the this file using file_get_contents(), explode it on the newline-character, and assign this array to the view.
In your view loop through the array, use the array index as your number, and explode each item on the first space, so you can display the title.
In the view action your open and explode the links file again, and now you can pointer directly to the index, explode again and you have the URL.