Retrieve ASP.Net's User.Identity.Name in PHP - php

i am using form authentication for my website which is written in ASP.Net, but i have a PHP script that i need to run. Is it possible to get the value of User.Identity.Name in PHP ?
thanks.

Yes, if you pass it on to the PHP page using POST or GET (Querystring or Form), meaning getting the value from an ASP page first and then sending it to you PHP page. You can also take a look at this question on Stack Overflow, which offers a different solution.
*Edit: Possible solutions:
Using IIS7 Forms Authentication with PHP files
How to Share Session State Between Classic ASP and ASP.NET
The second one could work for PHP as well with a bit of creativeness.

why don't you just store the User.Identity.Name from the ASP.NET page in a session, and then when you call the PHP page you can just retrieve it from that session?
As long as its the same site, it should work.

Since you mentioned loading the PHP script in an iframe, you want to do something like this:
<iframe src="myscript.php?username=<%= User.Identity.Name %>" />
This passes the Identity name along as a GET parameter, as suggested by Boekwurm.
Then, in your PHP script, grab it like so:
username = $_GET["username"];
Depending on what you're doing with it, you may need some security in place to prevent people from running the PHP script with arbitrary username parameters.

Related

How do I constantly update a variable in PHP as a user changes input?

I looked for answers to this question, and it seems that most people have a specific problem. I'm looking for a more general answer. I have a text box where a user will type in their name and I would like to have PHP constantly monitor the text box and change the value of the $name as it is typed or edited.
I would also like to do the same with buttons, and as different buttons are clicked, the content of a variable would change to match that which the button represents. Basically, is there a way to get PHP to constantly run on the page and gather information from a user as it is changed?
It seems like it should be possible, but my experience with PHP is limited, and I'm not sure how to begin, so I don't have any code to really show.
This sounds to me like you require an ajax script checking for input changes(eg/ keystroke, on_blur or on_click for your buttons) and sending back to a php script that will update your variables/tables and return the new variables to the ajax script once they are updated.
1 - Ajax checking for changes on the page, and firing off to a php script on server.
2 - Have a method in your js that waits for the action to be completed and load the new variables into the HTML document.
Basically look up Ajax/PHP - Check username availability, Then adapt to your specific needs.
:)
Simple ajax script will be what your after, there are many scripts available for checking username availability --- As for a lone PHP script, this will not be possible as the PHP code has already ran on the server before the html document is rendered to the browser.
My first answer so my wording may not be perfect comment back if i have confused you more.
It seems like it should be possible, but my experience with PHP is limited, and I'm not sure how to begin, so I don't have any code to really show.
Yes, it's possible, but most likely only due to the nature that the browser (e.g. Firefox) and PHP itself are Free Software.
A proof of concept is missing so far, so you really need to start at a very basic level.
You can download these software packages and modify them to your needs, e.g. make the browser interactively corresponding to the DOM and DOM events process PHP scripts that you embed like script tags inside HTML.
But well, as you wrote, you're starting, so I guess, you don't want to start with rewriting the browser and the PHP interpreter, so even if possible, it's perhaps best to stick that interactive part inside the browser to Javascript and some HTTP request / response programming on the server with PHP.

Simple PHP web crawler to submit form and store the returned results

For a system I am developing I need to programmatically go to a specific page. Fill out one field in the form (I know the id and name of the input element), submit it and store the results.
I have seen a few different Perl, python and java classes that do this. However I would like to do this using PHP and havent found anything as of yet.
I do have the permission to do this from the site i am getting the information from as well.
Any help is appreciated
Take a look at David Walsh's simple explanation.
http://davidwalsh.name/curl-post
You can easily store the response (in this example, $result) in your database or logfile.
Usually PHP crawlers/scrapers use CURL - http://php.net/manual/en/book.curl.php.
It allows you to make a query from the server where PHP runs and get response from the website that you need to crawl. It returns response data in plain format and parsing it is up to you. You can manually check what does the form submit when you do it manually, and do the same thing via curl.
You also may try phpcrawl (http://phpcrawl.cuab.de), seems to fit all your needs.
(See "addPostData()"-method)

grab a variable value from external webpage for processing?

Let me just start by saying I know almost nothing about PHP but, I think that may prove to be the best way to do what I'm trying to do. I'd like to grab the value of a variable from an external page so that I can then process it for the creation of graphs and statistics on my page. An example page that I'm trying to get the variable from (requires a Facebook Account) is - http://superherocity.klicknation.com/game/pages/battle_replay.php?battle=857337182
The variable name is fvars and it contains data about what the 2 players used for attacks, how much damage they did, etc. Ultimately what I'd like is to provide a page with a form where a player can go and plug in their replay link (like above) and get a nice neat detailed breakdown of the battle.
At the very least, if someone could explain to me how to just echo out the value of fvars after a form submission with the replay url as input it would help out immensely!!! I've tried looking at some PHP references and other posts here but, have so far been lost. :(
Thank you for any help or guidance.
One way you could approach it is to use Selenium. You would need to setup the selenium server and a browser and then write a selenium script to fetch the page for you. The key point here is that selenium can run a firefox client with javascripts, facebook logins etc, everything you have on your ordinary firefox, through selenium programmatically.
I run selenium in a Linux environment and control it through php cli scripts. I run the java selenium-server-standalone along with framebuffered X and firefox. PHP Unit test library allready has an extension though you wouldn't need it for testing obviously.
You can get the contents of any webpage like so:
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
And then just use regex or basic searching to find the variable you need in $homepage. The problem is that you need to be logged in via Facebook. I know of no current way to do this dynamically with PHP.
Mike
Edit: found an SO question that addresses this exact issue - Scraping from a website that requires a login?

Extract information from javascript counter via PHP

I'm looking for a way to extract some information from this site via PHP:
http://www.mycitydeal.co.uk/deals/london
There ist a counter where the time left is displayed, but the information is within the JavaScript. Since I'm really a JavaScript rookie, I didn't really know how to get the information.
Normally I would extract the information with "preg_match" and some regular expressions. Can someone help me to extract the information (Hrs., Min., Sec.) ?
Jennifer
Extracting the count-down time is not going to be easy, because it is fetched and set purely using JavaScript, which cannot be parsed using pure PHP. You would have to de-code the JavaScript code and see what calls it makes to fetch the initial times.
That is not an easy process, and could be changed by the site owners in no time.
Also, doing that, you would be in clear breach of their T&C:
For the avoidance of doubt, scraping of the Website (and hacking of the Website) is not allowed.
I hate to say "no", but in this situation PHP is not the right job for this. JavaScript requires a browser to run (in this case) and on top of that you probably have a jQuery lib.
The only thing PHP could do is invoke a browser that would contain some JavaScript (i.e., GreaseMonkey) that could try and scrape the page for the info. But this is really a job for embedded JavaScript.
As the others have said you can usually not access JavaScript stuff from PHP. However JavaScript has to get its data from somewhere, and this is where to start.
I found this in the source code:
<input type="hidden" id="currentTimeLeft" value="3749960"/>
That's the number of microsecond until whatever it is.
However this was only present in firefox, not when fetching it with wget. I found out it's the cookie that matters, so you'd have to request the page once, store the cookies and then access it a second time.

Send a Variable to an IFrame's Parent in PHP?

How can I transfer an array from an IFrame running a php script, to the parent PHP of the IFrame?
I have an Array of strings in PHP that need to be transferred to the main window so that when the iframe changes pages, the array is still stored.
I could use a cookie for this, though I'm not sure that would be the best idea.
Thanks.
you can't do that in php. iframe is like a new browser window, so they are separate requests. separate requests can not transfer data between each other in a server side language.
if you give some detail as to what you're trying to accomplish, there may be another way around the issue that someone can suggest.
Like Tim Hoolihan said, PHP is a server side language that is only responsible for generating the HTML before it is sent to the browser. Meaning once the page shows up in your browser window, PHP has done it's part.
However, with that said, if you control both the "parent" page and the page being iframed, you can json_encode the array in the page being iframed and set it to Javascript variable, then on load pass it to a Javascript function on the parent page (assuming not violating any browser/domain sandbox constraints). At that point you can do whatever you want with it.
Take a look at jQuery for your core Javascript/Ajax needs.
if you control the iframe, you can save the array in a session variable and make the parent do an asynchronous call to retrieve the array from session.
however Jordan S. Jones solution with only javascript works as well

Categories