Jump to content

PHP If...Else Help


williwaw

Recommended Posts

Hi all,

I am trying to password protect a .pdf document.

 

I have it working "pretty much" but rather than have a link that needs to be clicked after the name/pass is entered in the "Else..." statement, I have been trying to have the .pdf document open "automatically" without the link.

   <?php

    // Define your username and password
    $username = "name";
    $password = "pass";

    if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

    ?>
    
//HTML Form resides here...just took it out for ease of reading 

    <?php
    }
    else {
    ?>
//This is where I would like the document to 
//"automatically" open.
    <p><a href="doc.pdf">SURVEY</a></p>

    <?php
    }
    ?>

 

Thanks for your help and I am going to go and open my PHP book. I will post an answer if I get one.

 

 

Cheers,

Williwaw

thLavaLampSmall_anim.gif

 

Link to comment
Share on other sites

Im assuming u just need to redirect the user to the pdf file...

 

<?php

    // Define your username and password
    $username = "name";
    $password = "pass";

    if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

    ?>
    
//HTML Form resides here...just took it out for ease of reading 

    <?php
    }
    else {
    ?>
//This is where I would like the document to 
//"automatically" open.
    <p><script language="javascript">window.location='doc.pdf';</script></p>

    <?php
    }
    ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.