Separate php logic from html document and maintain functionality [closed] - php

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'm having a bit of trouble wrapping my head around this problem.
I have an image map that I can click which sends various GET requests to my PHP script. My PHP script receives these GET requests and search through my MySQL Database to retrieve the appropriate information. My client is re-directed to this PHP page.
This all works and is great, but I need to incorporate Jquery for other functionality. So, I can't use a standalone PHP script.
My solution to this is use my imagemap to open up a HTML file instead, and use an include statement to incorporate my current PHP file.
However, I don't know how to include the PHP file if I need the GET requests created by clicking the image map.
How can I click on my image map, and be re-routed to a HTML page that displays the same information available from the GET requests in my PHP? I want to do this without creating multiple html files for such a small difference of one variable.

should try to use ajax-javascript to combine the php request with the javascript request and then redirect using the combined info.

Related

Scraping data which loaded after scrolling to bottom [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 working with PHP and I want to scrape some data from any website. But I have a problem. I scrape data but these items number are 48. But I know that page has 11K items. Rest of datas extend when you scroll and you get new bunch of datas (48 items).
I'm scraping with simple_html_dom. How can I manipulate scroll and get data ?
Thanks! :)
Sounds like the missing data is loaded via ajax.
Check the Network tab in the Developer Console (by pressing F12). Take a look at the URL which is being called (and the response), and edit it to your needs. Then call this URL instead of the one you are taking now.
It is impossible by this way.
But if you need to scrap this data you can send requests to endpoints which return lazily loaded data. You must research js code of target site.
p.s.
If you want to use really hard approach, you can research browser emulating.

Can we Use php script in Google Tag Manager [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 3 years ago.
Improve this question
Just wondering if a php code could be executed via Google Tag manager?
Thanks
No. The Google Tag Manager inserts client-side Javascript. PHP requires a server that is configured for PHP. Inserting a PHP script via GTM would just output the raw PHP code to the browser, it would not execute the code.
If you want to include the results of a PHP Script you would have to run the script on your own server and fetch the results via Javascript as suggested in UncleRicos answer.
I would look at Custom Events in Triggers here: https://support.google.com/tagmanager/answer/6106961?hl=en&ref_topic=3441647&vid=1-635797415927700239-1991783559
You can specify a javascript event that would be called upon a trigger being executed, which in turn could call a routine via ajax (which could be PHP or anything).

Is it possible to run a PHP file which doesn't contain any 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
Is it possible to run a PHP file which doesnt contain any html?
I have a form, from which I want to submit data to a database. If I were to have the submit buttons action property set to a php file which solely deals with data submission, and then have a redirect on this page to the next visible webpage, would this work?
My reason for asking is I have quite a few different forms, some of which use the same submission code. If I were to have all this on one page and then use conditional logic to determine where the data came from (thus being able to determine what data was submitted and which page to load next) it would make my webpages much more readable, and the submission code much more re-usable.
PHP can take care of all kinds of things behind the scenes. That's the basic meaning of server-side scripting. So yes -- HTML or on-screen presentation are not necessarily in the code everywhere.

What is it called when you use the <script> tag to link to link to a php file? [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 9 years ago.
Improve this question
Our site is linking to php files containing javascript, so the javascript can use php to get data from the database. Here's an example of how these files are linked:
<script type="text/javascript" src="http://www.our-site.com/javascript.php"></script>
My question is what is this called? I've tried using google to help me with coding issues, but it's hard when you don't know what to search for.
Server-side-generated JavaScript would be an appropriate description. It even shows up on Google autocomplete, and there are many results. I am not a fan of this pattern. I find that it is better to keep JavaScript on the view-side completely and just inject the values you need via an init method of some sort.
It doesn't have a special name when it's PHP.
Just make sure you set the header in the PHP file.
Header("content-type: application/x-javascript");
What you have there is nothing special. It's not named somehow. You just include the PHP file, the PHP file gets interpreted and generates any kind of output which then gets included as regular JavaScript.
If you have issues you might just open up the link to the PHP file and search for your problem there.

What is the correct way of doing JQuery/AJAX and php, file structure? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
what way should I structure my files when doing Jquery AJAX requests in PHP.
i.e.
showRecords.htm - contains jQuery/AJAX that gets data (HTML) from the php file below.
showRecords.php - contains php that does some processing, likely to get data from DB and echo some HTML.
or
one file:
showRecords.php - contains the JQuery/AJAX and is the php file and requests data from itself.
also you clever people out there, please note I am a beginner in JQuery
and AJAX so please forgive me if its a silly question or trivial.
Obviously not: one file.
I'd do it this way:
showRecords.php - form processing, db requests
templates/showSomeHtml.php - displays everything that your users can see
showRecords.js - jQuery/AJAX that gets data
And if the jQuery/Ajax modifies the HTML, you could also move that (the dynamic HTML) into the templates (read about javascript templates)
I think it's up to you. If you have a quick ajax call you'd like to do and you know it won't be used anywhere but there then I see no issue with having everything in one file. On the other hand, you might need to access that processing script in multiple locations on your site. If that's the case, it's not ideal to place it all in one file. I think two files avoids confusion. Keeps everything separate and neat.

Categories