Mimic browser hit from php script - php

I have a script which logs you into zencart when you open it in your browser.
Now when I try to call this from inside another php script using require, header, or curl, it does not login to zencart. It only works when the user opens the php script directly in their browser.
I also tried virtual(), but its running the index.php script for the top level of the site, not the file I specify. Thanks.

I got this working by reading the session from the database. Let me know if anyone is interested and I will open up a github. Thanks!

Related

Open HTML Content of PHP file in browser for Website Debug

Whenever I have to test a design change on an HTML page that's written within an PHP file, I have to make the effort of first uploading it to the webpage and then viewing it through the browser. Normally, if it was an HTML file, you'd just update the browser and see the changes locally. Of course, it's not possible to execute PHP on a browser unless you use XAMPP or whatever, but I consider that to be too much for simple debug. Isn't there a way to open a PHP file as just HTML, ignoring all PHP code for debugging purposes? If not, then I'll just get it with XAMPP. Thanks in advance.
PHP has a built-in webserver, you can utilize that i guess.
php -S localhost:8080
If the script does not require the http stack (which i doubt), you could also do:
php index.php > index.html
Update:
After you executed the command above (php -S), simply type the same url in your browsers address bar.

Using batch code in php

Is it possible to make a php code on a webpage send out a code that the visitor will run? Like:
<?php
batch("echo text");
?>
Then it will open a cmd window that says text. If it does not work in php does it work in another launge?
PHP runs on a server and has no magical control over what happens on someone else's computer. Once the page has loaded it will be send to the requester's browser.
From there you have access to some local storage/cookies/etc., but only what the browser provides to you. If the browser would give a website access to the cmd, it would mean that any website could simply read pretty much everything on anyone's computer, or do harm in many other ways. You can imagine that this is not really secure.
The only way you can execute batch commands on someone's computer is if you or your program have access to that computer. In other words, the user must download your batch/.exe file and run it manually.

PHP Script in CPanel not running

I was transfering my website from Hostgator to a new server.
When I open the PHP page in my website, it will download the page rather than execute and showing the page, but if I open the HTML page, image, etc. It will open it like it should be.
What should I do so my Website can run the PHP script and showing the page rather than downloading it?
Add some handlers to your .htaccess file so that it will recognize the php files and execute them as they should be

Download processor implementation

I will try to explain on example.
There're files on the web I publish (let's say, something.pdf or thefile.zip). I want, before actual download when user follows the link to file, some php script to be invoked which then will return the requested file. How to do it? Please advise. Thank you!
Edit 1: thanks amadeus. In my case PHP script is located on the other server than web site and files to download = PHP script will need to read file from remote web server and send to client, which is extra traffic... I actually does not need PHP to control file download. It is ok to have it downloaded from the web server, but I want PHP script to be invoked when download is requested (to gather info on who is downloading and how many times).
Edit 2: thank you Pekka. I just realized that it is even more complex. Imagine server1 is webserver with downloadable files on it (no php), and server2 is php server. If I just give "server1/thefile.zip" I will be unable to invoke script from php server. Then it seems I should use "server2/script.php?thefile.zip" which will then just redirect client to the file on server1. Is it the best implementation in given conditions?
It is ok to have it downloaded from the web server, but I want PHP script to be invoked when download is requested (to gather info on who is downloading and how many times).
That's easy to do by calling
header("location: http://externaldomain.com/externalresource.zip
from your PHP script when you are done counting.
This will redirect the browser to the external resource.

How to use phatomjs from PHP to exec Javascript on a downloaded page?

I am working in an "autobrowsing" script. My script should be able to download certain pages and then parse these for finding certain values, and so generate an output. Also the server needs authentication.
I have been able to get these pages using CURL lib from PHP, including the authentication part, but the problem is that the contents of these pages are generated within javascript functions, so after downloading them with CURL functions, most of the contents are missing because the JS code isn't executed.
So, what I need is the DOM after the JS is executed. I have spent sometime figuring out the best approach for this, and I am not sure to have found it. Anyway It didn't work for me yet, so...
What I did was install phantomjs on my Linux box, and try to use it just for execute the JS code in the pages downloaded. So, I download the page using CURL and save it as "test.html" file, then I exec "phantomjs test.html", but all I get is this:
$ phantomjs test.html
undefined:1 SyntaxError: Parse error
And it does nothing more, like it were hanged.
test.html contains both, html and JS code within script tags, you know, as every other so common webpage with JS.
Anyway and to be sure that it was not a problem with test.html, I downloaded the index.html page of google.com with wget, and I have obtained the same result:
$ phantomjs index.html
undefined:1 SyntaxError: Parse error
So I concluded that I must be doing something wrong...
Any help is welcomed. :-)
Bests,
The reason phantomjs index.html will not work is because the first parameter you pass into phantomjs is the phantomjs script you wish to execute, not a html file. I would recommend using phantomjs to open the webpage directly as oppose to passing a html file into it. There are quite a few examples of how to do this, even look at the one on the home page of http://phantomjs.org/. For more advanced features see the API. If you have any more specific questions then ask here.

Categories