PHP - Htpasswd Based On Referer
I have htaccess file from which I am calling htpasswd.
Currently its ask for authentication from everyone. I want it IP based or Domain based so that a user requesting from specific IP may not have to go through http authentication. Some domain calling the web pages in background like paypal OR google checkout can access the page without http authentication. Is it possible ? content of htaccess file is given below. AuthUserFile /var/www/web/.htpasswd AuthName "Authorization Required" AuthType Basic <Limit GET POST> require user username </Limit> Similar TutorialsHoping someone can help. I have a file, say bounce.php that uses php url ramdomizer, like this: <?php $urls = array("link1", "link2"); $url = $urls[array_rand($urls)]; header("Location: http://$url"); ?> What I want is to only allow that code to execute if the user is coming from another php page on the same sever/folder. So like this.... So bounce.php will check where the traffic is coming from.....if traffic is coming from page1.php (file on same server) then it will allow URL REDIRECT CODE to execute, if traffic is coming from another source, such as google.com, or from no referel, then person is sent to another site, say msn.com. Hi, I am trying to create .htaccess and .htpasswd files in PHP using fopen and fwrite. But I don't think I'm encrypting the password correctly for the .htpasswd file. When I enter the username and password on the protected page, I am asked to enter them again. My error logs say "Password Mismatch". I have tried encrypting with: $encrypwd = crypt($pwd); and $encrypwd = md5($pwd); my username, password and create .htpasswd code $name = "6"; $pwd = "6"; $hpfile = $name."/private/.htpasswd"; $fh2 = fopen($hpfile, 'w') or die("can't open file"); $stringData = $name.":".$encrypwd; fwrite($fh2, $stringData); fclose($fh2); When I create a .htpasswd manually (entering the username and using an online htpasswd generator for the encrypted password) I am successful. I am using Xampp Lite, Windows 7, PHP Version 5.3.1 In case it matters Thanks I previously asked this question in the Apache Server forum with no reply so I'm thinking maybe that was the wrong area to post it in. I have a directory with media files in it (mp3's, videos etc.) that I want to secure from being downloaded yet be able to be played by a local player on the site. I was thinking of trying to secure the directory using .htaccess and .htpasswd files. I would then like to have the page the player is on pass the login credentials to allow the media files to be played. I do not want the user to be prompted for login credentials but if they tried to access the directory to download a file they would be denied. The server is (of course) Apache 2.2.17 and the scripting languages are php (version 5.2) and jQuery. Is this possible or am I going about this the wrong way? Thanks in advance. P.S. Yes, I have extensively searched for answers before posting but could not find the answer I was looking for. Hello dear friends, if i want only to get visitors from certain website (referer) say 7777777site.com so can someone rewrite that code for me please // that code to get referer right ! $r = $_SERVER['HTTP_REFERER']; // the only site i accept $sto = "7777777site.com" // now to compare it if ($r == $sto ) { echo "goood"; } else { echo "bad"; } i've tired this and totally wrong .. - it didn't works - i found if someone comes for example from 7777777site.com/vb/index.php it will consider it bad however it should be accepted referer so can someone please help me how to write such code ? Im working on an issue that keeps sending the user to logge_in.php and never to post_new.php even if it is the referer. Here is the code I have wrote so far: Code: [Select] if($_SERVER['HTTP_REFERER'] =="post_new.php"){ $referer = "post_new.php"; }elseif($_SERVER['HTTP_REFERER'] =="logged_in.php"){ $referer = "logged_in.php"; } header("Location: ".$referer." "); exit(); } Thanks in advance! I need to close a window if referer not valid, but it cannot be in HTML, needs to be php. This is what I have so far: Code: [Select] if (ereg("http://www.mysite.com/test.php", $_SERVER['HTTP_REFERER']) != true){ header('Location: ?????????'); exit; } I get a header already sent message if I use a URL. I need it to close the window after 3 seconds. Any ideas? now i use this code to show where the visitors came from to my site. <?php $referer=$_SERVER['HTTP_REFERER']; echo $referer; ?> now, i want to show the 5 latest vistors referer's site url on my site ? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=359538.0 Hello. I want to make a web-based rpg with mysql and php but need alot of help, I tryed once and failed. Please msn me: cginbarrhaven@hotmail.com I need LOTS of help. Im stuck! Zeroth hi everyone. i need to figure out how to display one tr or another based on if N/A appears in one of the TR's. if i use: 'if ($result['NoChargeFile'] = 'N/A')' it repeats N/A for all rows. if i use: 'if ($result['NoChargeFile'] = N/A)' only the TotalFees TR is displays. What i need to do is display the TOTALFEES if the NOCHARGEFILE is not N/A. If NOCHARGEFILE is N/A, display N/A instead of the TOTALFEES. Any ideas how to fix this issue? thanks. Code: [Select] <?php echo "<table width='100%' border='0' cellpadding='1'>"; $string = $string."$pages->limit"; $query = mysql_query($string) or die (mysql_error()); $result = mysql_fetch_array($query); if($result==true) { do { echo "<tr>"; echo '<td nowrap>' . $result['CompanyName'] . '</td>'; echo '<td nowrap>' . $result['CompanyReferenceNumber'] . '</td>'; if ($result['NoChargeFile'] = 'N/A') { echo '<td nowrap>' . $result['NoChargeFile'] . '</td>'; } else { echo '<td nowrap>' . $result['TotalFees'] . '</td>'; } echo '<td nowrap>' . $result['DateRecorded'] . '</td>'; echo '<td nowrap>' . $result['DateClosed'] . '</td>'; echo "</tr>"; } while($result = mysql_fetch_array($query)); } // close table> echo "</table><hr>"; ?> I figured it out. i need == not =. Hi all, Relitively new to PHP but am trying to code a site that dynamically creates urls using Joomla CMS. Basically I'd like a div to show on pages' url starts /component/.... but hide it if not. The urls of the pages on which the div is to be hidden start /index.php?. I've tried Code: [Select] <?php if (strpos($_SERVER['REQUEST_URI'], 'component') > 0) { echo '<div id=\"stuffdiv\">stuff</script></div>';} ?> only issue is... its always fasle hence the div never shows. If i replace > with >= its always true, and appears on all pages, even those not containing 'component'... Can someone tell me if this should work or if Im being really stupid? Thanks in advance! Tom Hello folks. I have a system showing stock of products. Now I want to colorize the value based on how much it is. For example 0 is red and then green is 10 000 and up. So the range should be like a smooth gradient. What's the algorithm? I have this array: Code: [Select] Array ( [jan] => 2 [feb] => 1 [mar] => 2 [apr] => 1 ) ..and I want to return: Code: [Select] Array ('jan', 'mar') As in, find the 2 elements with the highest count and put them in an array. What is the simplest way to achieve this? I have a page where I want a success and a fail response. It's a contact page so, if they fill in all that's required, and send, a success "message" will pop up but if they send but for some reason, it fails, to display a fail "message". What it does right now is the fail and success are constantly visible regardless. So how do I make it display the corresponding message accordingly? *Also how am I to make the text within the boxes invisible ? But that's lower priority Hi, I need to create a secure API at work so that 2 systems can interact with each other and request data (json format). I need to use an API key for this but don't want to use an API key stored in a database, what is the best way to go about this? I would like to use some sort of encryption algorithm and a white list of a few values to validate against once decrypted, is this safe and are there any algorithms I can use to generate my keys and white list? Hi all, I'm wondering if it's possible to use the $numrows boolean parameter where $numrows = 0 and meets a condition. For instance, my code is set up to check for classes where $numrows>0 and then displays the classes. If $numrows < 1, it echoes a message saying there are no classes available and to call the training department. I would like to redirect one of the classes to another link by using a strpos function to search for the classname within the URL. As I understand it, I would have to embed it in the else part of the statement if it's at all possible. Here's what I have so far. if ($numrows > 0) { echo "<p align=\"left\" class=\"style2 style4\">Click in the check box next to the date for which you would like to register: </p>"; echo "<p align=\"left\" class=\"style2 style4\">" . $_GET['classname'] . "</p>"; echo "<table width=100% style=\"color:#FFFFFF\">"; echo "<th></th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "<th>Location</th>"; echo "<th>Instructor</th>"; while ($results = mysql_fetch_array($rs)){ echo "<tr>"; echo "<td><input type=\"radio\" name=\"checkbox\" value=\"" . $results['date'] . "|" . $results['time'] . "|" . $results['location'] . "|" . $results['instructor'] . "|" . $results['course'] . "\"" . "></td>"; echo "<td class=\"style11\">" . $results['date'] . "</td>"; echo "<td class=\"style11\">" . $results['time'] . "</td>"; echo "<td class=\"style11\">" . $results['location'] . "</td>"; echo "<td class=\"style11\">" . $results['instructor'] . "</td>"; echo "</tr>"; } echo "</table>"; } elseif (strpos($_REQUEST['classname'], "BloodBorne Pathogens Video")); { echo "Bloodborne Pathogens is exclusively offered online. Please <a href=../training/online_courses/Bloodborne/BB.html>click here</a> to take the course."; } else { echo "Please call the training department as there are no classes scheduled at this time." } Please let me know if this is even possible or if I'm off my rocker. I'm fairly new to the PHP world but not a newb Thanks a bunch for your time! Hi guys, PHP advanced amateur and PHPFreaks newbie here. I have a problem with some code I've written. What the code is supposed to do, is take in 15 records in a single MySQL table column, and then print them out in a format like this: 1 2 3 4 5 6 7 8 9 so on so on. Here is the page in question: http://robbieduggan.com/strawberry-interactive/portfolio-web-design.php Now the problem is, you can see 14 images there, but it seems to be negating the first one. Its always whatever row 0 is, because if I change the SORT BY attrabute in the code below, it's a different one that is missing. Here is my code to get the data: mysql_select_db($database_strawberry, $strawberry); $query_rsProjects = "SELECT page_unique_identity, clean_title, thumbnail FROM tblprojects ORDER BY `timestamp` DESC"; $rsProjects = mysql_query($query_rsProjects, $strawberry) or die(mysql_error()); $row_rsProjects = mysql_fetch_assoc($rsProjects); $totalRows_rsProjects = mysql_num_rows($rsProjects); And here is the code to create the table: echo "<table width='100%' border='0' cellspacing='5' cellpadding='5'>"; for($i = 0; $i < $totalRows_rsProjects; $i++) { $row = mysql_fetch_array($rsProjects); if($i % $columns == 0) { echo "<tr>"; } echo "<td>"; if($row['page_unique_identity'] != NULL){ echo "<a href='website-details.php?project=".$row['page_unique_identity']."'><img src='portfolio/".$row['thumbnail']."' alt=".$row['clean_title']." width='267' height='162' /></a>"; } echo "</td>"; if(($i % $columns) == ($columns - 1) || ($i + 1) == $totalRows_rsProjects) { echo "</tr>"; } } Thanks in advance for any help Hi, I'm trying to get a working php script that will redirect visitors based on a number of variables. I first want to check the country the visitor is from, and redirect based on the user's country ip address. If visitor is not from the US, then go to google.com (for example)... but only after also checking some other variables. I want to also redirect any user (including US visitors) who are using a mobile device browser/cell phone, and redirect visitors coming from a Linux box. I'm not sure how to add those as if/else statement. Any help would be appreciated. Here's what I have so far... Geo ip Redirect: ------------------- <?php require_once("GeoIP.inc"); $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code == 'US') { header('Location: http://www.google.com'); } else { header("Location: http://www.redirect.com"); } ?> Mobile Browser Redirect: ------------------------------ require_once('mobile_device_detect.php'); mobile_device_detect(true,false,true,true,true,true,true,'http://redirect.com',false); So not sure how to detect and redirect Linux users, and then how to link these all together in one script so it checks all variables before sending user to destination URL. Hope you can help. I really appreciate it! I am new to using animation and I want to have some photos scroll
I have it working, I just want to know what the percentages are based on and perhaps knowing that I can absolutely design a website rather than being vague.
Another side question is the method that the images are loaded... I'm wondering if it is possible to load one image at a time while having a seamless animation, even using infinite.
I don't want to load a bunch of pictures at once or string photos together and string them to make one large image to be scrolled... I need the animation to stop when hovering over any photo and also for each of those photos to link to a unique location.
I've got the linking done but the stopping eludes me... I can achieve it if I animate photos individually and maybe I will have to follow that route for now which this is based on the lifetime of the photo eg. screen space.
Thanks for any help
Hi all.
In my database, i have a table where a client chose a service providers to make payments and each bill setup counts as a reward point for the client. Each bill counts as a single point even if the bill is edited after a services might have expired or renewed it should not be counted again as point.
to count the number of bill set up by a client i did
$stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();Its okay if it counts for new bills but i want it not to count for the same service provide and so i did $stmt=$pdo->query("SELECT company FROM payment WHERE username = '$username' AND trans_ref = '$trans_ref'"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $coy = $row['company']; } //ps: note, $company is a variable from the form if(strcmp($coy, $company) == 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 0 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }elseif(strcmp($coy, $company) != 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }it just wont add up i also tried $coy1 = $coy; $coy2 = $company; $point = 0; if(strcmp($coy1, $coy2) == 0){ $add_point = $point + 0; }else{ $add_point = $point + 1; } $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = $add_point WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();still wont work. any idea? |