How do I send to the current page? [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 7 years ago.
Improve this question
In my page I have a bunch of instances where (using php) I have links sending to the same page with query strings (?action=x) so that when it sends to the same page at the beginning of the page it will see that _GET[action] isset and perform the desired action.
FOR EXAMPLE: Say you want to allow a user to delete a comment made at the end of one of their posts (on a blog). The way I learned to do it is to make the delete button a link to "currentpage.php?action=delete". Clicking the button will in a sense refresh the page where the page will see that _GET[action]=="delete" and run the code to delete the comment.
Is this the best way to do this? Is there not a way to make a click of a button cause code to run (in php) without having to refresh the page?
In addition to causing the user to lose their place in the page, there are certain cases when I won't know the actual page url and need to reference it (like if you have a "comments" function in a file that's required on each page so that you don't have to use the code to display the comments on every single page that has comments). So, I'd need a way to reference the current page in the link since I won't know it ahead of time. Is there a way to do that?
I apologize for not being clear enough earlier. Is this any better?

Take a look at the $_SERVER superglobal. It contains all the information you'll need about the current request, to reconstruct it.
echo '<pre>';
print_r($_SERVER);
echo '</pre>';

Related

How to I keep a log of urls when a link is clicked? [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 have a link called "Click Me" on 100 pages on my website. When a person clicks this link, I need to be able to write the url of where the click came from into a txt file or send me an email everytime the link is clicked.
Any ideas?
Fragments of code are requested here, please update your question. I will give you an idea on how to acomplish that:
In my opinion the general idea that will work best is:
Monitor user click with jQuery only if content is Click me.
When content of click is "Click me" load some php file via Ajax that will monit the click
Load this file with some parameters (?referer=...)
PHP file will append this $_GET['referer'] to a txt file
Remember that user can manually scam Your clicks (go to php file, and refresh it). You must think of some anti scam filter (for example after clicking lock IP clicks for few seconds or add some random hashes / etc to Your url).
Hope it helps, for more info, please upgrade your question with some code.

Keep track of user selected elements even after they leave the page [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 years ago.
Improve this question
I am making an enrollment system in which users can select courses that they wish to take. It is a multi-page website where users first select a topic then they are directed to a new page where a list of courses associated with that topic is loaded from a MySQL database. When the user finds a course they want they click on a button and the course is added to a session variable with an AJAX call. I want to add an image or text that lets the user know that they added that course once they do. Currently there is no way the user can tell if they added the course or not. This of course is easily done when the user first adds the course. I can have a hidden image that is toggled on click. This however will be forgotten on page reload.
The question is, how can I flag the course(s) they added if they reload the page or leave that topic's page and later come back to it?
A possible solution that I came up with was to upon every page load to search the list of courses that are in the session variable for matches on that current page, then set the "Added" image to visible using jQuery. Is this a good solution? Is there a better one? I hope this is not too open-ended.
yes you can do it as you described on your own (the jQuery way)
maybe a:visited could do the job for you (i don't think so but you never know before trying)
regards :)

PHP Include = AJAX? [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 8 years ago.
Improve this question
I think this will be quite a stupid question, but is the PHP include comparable to AJAX? Because I made a little page in which i load the contents via one index.php in which i have a pages array with every content page. And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
Can someone explain me, where the difference between AJAX and include is? Or is include in fact reloading the page rather than "swapping" contents?
is the PHP include comparable to AJAX
No.
Ajax is the process of making an HTTP request from JavaScript without leaving the current page.
A PHP include just includes some content (and may run some PHP) when the page initially loads.
And when I click on a link in the nav it seems to dynamically get the content, rather than reloading the page.
If that happens, it isn't because of an include.
The most you could get from an include is to load a complete new HTML document which has some content that is identical to the previous HTML document.
If the page loads very quickly then the user might not notice the whole page reloading, but it will still do that.

Adding HTML search terms to results page URL [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Currently I have a search box on site.com/search.php. A user enters in a search term and is taken to site.com/index.php which displays the results for the search terms. Except, no matter what a user enters, the results page URL will always just be site.com/index.php - instead, I want it to read site.com/search=word1+word2 or something like that so that each page has a unique URL based on the search input.
I also want it to work in the reverse way, so that someone could, in theory, go straight to site.com/search=query and it would be the same thing as if they first went to the main search page, typed something in, and hit return.
I'm new to programming and recently started learning about the .htaccess file which I understand I'll need in order to do this. I am just at a total loss as to how to do what I want. I know I need some sort of URL re-writing but not much more than that.
The easiest approach here is to change your search form to use method="get" instead of method='post'.
This will create a URL like:
site.com/index.php?search=word1+word2...
Simply change the search script to use $_GET or $_REQUEST instead of $_POST and you'll be all set without any other significant changes. It will also let users directly run searches via the URL.
The only downside of this approach is that it does not create a beautiful URL (i.e. is still shows "index.php")... however, you can easily work around this by using .htaccess to rewrite the URL.

Pulling info from an external page [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 8 years ago.
Improve this question
Okay, bear with me. Part of my job is filling out online forms for customers who call in. In these forms there are all kinds of useful information that is hidden in input tags. I would like to make my own page that would extract and display all this useful information. I would also use this page to count the number of times I submit the form throughout the day.
The way I currently have it set up it is in a frameset. The left frame has links to the different forms we fill out, and when I click on one the external form is populated in the right frame. Javascript would be perfect for the job except that my frame is not located on the same server as the forms.
I stink at PHP. Not gonna lie. So i'm not looking for any hand-outs but any pointers would be great.
For example you may check out the forms on http://www.youcangetacar.com and you may use the pin code "A101" or you can check out what I have so far at http://customertrack.host-ed.me/
Make a page that cURL’s the page that is passed to it via url(curl.php?url=http://www.google.com) and then you dont have trouble with same domain policy.
Don’t forget to string replace relative urls with absolute urls.
eg, action="/submit/form.php" must become action="http://www.domain.com/submit/form.php"

Categories