I came across a requirement to import my DB-Users to a google-spreadsheet.
I did a code with the help of the below instruction.
http://www.distilled.net/blog/distilled/guide-to-google-docs-importxml/#chapter4
Now i can get all my DB-Users using the below code.
=importxml("http://mydomain.com/v5/admin/export_google.php","//tr")
If i paste the above code in a google spreadsheet i can see all my DB-Users in my spreadsheet.
Now, as far as security is concerned
http://mydomain.com/v5/admin/export_google.php -> If i type this url in my browser, then i can see all the db-users.
I need this file to be password protected. Only my client having the code to import the db-users can view my db-users.
Is there a way to keep the file password protected(export_google.php). I know, i can set a username and password at top of my php file but doing that will it won't work if i paste the code in google spreadsheet.
Could someone help me out.
In other words - my client having the code i.e. =importxml("http://mydomain.com/v5/admin/export_google.php","//tr") can take the db-users in google-spreadsheet. Others should not get the information of my db-users using the php file.
You just need to add some GET var to your request and check it inside your script.
Like so:
=importxml("http://example.com/v5/admin/export_google.php?pass=mypass","//tr")
And inside PHP script:
if (isset($_REQUEST['pass']) && $_REQUEST['pass'] == 'mypass') {
// your code here
}
Related
I'm a bit lost at the moment and I hope that you can help!
I try to recognize people with OpenCV in Python. This is working so far. With the id of the recognized person I want to display information which belong to her or him.
For that I tried something like this:
1)
import webbrowser
webbrowser.open('http://mysite/index.php?userID=XYZ', new = 0)
But although I wrote the "new = 0" it opens a new browser tab everytime an other userID stands in the link.
2) An other approach was to send information via a http post request to the website like:
url = 'http://mysite/index.php'
query = {'personID': XYZ}
res = requests.post(url, data=query)
But doing this I don't have any idea how to work with this post command in my PHP code so it refreshes the site with the data belonging to user XYZ..
May you help me please?
Kind regards
Edit1 - START:
A small php example with using GET parameters would be something like this
<?php
echo("<html><head><title></title></head><body>");
if ($_GET['userID'] == 1) {
echo("<div id='userContent'>Hello User 1</div>");
}
else if ($_GET['userID'] == 2) {
echo("<div id='userContent'>Hello User 2</div>");
}
else {
echo("<div id='userContent'>Public, non user specific information</div>");
}
echo("</body></html>");
?>
But at this point I don't know how to make this site to a dynamic one which shows different information when Python sends a request..
Edit1 - END
This is not possible in webdriver currently. The 0 flag refers to the window, not the tab. See a discussion of this on reddit here. Another question also asked this on Stack Overflow but got no answers.
It is possible however with the much more feature rich package Selenium.
import time
from selenium import webdriver
link1="http://mysite/index.php?userID=ABC"
link2="http://mysite/index.php?userID=XYZ"
driver=webdriver.Firefox()
driver.get(link1)
time.sleep(5)
driver.get(link2)
Selenium does require some installation steps: http://selenium-python.readthedocs.io/installation.html
Regarding using requests, there's no reason you can't do a GET request so you don't have to worry about handling a post request:
import requests
url = "http://mysite/index.php?userID=ABC"
res = requests.get(url)
print(res.text)
Without seeing more of your php code or knowing more details, it is hard to say what approach is best for you but this should get you past the issues you mentioned.
Wow, i hope i have written the title in a correct way, because i really have no idea how this is called.
Let me explain what i am looking for.
I have a simple application. And it contains the following:
- Frontpage (salespage)
- Admin area
- Member area
- Database to provide the app of data
I have hosted the basics of this application on a server, let's call it 'www.the.app'. And i have written it in PHP using Laravel.
Now i want to use the functions of the app, which is hosted on www.the.app and use the functions like the admin area, member area, the frontpage and create my own database on 'www.awesome.app'.
What would be the best way to make such a thing happen?
I am not looking for direct solutions. I am just looking for information to point me in the right direction to be able to make the above reality. Anything would be apreciated, like information, a name i can search on, what ever is related to this.
And if there is any more information needed, let me know please :)
Here is exactly how you can do it :
1) To Auto Login To The Site :
Note : As you will need to probably get data from login based site so you can auto login to the site through using CURL while using User Credentials with it.
To Learn How To Login Through CURL.Take A Look At :
Using PHP & Curl to login to my websites form
2) Extracting Data After Logging In Through CURL :
Note : After logging to the site now you will need to use PHP DOM to extract data from the site.So you can extract data something like this way by using PHP Simple HTML DOM Parser Library.
PHP Simple HTML DOM Parser :
LINK : http://simplehtmldom.sourceforge.net/
Sample Code For Downloading All Images From A Link :
Note : Following code will download all the images present at the URL given in the code.
<?php
// Make sure to include the library php file
include('simple_html_dom.php');
//URL To Download Images From
$url = "http://www.facebook.com/"
// Create DOM from URL or file
$html = file_get_html($url);
// Find all images
$i=1;
foreach($html->find('img') as $element) {
$url = $element->src;
$img = "/my_folder/image_".$i.".png";
file_put_contents($img, file_get_contents($url));
$i++;
}
?>
Preface: I started learning Python one month ago, please don't yell at me :)
I have a full developed site written in PHP, with all the functions I need with pages to insert "stuff" in the database. I am developing a command line program to insert the same thing and send them to the PHP scripts in the $_POST array, but I have no idea on how to send the file so that it would come up in the $_FILES array.
Here is what I have so far:
I send the $_POST values using the urllib modules and it works just fine
import urllib.request
import urllib.parse
data=urllib.parse.urlencode({"hello":"Yo!", "some":"AlphaBetaParkingLot"})
data=data.encode('utf_8')
request=urllib.request.Request("http://www.site.it/read_from_py.php")
f=urllib.request.urlopen(request, data)
out=f.read().decode('utf-8')
if out[0]=="1":
print("Connection acquired!")
else:
print("No connection!")
print("Exit!")
#Then actually exit!
...I read the filename from the local computer by prompting a choose file dialogbox...
from tkinter import Tk
from tkinter.filedialog import askopenfilename
Tk().withdraw()
filename=askopenfilename()
...but then I have no idea on what to do with the filename. I have looked around and I have seen no way on how to send this to the $_FILES in PHP.
I have a "dirty" solution: creating a temporary html with a form just with the file and make it choose from there, but I was wondering if there was a cleaner solution.
Thanks!
P.S. If you are wondering if I have all the things I need in the PHP scripts, why would I need this Python program? Well, you would be correct, I wouldn't need it but it's not up to me...
Try Like This
import urllib,MultipartPostHandler,urllib2,cookielib
cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),MultipartPostHandler.MultipartPostHandler)
urllib2.install_opener(opener)
login = urllib.urlencode(dict(admin_user='admin',admin_pass='****'))
o=opener.open('http://some_domain_name.com/admin/index.php',login)
print o.read()
raw_params={"adtitle":"sample title",
"area":"sample area",
"addesc":"<p>sample post</p>",
"pic[0]":open("indian_eye.jpg", "rb"), #File Goes Here
"pic[1]":open("nature.jpg", "rb"),
"subcatid":"1",
"do":"post",
}
url="http://YOUR.php?cityid=15&subcatid=1"
opener.open(url, raw_params)
Hope it works!
At first apologies in advance if there is some problem in my ques, i am new to heroku ,my basic problem is i have some messed up code, where i want to test if i am able to fetch facebook variables in my own code and use them..
in my .php file i want to put name for person using my facebook app to displayname array variable of array and url of array should get the application users picture..i took the idea to assign these value via the index.php file provided by facebook itself.
My .php file code is :-
$basic = $facebook->api('/me');
$options = array(
'displayName' => he(idx($basic, 'name')),
'image' => array(
'url' => 'https://graph.facebook.com/'.he($id).'/picture?type=square',
'height => '48',
'width => '48'
)
);
but there is something wrong going here which i cant figure out.
i tried to debug it via javascript or other techniques but now able to connect the .php file to some .js file by any means to transfer variable values present in .php file and print them on my browser,i use to edit code at my own system and push it via git and since the code is executed at heroku i cant figure out what errors are creping in..i am using free account as per now so is there any way i can see my code in execution at heroku.. or any help to debug my code efficiently..
Edit1: alternatively is there any way i can pass these variable from my .PHP file to a separate .JS file and print variables in message box or something..any example code given will help a lot..there are many questions asked in this regard to transfer variables from separate .PHP file to separate .JS file..but i found no direct answer for it, all suggest workarounds but no direct way... questions i visited for it are ..
What's the best way to pass a PHP variable to Javascript?
Grab/input php variable in javascript?
and some more but dint find the perfect answer.
Edit2: if my ques needs more info plz let me know,and if second option is the choice left to debug my code ..then can someone give me an example with transferring variable/array present in testfile.php file say present at appfolder/php/lib/testfile.php and output it on browser in HTML format using testjs.js file say present at appfolder/lib/js/testjs.js
A common exchange format between PHP (or other language) and JavaScript is JSON. You can encode an array (or an php object) to json using json_encode, in PHP. Like this :
$options_json = json_encode($options);
So, you can write this javascript variable in your html results, like this :
echo '<script>var options = ', json_encode($options), ';</script>';
Your picture will then be accessible using javascript :
console.log(options);
console.log(options.url);
I want to access some function written in some php file on another server and receive the input, I have access to those server files so that I can change them for proper configuration, I have all the privilleges to do so, can anybody please guide me how can I do it, thank you
$result = file_get_contents("http://some.server/out.php");
and in this out.php
<?php
include 'some.php';
function();
I think you can implement web service or an api, and the output could be in xml or json read the content and use it on your website.
It is just Facebook graph API using URL
https://graph.facebook.com/Pepsi
The above link will fetch information regarding Facebook page of Pepsi.