473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to fill user/pass field of a prompted form with php?

5 New Member
Hello, i've been spending some time trying to figure out a solution for the hotlinking of the videos hosted at my site, which is imposible to do trough htaccess since firefox has a bug that can't read the referrals in this particular case like IE or chrome would. Well i figured out something, in my cpanel i have the option to protect folders with an username and password, and for what i have tested so far, it works to avoid the hotlinking. So here is my idea, since with that activated the browser will ask for an username and password, is there a way to put a script that fill this form with the correct password & user stored in variables in the php with out the need of the human hand to do it, so i could put this code in every web at my site so they can access the folders (people shouldn't be prompt it with the log in screen since the php should fill it underneath) but since the other webs don't have the password and the php script they are screwed. I hope i made myself clear, and please help me out with this, i just know enough php to edit it but not to create it yet and I'm not sure if this is possible though, if you help me out to create this code I'm sure a lot of people will be grateful since most of video streaming have this issue cuz of the firefox bug.

Well thanks in advance to whoever gives me an idea of how to do this.
And please don't say "use htaccess" just help me with a code that could fill the username and password when prompted by my own website.
May 1 '10 #1
3 2577
Atli
5,058 Recognized Expert Expert
Hey.

I don't think this is possible, no. The password protection is most likely at the HTTP server level, which happens before any PHP code is executed. The request needs to include the authentication info, which is not something PHP can circumvent.

There is one idea I can offer you; something that might at least prevent people simply linking to things like images or videos on your server. This is by no means bulletproof, though.

You could use a server-side session to keep track of whether the requester has actually accessed a page on your website before sending the request for the resource, and if he has not you can deny access. To do that, you would simply add two lines to the top of your scripts that would register a session variable.
For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION['isEnabled'] = true;
  4. ?>
  5. <html>
  6. <head><title>Hotlinking test</title></head>
  7. <body>
  8.     <h1>Image!</h1>
  9.     <img src="logo.png" alt="Logo!" title="A logo">
  10. </body>
  11. </html>
Then you would pass all requested images through a .htaccess filter that would, rather than serve the requested image, redirect it to a PHP script:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^(.*\.(jpe?g|gif|png))$ getContent.php?file=$1&nothing
(Note, the "&nothing" is there just to prevent a loop, as the rule would also match the redirected URL without it.)

The PHP script, "getContent.php", would then verify that the session element has been register before serving the image. If it has not, it either just gives a 404 error or some other non-content.
For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. define('CONTENT_ROOT', 'files/');
  4.  
  5. if(isset($_SESSION['isEnabled']) && isset($_GET['file']))
  6. {
  7.     $filename = $_GET['file'];
  8.     $filePath = CONTENT_ROOT . $filename;
  9.     if(!file_exists($filePath) || !is_file($filePath))
  10.     {
  11.         send_image(CONTENT_ROOT . '404.png');
  12.     }
  13.     else
  14.     {
  15.         if(!send_image($filePath))
  16.         {
  17.             send_image(CONTENT_ROOT . '404.png');
  18.         }
  19.     }
  20. }
  21. else
  22. {
  23.     send_image(CONTENT_ROOT . 'denied.png');
  24. }
  25.  
  26. /**
  27.  * Sends an image to the output buffer.
  28.  * Note, this can not be called more than once,
  29.  * and can not be called after ANY other output.
  30.  * @param $path The location of the image to send.
  31.  */
  32. function send_image($path)
  33. {
  34.     $data = getimagesize($path);
  35.     if(!$data) {
  36.         return false;
  37.     }
  38.     header('Content-type: '. $data['mime']);
  39.     header('Content-length: ' . filesize($path));
  40.     readfile($path);
  41.  
  42.     return true;
  43. }
  44. ?>
May 1 '10 #2
Zarich
5 New Member
Oh, i get what u mean, since its a server function it should be executed before any php could be loaded. Now your idea seems interesting, correct me if im wrong on this; ill add the first piece of code to all my php files so they all have active sessions, then the htaccces, then the last part is a script that would register the image based on the getimagesize parameter. Well now how would i be able to do that with mp4 videos since the getimagesize won't work there (at least i think so), After all im just a Newbie at php and thats why i ask for help. Btw since we will be using htaccess here im not sure if it will work, because the thing is firefox completly bypass the htaccess protecion when hotlinking a video on a embedded .swf.
More info about this issue at http://www.longtailvideo.com/support...m-with-firefox

Anyways at least i can try with the code you gave me, but help me out to modify it to work with .mp4 videos if it is capable to.

Another question in case this won`t work, is it possible to protect folders with a password in php?, i have seen i can protect webpages but not the folders, but if is possible it would do the thing.

Well i really appreciate your help and spending some time in your answer, you are the man =P.

Cya
May 1 '10 #3
Zarich
5 New Member
I was Able to do it with httaccess cookies =D, so if u have problemes with hotlinking and videos you gotta do that.
May 5 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1590
by: Marius | last post by:
Hi I have a form that users fill in, thefirst field is a username, which must be unique. Currently only when I attempt the Insert into the DB does the restaint inform the user that it already...
4
5354
by: Apple | last post by:
Can I edit an calculated field in my form if needed. Thank you in advance for your help. Sincerely Apple
3
11453
by: Jain | last post by:
Hi, How can I make it compulsory for data to be entered into a field in a form. Eg it won't allow the user to close the form without filling in a particular field. An error message appears...
3
1816
by: euphorica | last post by:
I am making an inventory database. I have a field InventoryNumber where I put a specific code. The code always starts with a particular letter. I would like to fill in another field with...
5
3017
by: Sam | last post by:
I have some required fields on a form. I'm checking these fields in the Form_BeforeUpdate sub. When just clicking on the fields and then trying to go to the next record by clicking on the little...
11
7391
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
2
1216
by: muddasirmunir | last post by:
i am using vb6 i want to restirct user to close a form if it has a blank field for e-g if user did not write name is the box and he tries to close the form by clicking on the croos button at...
3
1340
by: sillyr | last post by:
Hi I have a form where i have a dropdown box. The user selects either: No Yes-Observer Yes-Technician The table (LU Observer Present Lookup) that is used for the dropdown box has three fields:...
3
3531
by: Ron Mowry | last post by:
I am wanting to create a macro that will fill a specific field on a form and then go to the next record set. I have a blank field in the table that the form is pulling from. I want the user to be...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.