PHP - How To Ping A Domain With Custom Referrer Url?
Hello,
I need a small php script to ping a domain with custom referrer url eg: I need a script to ping a website www.abc.com with a custom referrer url ie. xyz.com so that the website abc.com would think that the traffic is from xyz.com Anyone have an idea? --SS Similar Tutorialsis this the best way to check if a server is live? <?php $host = "www.google.com"; $fp = fsockopen($host, 80, $errno, $errstr, 10); if($fp) { echo "yes it is"; fclose($fp); } else { echo "no it is not"; } ?> But if you type in a false server eg www.googddfsdfsd.com it returns an error how can i get it to return false and why doesn't it. How Would I ping an IP Address with Php. I am planning on using ping so that it pings a server ip, and if it matches the ip that the server is hosted on, then it will activate the profile. EG: Ping: MagicPkz.no-ip.org Comes out with my IP(70.177.**.***) Now I go to a page, it checks to see if MagicPkz.no-ip.org matches up to my IP, and if it does, it activates the profile, if it doesn't it gives an error. I have two domains both running SSL. Let's call them old-domain and new-domain. old-domain is permanently redirecting traffic to new-domain. There are still a lot of links out there to old-domain with https://. If I were to remove SSL from old-domain but keep SSL on new-domain, I am betting that users will be getting some sort of certificate error. Right? Any way around that if I want to remove SSL from old-domain?
This topic has been moved to the corner of 3rd Avenue and mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359430.0 I know that php has a function that can execute ping command but i'm not sure how it works. I am trying to get the result of the ping command to determine: IP address has a reply (PC/device is turned on) IP address has no reply (ip address is vacant and not assigned to any pc/device IP address has a response (PC/device is turned off) is this "do-able" in php?? this is my script: Code: [Select] function ping($ip){ // #5882FA blue color indicates Fiber Module // #FACC2E orange color indicates cascade/uplink cable // #81F781 Green color indicates connected/turned on // #FE2E2E Red color indicates disconnected/turned off // #585858 dark gray color indicates connected patch panel port is vacant at user side if($ip=="Cascade" OR $ip=="Uplink"){ return $status="style=\"background-color:#FACC2E;cursor:pointer;\""; /* orange */ }elseif ($ip=="Fibre Module"){ return $status="style=\"background-color:#5882FA;cursor:pointer;\""; /* blue */ }elseif ($ip==null or $ip==""){ return $status="style=\"cursor:pointer;background-image:url(images/x.gif);\""; /* dark gray */ }else{ $str = exec("ping -n 1 -w 1 $ip", $input, $result); if ($result == 0){ return $status="style=\"background-color:#81F781;cursor:pointer;\""; /* green */ //return "on"; }else{ return $status="style=\"background-color:#FE2E2E;cursor:pointer;\""; /* red */ //return "off"; } } } i can get it display on or off and i've tested it working. but i just can't figure out if i could use this command to determine if the IP address is vacant or unassigned. I'm using this for a IP list inventory system built in PHP. I have careted a page where the the 3com switch is drawn in tabulated format with each port assigned (via PHP) to the corresponding IP address of the device/PC and indicates the port color as described in the above function. Surprisingly it works well for this switch inventory. I just want to create another page for IP address inventory using the same function. To put is simple i want to have the same function as the sofware "Advance IP-Scanner" which does the same thing as well only thing is my resources are limited to PHP (WAMP). any help guys? Hello All happy new year I am trying to make a php page that detects if something is plugged in to the ethernet port. This would be complex if not impossible. I however managed to do something similar the device that will be plugged in has a static address 192.168.1.1. so I created a ping that says if the device is up or down. function ping($host, $port, $timeout) { $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); $status; if ($fP) { echo "Device is ready to accept data";} else { echo "Device Down - Retrying connection"; } } What I would like to do is have a script that is constantly checking is the device is plugged or when it is not (so sort of a loop or auto detect). The idea is to have an image with the device up or down. Regards and a happy new year JG ok hi im new to the forums and didn't really know where to put this, so il put it here if its in the wrong place then im sorry, anyways currently im working on a site that will ping a server and come back with the standard Online/Offline and the MS, i've already worked on that cod and its working, one thing im not sure about though is, if its possible to only ping the server once every 2minets or so, as currently every person who comes on the site or presses F5 will ping it, i was thinking maybe somehow storing the MS ect in a database, and having the PHP read from the database and somehow every 3 minutes having it update?, but im not really sure how i would go about doing this, or even if its possible my, mySQL isn't great to say the best, il leave the PHP code below and see what you think, sorry about the code being a bit messy Code: [Select] <tr> <td class="SEBody1"> <?php // Function to check response time error_reporting(0); function pingDomain($domain) { $starttime = microtime(true); $file = fsockopen ($domain, 443, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file) $status = -1; // Site is down else { fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } echo '<table>'; $domainbase ="ipadress"; $status = pingDomain($domainbase); if ($status != -1) echo "<img src='img/shard_status_online.png' width='18' height='18' alt='Online' /> Online "; else echo "<img src='img/shard_status_offline.png' width='18' height='18' alt='Offline' />Offline"; echo '</table>'; ?> </td> <td class="SEBody1">Login</td> <td class="SEBody1">PvP</td> <td class="SEBody1"> <?php if ($status !=-1) echo "$status ms"; else echo "0 ms"; ?> </td> <td class="SEBody1">English</td> </tr> Hello, please can anyone advise a right solution on how to avoid my site acting strangely when one of my AD companies stops to function. I mean there are downtimes for AD servers as well, and i'm wondering what is the best solution? Can i load ads on my pages separately, so i mean lastly? They are all over my page so i guess i can't do it. Or is it better to ping ad server and wrap these ADS around PHP if functions, which ping these servers? If you have a solution , which is most effective, please tell me. 1st the log in code: Code <form method ="post" action="cartnisya.php"> <table border="0"align="right"> <td>Username:</td> <td><input type="Text" name="Username"></td> <td>  </td> <td>  </td> <td>Password:</td> <td><input type="Password" name="Password"></td> <td>  </td> <td colspan="2" align="center"><input type="Submit" name=submit" value="Submit"></td> </table> <img src="Vinnex1.jpg"> </form> it will then go the php code: CODE: <html> <?php $db = mysql_connect("localhost", "root",""); mysql_select_db("vinnex",$db); $Username = $_POST['Username']; echo $Username; $result = mysql_query("Select TransNo From transaction", $db); $myrow = mysql_fetch_array($result); if ($myrow=='') { $TransNo='1000'; $sql = mysql_query("Select * From customer where Username='$Username'", $db); $myrow1 = mysql_fetch_array($sql); $Username = $myrow1['Username']; $Firstname = $myrow1['Firstname']; $Lastname = $myrow1['Lastname']; $name = $Firstname. " ".$Lastname; $Date = date('m/d/y'); $sql1 = "INSERT INTO temptransaction (TransNo, Username, Firstname, Date) VALUES ('$TransNo', '$Username', '$Firstname', '$Date')"; $result = mysql_query($sql1); //or die(mysql_error()); } else { $sql = mysql_query("Select max(TransNo) maxTransNo From transaction", $db); $myrow1 = mysql_fetch_array($sql); $orderno = $myrow1['maxTransNo']+1; $sql = mysql_query("Select * From customer where Username='$Username'", $db); $myrow1 = mysql_fetch_array($sql); $Username = $myrow1['Username']; $Firstname = $myrow1['Firstname']; $Lastname = $myrow1['Lastname']; $name = $Firstname. " ".$Lastname; $Date = date('m/d/y'); $sql1 = " INSERT INTO temptransaction (TransNo, Username, Firstname, Date) VALUES ('$TransNo', '$Username', '$Firstname', '$Date')"; $result = mysql_query($sql1) or die(mysql_error()); } ?> <meta http-equiv="refresh" content="0;url=orderproduct.html"/> </html> once this is open it will go the selected it wont display the matched echo for the text field. once i call the database when using username and password it wont filter and it wont call for a firstname and username to be saved in the database please help how can i output the remote user's ping to my server on my website through php? I found a pretty cool function that allows me to ping Pingomatic for new blogs that I have. Great. Now I can automate the process instead of manually going to their website. My problem is actually simple. Sometime Pingomatic is quite busy and is unable to receive the request. I want to be able to check the status of my ping request but I don't know how to get this specific field/variable? from the result. Here is the ping script: Code: [Select] $title = "My blog title"; $url = "http://mynewbloglink"; function pingomatic($title,$url,$debug=true) { $content='<?xml version="1.0"?>'. '<methodCall>'. ' <methodName>weblogUpdates.ping</methodName>'. ' <params>'. ' <param>'. ' <value>'.$title.'</value>'. ' </param>'. ' <param>'. ' <value>'.$url.'</value>'. ' </param>'. ' </params>'. '</methodCall>'; $headers="POST / HTTP/1.0\r\n". "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)\r\n". "Host: rpc.pingomatic.com\r\n". "Content-Type: text/xml\r\n". "Content-length: ".strlen($content); if ($debug) nl2br($headers); $request=$headers."\r\n\r\n".$content; $response = ""; $fs=fsockopen('rpc.pingomatic.com',80, $errno, $errstr); if ($fs) { fwrite ($fs, $request); while (!feof($fs)) $response .= fgets($fs); if ($debug) echo "<xmp>".$response."</xmp>"; fclose ($fs); preg_match_all("/<(name|value|boolean|string)>(.*)<\/(name|value|boolean|string)>/U",$response,$ar, PREG_PATTERN_ORDER); for($i=0;$i<count($ar[2]);$i++) $ar[2][$i]= strip_tags($ar[2][$i]); return array('status'=> ( $ar[2][1]==1 ? 'ko' : 'ok' ), 'msg'=>$ar[2][3] ); } else { if ($debug) echo "<xmp>".$errstr." (".$errno.")</xmp>"; return array('status'=>'ko', 'msg'=>$errstr." (".$errno.")"); } } pingomatic($title,$url,$debug=true); This script works and when Pingomatic 'is available' returns something to the effect of Thanks for pinging, you're blog is being forwarded...etc. etc. When Pingomatic is too busy I receive the following result: Code: [Select] HTTP/1.1 200 OK Server: nginx Date: Mon, 30 Apr 2012 22:23:17 GMT Content-Type: text/xml;charset=utf-8 Connection: close Content-Length: 390 <?xml version="1.0"?> <methodResponse> <params> <param> <value> <struct> <member><name>flerror</name><value><boolean>1</boolean></value></member> <member><name>message</name><value><string>Pingomatic is a bit overloaded at the moment</string></value></member> </struct> </value> </param> </params> </methodResponse> What I'm trying to get in a variable is the '<member><name>message' result. In this case it's "Pingomatic is a bit overloaded at the moment". This way I can try to ping the server again later at another time knowing that the ping was not successful. What I've tried: I've attempted to see if the 'message' (Pingomatic is a bit overloaded at the moment) is in some of the variables within the original function: $pingresponse = "<xmp>".$errstr." (".$errno.")</xmp>"; $pingresponse2 = "<xmp>".$response."</xmp>"; $pingresponse3 = array('status'=> ( $ar[2][1]==1 ? 'ko' : 'ok' ), 'msg'=>$ar[2][3] ); echo "Ping Server Response : Debug: ".$debug." Errstr :".$errstr." Errno: ".$errno."Response: ".$response; But it isn't. My plan was to use strpos to search for the term "Pingomatic is a bit overloaded at the moment" in which I'll be able to know whether or not the ping was successful or not. Any ideas? Hi, Hoping someone can help me out with something that is probably really simple, but I can't seem to figure out. I'm storing referring URLs, and some of them are over 1,000 characters because of all the variables. How would I Get only the actual url and not all the variables, such as... Code: [Select] http://www.google.com/ajax/search/start.php?eid=AAAAAwAgACAAAAH0v4jVmjrvBVRZxy6_CX4Rl8t6reioLF6htZb4qitx_2nR3dkfj7b8VJhn43Rc1JD0_Mn8S05zD1-Zg35FdE4rE6-cSmGB4Jrvebc3B6sFCY1vamkir_c--8ESJIzZeybl-22ddGIv4qP3JFtmaaLXWpOZSkyeSN17nD_I-vMnhsV8nY-gHeYTC4vqddkJQYI2bBSXP9Y0KHE189A1tFH9Cyprt4hpubL7KCKE2EPG4rErzSgnERqJMiqeLDtmdUs1Fe6e6nhaoE5bBim00LCnsfvQfYfX2wWkpglx2cZIASlb7H3AohF0amFZN2ZVeQBMhR7PsCNhhIXuuxa39-mxdjARVLqwpoQHXa2ODMu7jyNA7CO5pJ56F7vqtL2h9oDA-YlQ8BBgfXwKrmKaTKgWEU-mRqMeJ076B-JGPY6NjOg9Vkpe3KVhzh_L_rF4fz7kbQYKOgyGvmnsIEdkqlVCePqDOTvkKNMwOEdDW1LqYXIG3i3u21GGZAOqUslMnCix0sVIE09ENi-K6k75mvHxvTADiBXgPAw03BodR3I5hBfw3uFjkBKAfGJ1ir_03z5ec0Yz9RoSIOEYcZlvxeiTP-V4OnTz7n5eVYzD3o0c9mfyAYhLh4KY9LVxy88Pux2NSeIG3XAWextqYtPJhoIxWvO1qSp9tJBl_smywvlF2oZRQNCCbNNGeJ4BhdvmZ3OG7e0Jjm9FL4zEadh5pENY1A0lSInBN_reFiqe2iZh2_N8NX83Y51Tl0bn_Xrhf9SOI&c=4&f=0&ui=6002910216647-id_4d487a6db36b33126309761&en=1 I only need the info up to the "?" Code: [Select] http://www.google.com/ajax/search/start.php My php code looks like: $referer = $_SERVER['HTTP_REFERER']; mysql_query("INSERT INTO `refs` (`referer`) VALUES ('$referer')"); Is there an easy way to handle this? Hello, I know i can use server side code to capture a url etc, however i have a problem, i have a piece of Javascript that collects some information and passes it back to a php page which then proceses the information collected, which all works fine, on that php page i have the code to collect the refferring page, but obviously it just collects the details of the page it has come from which i already know. Is there anyway of using php to look back and get the page before that and any keywords that might have been used to get to that page, i know i could do this with javascript and include that information in the send, however the javascript is on another site and i really would prefer not having to change that if possible. I am not neccesarily looking for the solution but more if it is possible. Any advice would be appreciated. Thanks I'm sure it's not much, but I'm not understanding something with custom error handlers: I've created a custom error handler, which I initially set when my page loads : set_error_handler(array ( new ErrorHandler(), 'handleError' ));
It seems to catch all internal PHP errors, such as if I: var_dump($non_existing_var); right after the set_error_handler.... Now, I have an object that throws an exception after: set_error_handler(array ( new ErrorHandler(), 'handleError' )); $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception ... I thought that with an error handler set, I could 'skip' the try/catch for it, but doing so, PHP spits out in its internal log: PHP Fatal error: Uncaught CorbeauPerdu\i18n\LocaleException: ....
My error handler doesn't catch it at all before, thus my page breaks!! If I want it to go through the error handler, I have to init my Locale with a try/catch and use trigger_error() like so: set_error_handler(array ( new ErrorHandler(), 'handleError' )); try { $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception } catch(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } ... Is this normal ? I thought one of the goals of the error_handler was to catch anything that wasn't dealt with? Thanks for your answers! When making a fake identity in cURL, we use curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'); but which is better for the referrer: curl_setopt($ch, CURLOPT_AUTOREFERER, true); or curl_setopt ($ch, CURLOPT_REFERER, "http://www.google.com/bot.html"); Hello, I'm using a direct feature on my site, and on redirect I want to record unique hits, Ip Address, and referrer, so far, the code below records unique hits, and ip address, but i want it to record referrar aswell (it records data to data.txt): <?php $filename = "hits.txt"; $file = file($filename); $file = array_unique($file); $hits = count($file); echo $hits; $fd = fopen ($filename , "r"); $fstring = fread ($fd , filesize ($filename)); fclose($fd); $fd = fopen ($filename , "w"); $fcounted = $fstring."n".getenv("REMOTE_ADDR"); $fout= fwrite ($fd , $fcounted ); fclose($fd); ?> I have this on redirect page <?php include ('counter.php'); ?> Thank you. Hello. I am trying to redirect from page A to page B. I redirect from page A with code header( 'Location: http://AAA.com/bbb.php/' ); in page B I have code if(isset($_SERVER['HTTP_REFERER'])) { echo $_SERVER['HTTP_REFERER']; }else{echo 'SKATA';} so far I see the world SKATA. Can somebody tell me how can i redirect to page B including the referrer info from page A ? I am trying for hours and I can't get the solution. thank you in advance. I'm trying to redirect visitors that contain broadly matched URLs. For example, redirect the visitor if their url contains: "/welcome" or "order.php" or "login.mysite/" At the same time I also want to redirect the user if they a particular User Agent. Here's what I have, but doesn't seem to be entirely working... Code: [Select] <?php //detect referrer $ref = $_SERVER['HTTP_REFERER']; $find = "order.php"; $find = "login.mysite/"; //setting the variables $linux = stripos($_SERVER['HTTP_USER_AGENT'],"Linux"); $aol = stripos($_SERVER['HTTP_USER_AGENT'],"AOL"); //detecting user agent device, os, browser, etc. if ($linux == true || $aol == true) $redirect = 1; //detect referrer elseif (preg_match($ref, $find)) $redirect = 1; //set redirects if ($redirect) { $url = "http://www.google.com"; } else { $url = "http://www.yahoo.com"; } header("Location: $url"); ?> Any help you can offer is appreciated. Thanks! Hi, I have decent knowledge of htaccess and know enough about php/mysql so a little direction/advice is mostly what I need. I host a website(site1.com) that has links to files that are hosted on a different website(site2.com) on a different server. When a file link is clicked from site1.com, first it will go to a local php file(within site1.com) that checks that the user is logged in and make sure the file exists. Then it redirects(using a simple header function) to the file located at site2.com to begin download. But since my files at site2.com stored in a simple folder(if you knew the folder name, you could download all the files without having to be logged in), I want a way for site2.com to check that the file request is coming from site1.com(maybe using php referrer?) before it allows the download to proceed. Any ideas? |