PHP - How To Identify The Browser Tab That Sent A Request?
I need to be able to identify the browser tab that sent each request the server receives.
I originally planned to do this by passing an ID back from each web page. However, I found that when the user leaves a web page by clicking a non-form button or a link, this causes huge problems. The ID really has to be returned via POST to prevent users from using it inappropriately, and the prospect of making a button or link do a POST is not appealing. Is there any other technique I can use? I've examined all of the superglobals, but I didn't find anything that would work. Similar TutorialsHi, suppose the user requests a page www.foo2.php. Now if it is a link embedded in another page, say www.foo1.php, then Javascript can send the server browser info before furnishing the page. But is it possible to let the server know which browser is being used when the user requests the page by just typing the url http://www.foo2.php and hitting enter? Doing something wrong, but don't see it. How should one retrieve a POST parameter? My $request->toArray()['html'] works, but I am sure it is not the "right way". <?php namespace App\DataPersister; use ApiPlatform\Core\DataPersister\DataPersisterInterface; use Symfony\Component\HttpFoundation\RequestStack; class ArchivePersister implements DataPersisterInterface { public function __construct(RequestStack $requestStack) { $request = $requestStack->getCurrentRequest(); syslog(LOG_ERR, '$request->getMethod(): '.$request->getMethod()); syslog(LOG_ERR, '$request->getContent(): '.$request->getContent()); syslog(LOG_ERR, '$request->request->get(html): '.$request->request->get('html')); syslog(LOG_ERR, '$request->query->get(html): '.$request->query->get('html')); syslog(LOG_ERR, '$request->get(html): '.$request->get('html')); syslog(LOG_ERR, '$request->toArray(): '.json_encode($request->toArray())); syslog(LOG_ERR, '$request->toArray()[html]: '.$request->toArray()['html']); } } output $request->getMethod(): POST $request->getContent(): {"project":"/projects/1","description":"","html":"<p>{{ project_name }}</p>"} $request->request->get(html): $request->query->get(html): $request->get(html): $request->toArray(): {"project":"\/projects\/1","description":"","html":"<p>{{ project_name }}<\/p>"} $request->toArray()[html]: <p>{{ project_name }}</p> Hello, I'm using this plain and simple script below to count page views. Is there a way to identify a spider bot with php and then do something like.. if this visitor is a bot, don't count it. If not, count it? Here's my simple script: Code: [Select] $querySelect = mysql_query("SELECT * FROM video WHERE video.id = '$_GET[id]'"); $rowcount = mysql_fetch_assoc($querySelect); $count = $rowcount['counter']; if (empty($count)) { $counter = 1; $insert = mysql_query("INSERT INTO video (counter) VALUES ($counter) WHERE video.id = '$_GET[id]'"); } $add = $count+1; $insertNew = mysql_query("UPDATE video SET counter='$add' WHERE video.id = '$_GET[id]'"); thanks, Ryan I was just wondering what the best way to identify an empty set is. At the moment I have this but this doesn't seem to work so I was wondering what the best way is. Thanks. $article_rs = mysql_query($article_sql, $mysql_conn); if (!$article_rs) { $_SESSION['no_articles'] = "<p>Sorry but there are no articles that match your search.</p>"; } Hi, how to identify whether the array is single or two dimensional array? Good Evening, What I am trying to do in here is to display data based on my selected option in the drop down list. I don't have submit button, I just want it to automatically display results based on my selection. Here's my code: <link href="add_client.css" rel="stylesheet" type="text/css"> <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["territory"])) { $query .= " WHERE territory LIKE '%".$_POST["territory"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="trustlist.php" method="post"> <table width="293" border="0"> <tr> <td width="140" align="left" valign="middle"> SEARCH RECORD: </td> <td width="143" align="center" valign="middle"><select name="territory" id="territory" style="width: 143px" width="230"> <option selected="selected" disabled="disabled">Select Territory</option> <option>Territory 01</option> <option>Territory 02</option> <option>Territory 03</option> <option>Territory 04</option> <option>Territory 05</option> <option>Territory 06</option> <option>Territory 07</option> <option>Territory 08</option> <option>Territory 09</option> <option>Territory 10</option> </select></td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="148" align="center" bgcolor="#E0E8F3">Acute Trusts</th> <th width="262" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 AsiaLimited. All rights reserved. </td> </table></td> </tr> </table> Hi Guys, I keep getting the following error: Parse error: syntax error, unexpected T_ECHO in /Applications/XAMPP/xamppfiles/htdocs/pet/petCatalog1.php on line 51 I have copied the code from a tutorial and cannot for the life of me work out what the problem is with line 51???? I have attached the file and pasted the code below. The real problem line is: echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" The full code is attached - btw, inserting the ">" does not help to fix it!! <?php /* Programme: PetCatalog.php * Desc: Lists all pet categories with radio buttons */ ?> <html> <head> <title>Select a Pet Category</title> </head> <body> <?php /* Database login info - Move to an Include */ $host="localhost"; $user="root"; $passwd=""; $dbname="information_schema"; /* Establishes a connection with the databse */ $cxn = mysqli_connect ($host, $user, $passwd, $dbname) or die ("Could not connect to the database JAMIE!"); /* SQL Query to select all categories of pet from the petType column in the pet table */ $query = "SELECT * FROM PetCatalog.petType ORDER BY petType"; $result = mysqli_query($cxn,$query) or die ("Unable to connect to the database JAMIE"); /* Echo of H1 & H2 above the pet table */ echo "<div style='margin-left: .lin'>\n <h1 style='text-align: center'>Pet Catalogue</h1>\n <h2 style='text-align: center'>The following categories of pets are now available</h2>\n"; /* Create form to diplay pet categories */ echo "<form action='ShowPets.php' method='POST'>\n"; echo "<table cellpadding='5' border='1'>"; $counter=1; while ($row = mysqli_fetch_assoc($result)) { extract ($row) echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n" echo "<input type='radio' name='interest' value='$petType'\n"; if( $counter == 1 ) { echo "checked='checked'"; } echo ">$petType</td>"; echo "<td>$typeDescription</td></tr>"; $counter++; } echo "</table>"; echo "<p>input type='submit' value='Select Pet Type'> </form></p>\n"; ?> </body> </html> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=345438.0 I have approximately 2,300 videos embedded on my site, and I am constantly adding more. The videos are hosted by YouTube. When a video is deleted from YouTube, it becomes unavailable on my site. Each video's ID is in my MySQL database. A video ID looks like this: ZFOuxAx-dkc I need a script that will do the following: select the IDs from my database check if the videos are still available on YouTube create a list of the videos that are unavailable. If possible, it would be great if the script could also tell me if any of the videos have been blocked in certain countries. The script has to be fully commented so that I can understand it. I want to run the script manually every few days. I don't want to have to change my database tables. I've been told that you can use YouTube's API or YouTube's oEmbed interface. I've also been told that, because there are so many videos, you will have to use cURL multi handles. If interested in this project, please PM me your price. This is an urgent project. I have placed ads elsewhere. hi, can anyone please check my code it has an error Quote invalid content type for request: application/x-www-form-urlencoded Code: [Select] <?php $request = "<?xml version='1.0'?><request><br> <authentication><br> <username>username</username><br> <password>password</password><br> </authentication><br> <operation>getResellerProducts</operation><br> <params><br> <int>22</int><br> </params><br> </request></myXML> "; $url = "https://testapi.ssl.trustwave.com/3.0/"; // fake - obviosly! $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // what to post curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($ch); curl_close($ch); print $result; ?> thanks! Hi Everyone First off I don't know PHP except the includes statement which I use regularly to make the site a little easier to update. But anyways am having an issue. I am trying to make a standard template page. On a prior site I had it set up this way with the code I will post below and it worked for me but I have tried to implement it on this site and am not having any luck. Few things on the code below. It was designed for another site. So what I need is as follows. The home page should bring up the default index.txt file. That has the home page info on it. Second the code below has a table in the coding as I required a table on my site so that is in the code but for this site don't need the table. There is also one image in the code. That too is no longer required. I will just leave these in place that way you can see the code I am working with so you can hopefully correct it to work for me as I am going nuts trying to get this to work. Also somewhere in the coding it seems maybe there is an open link tag as I did get this to work a little bit but for some reason when it was the TXT file information was also being made to be a link even though the txt file for time being only contains basic text no coding what so ever. Now what I need is as follows. Default home page TXT file loaded when home page loads. But the link below is what I was using for my site and when this was clicked it would load the TXT file for that page so the example link below would open up a members page that was associated with my message board I was using. Code: [Select] <a href="members.php?categories_file=Members">Forum Members Websites</a> that link would bring up file members.txt which was stored in the text folder Below is the code that in both cases was and is placed in the main window of the table I am using for layout. Last time this all worked perfectly but this time not sure why it refuses to load the page like it use to. Can anyways sort this code so it works fine for me. Thanks!! Dave Code: [Select] <?php if ($_GET['categories_file']) $fp = fopen("text/$categories_file.txt", "r") or die("Could not open $categories_file."); while (!feof($fp)) { $line = fgets($fp, 512); $categories[] = $line; } asort($categories) or die("Could not sort array."); $table_column_counter = 0; echo "<table border='0' cellpadding='0' cellspacing='0' width='90%'>"; foreach ($categories as $item) { if ($table_column_counter == 0) { echo "<tr>\r\n"; } $link = explode(",", $item); echo "<td><img src='images/green.gif' width='13' height='13'><a href='$link[1]' target='_blank'>".$link[0]."</a></td>"; if ($table_column_counter == 2) { echo "</tr>\r\n"; } $table_column_counter = $table_column_counter + 1; if ( $table_column_counter >= 2 ) { $table_column_counter = 0; } } ?> I'd like to use an application that's not browser based, on Internet Explorer. I've read somewhere that this is possible with a PHP script, but which one? If you can get me on the right track, I'd really appreciate it. Cheers. I'm struggle to build an appropriately formatted URL request for a particular API (not really important which, but it's for Toodledo). The API documentation says: Quote Tasks are edited by POSTing a URL encoded JSON encoded array to the API. Each element in the array will be a task object. You only need to set the fields that you want to set. For efficiency, you should try to send only the fields that have changed. At this time it is not possible to post XML data to Toodledo. http://api.toodledo.com/2/tasks/edit.php?key=YourKey; tasks=[{"id"%3A"1234"%2C"title"%3A"My Task"}%2C{"id"%3A"1235"%2C"title"%3A"Another Task"%2C"star"%3A"1"}]; fields=folder,star I've tried about 100 different combinations of code like the following: $arr = array ('id'=>$id,'completed'=>1,'reschedule'=>1); $tasks = json_encode(array($arr)); $params = array('key'=> $this->key); $params['tasks'] = $tasks ; $params['fields'] = 'id,completed,reschedule' ; $url="http://api.toodledo.com/2/tasks/edit.php?".http_build_query($params) ; $response = file_get_contents($url); None seems to get me to a URL formatted like they ask. Can someone help me out? I'm tired of banging my head against the table. [Note... the fields I'm passing in single element of the $tasks array are different than in the example... but it's the format, not the content, that I can't get right] Thanks in advance! I'm looking for a way to get the full url of the current page. something like $_SERVER['REQUEST_URI'] but the full thing. request uri doesn't work well for my situation, because my script is in a subdirectory of a domain. http://localhost/script. When I use request uri, it also includes "/script", which it should. Is there anyway to request the full URL? I am very confused at an example in a book I am reading called Beggining PHP regarding XML-RPC requests. I will write the code below: function send($remoteServer, $remotePort, $fullXMLRPCRequest) { $headers = ''; $data = ''; $socket = fsockopen($remoteServer, $remotePort); fwrite($socket, $fullXMLRPCRequest); while ($str = trim(fgets($socket))) { // why doesn't this exhaust the returned call?? $headers .= $str . "\n"; } while (!feof($socket)) { $data .= fgets($socket); } fclose($socket); return $data; } The question I have is notice how there are two while statements and they both access the same resource ($socket). So how can there be two while statements?? Wouldn't the first while statement exhaust the resource and there would be nothing on the second while statement? I hope this makes sense. It's sort of like saying while(x < 10) { //execute... ++x; } then another while statement while(x < 10) { //execute... ++x; } Well then wouldn't the second while statement not execute? I hope I made sense. Thanks for all the help in advance. Obviously knowing XML-RPC would help in answering this question, hopefully most of you are familiar with it. Hi, I don't know very much about php. I don't know any at all, actually. I play a game called Roblox where you get to use the programming languange, "Lua" to script your own games. What I am requesting has been done before on this game, but I only know Lua. I was also told PHP cURL is needed. Anyways, let me get to the point. I am essentially trying to create a system on my webserver (You can send HTTP Requests to external sites in this game via script) that will essentially log into an account on Roblox, to perform a task. My current idea would be to have the Lua script send a request to my webserver with an generated code that would access the username and password of my roblox account (Which would be on the webserver). It would then perform a task. Is this a good way to go about this? If not, I am open to suggestions. If you can find the time to actually help me set this up on my webserver, I would greatly appreciate it! I'm also sorry if this is the wrong place for this post, I'm new here. Hello, I am using the send mail form, everything is sent to my mail except the country field, it is sending blank. Code: [Select] $name = $_REQUEST['name'] ; $phone = $_REQUEST['phone'] ; $email = $_REQUEST['email'] ; $country = $_REQUEST['country'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail( $to, $subject, $name."\n".$phone."\n".$email."\n".$country."\n".$message, $headers); How could it be fixed please? thanks hey guys im tring to look for a good way of finding out if a ajax request is being performed on my page...now ive had a look about and found these two snippets.
Both seems to work fine...any suggestions on what one is best to use or even if there is a better way to do this would be helpful...thank you
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === "xmlhttprequest") { // is ajax } if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false){ // is ajax } I am new to all this, so please help I want to create a request form, basically when I click onto a hyperlink on my web page I want it to call windows explorer with the following ftp;//test.co.uk (example), which will bring up the page and I can log in. Any help would be a much appreciated |