codeigniter - hide variable from url - php

I want to do something very simple in codeigniter. I have a view, which contains several person profiles. Each person profile has contact button and it should go to a contact form which sends an email to the chosen person. So I have tried something like this:
Contact
And this is OK, but I do not want the email to be visible in the URL. Is this possible ?

Yes, it is possible. Use an array inside your controller:
$emails = array(0=>'email1#website.com', 1=>'..', 2=>'');
Your link would be
Contact
And then do something like this: email_to($emails[$email_index])
Well, you get the ideea.

If you don't want data to be visible in the URL you should not use GET. Instead take a look at the POST method. But if the problem is that you don't want to show just the e-mail, maybe you could pass an user id (or other variable that is unique for each user) in the URL, and use it to fetch the e-mail on the contact page.
(Please note that just because the POST data is not immediately visible in the URL field, it is not completely invisible. POST data can be easily displayed in different debugging tools.)

Related

Difference between GET and POST? what should i use specially for sending data to a Database ?or carrying a data from this webpage to another webpage?

Question about GET and POST in PHP. i wonder what is the difference between POST and GET and when do you use them respectively?
so as far from i tried, GET can also show the data in the link.
for example, the name of my link is Localhost/index.php then inside my php file is an input box and a submit button. if for example i use GET, if i click the submit button, it will take the data i put in inputbox(for example, name) and add it to the link. so the link now is Localhost/index.php/?name=Tina i think this is how GET works. but if i use POST, it will not show the input data in the link and it will remain Localhost/index.php. (atleast, from what i practice)
i wonder what are other differences between the two and when they should be use? for example im making a website(ex: sign up website) that will take information and send it to a database in MySQL..or the webpage should carry over the from this webpage to another webpage. should i use GET or POST?
You are kind of overthinking it. It is as simple as:
POST - used to post(send) data to the database.
GET - used to get(fetch) data from the database.
So in the case of the form, what you need to do is a POST request, so you send the data to MySQL. And in order to retrieve that data, you will perform a GET request.
See this https://www.geeksforgeeks.org/http-get-post-methods-php/ for a comprehensive explanation.
Keeping it very short:
You never-ever should pass any sensitive information over GET method, because it's visible by logs, by your internet provider/router, third parties.. such as google analytics and more.
A common use of GET is when you allow users to change the parameters of a page they see.. i.e. search parameters or the number of products per page.
POST when you want to send information to the server "privately" and (preferably) with a nonce to make it sendable only once.
But regardless of a method - POST or GET - sanitise, sanitise, sanitise.. that is what you need to really worry about. User input should not be accepted as is when you receive it, kinda #1 rule on the internet.

How to create new webpages automatically based on user input?

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.

Can we hide ID and its value from Query string in php?

I am facing problem with Query String in one of my Joomla Project.
I have video section in my project and also showing top video on home page. so when I link to detail page I am passing id of video. but here my client does not want to show id in string and its also cause some security problem.
So is there any solution to hide that ID from Query string?
Thanks in advance.!
You can do two things to make this work as your client want.
Encrypt the link data and send. At the PHP end decry-pt and use them.
When user click on the link user use a form submission. Pass the value as hidden fields. Using POST method is secure than the GET method. Here also you can encrypt the values you send.

Input Form Externally

I'm not sure if I worded the title correctly but here it goes...
This site: http://www.megavideor.com
In the big input field you can enter http://www.megavideo.com/?v=C6IJJDU6 and then click Load Video, and it will load the video on the right hand side.
I want to make a script where I can enter the field and submit it automatically with a url.
Example:
http://www.mydomain.com/SCRIPT.PHP?url=http://www.megavideo.com/?v=C6IJJDU6
And the above link would automatically enter the url and take you to the page with the video ready to watch.
Can anyone tell me how this is done or direct me to what this sort of script is called, so I can try googling it.
Thanks!
When you enter data into the url like that it's GET data, not POST data.
The form uses POST data, but it can be changed to use GET data as well.
If you want to keep your forum as is, use $_REQUEST in your php instead of $_POST.
$_REQUEST contains both $_GET and $_POST values.

How to display results so back button does not ask to reload POST variables

I have a form that uses XML to get results. From those results users can click to a detail page. My problem is when a user clicks back to the results page, they are asked if they want to submit the form again. How do I create this so back button just displays the results, like on aa.com, ebay, autotrader, etc.
Thanks!
When you submit your page move the $_POST variables into the $_SESSION array and then header redirect the user to the results page.
You should redirect to another page to using redirect() method of codeigniter. This will prevent the browser asking a confirmation on form submission.
Is it just a search page that displays results? Why not use GET rather than POST in your form? Looking at search engines out there, they seem to use GET for their search interface. I can think of a few reasons to use GET rather than POST.
If the operation simply fetches results, semantically, the GET method is more appropriate. GET is used when you are fetching data. POST is more used when you are submitting a change to the application.
If you use GET, clicking on the back button won't give you a dialog asking whether you wish to resubmit the form.
Your users will have a URL directly to a search results page for a particular query that they can share.
Unfortunately CodeIgniter, by default, nukes the query string when processing a request. You can enable the query string in CodeIgniter by following this answer.

Categories