Confirm user is logged in before he download from site

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jainritesh
    New Member
    • Mar 2008
    • 4

    Confirm user is logged in before he download from site

    Hello All,
    I want to confirm that the user is registered member before he is redirected to download link. How do i read URL stored in DB and redirect user to this URL in PHP, if there is no product with that id it will show message product not found

    User will click on link like
    www.url.com/download.php?do=12 where 12 no is product id, Now @ download.php it will check wheter the user has logged in or not, if not he will be redirected to login page, else it will read download URL from db and redirect to that link.

    i tried to rite following code but it is no functioning properly.

    [PHP]
    <?php
    include("config .php");
    include("head.p hp");
    if(!isset($_COO KIE['userId'])) echo '<script>window .location="logi n.php"</script>';
    $id=$_GET['Id'];
    $sql=mysql_quer y("SELECT * FROM affiliate_planp ages WHERE ppageId='".$id. "' AND status='u'")or die(mysql_error ());
    $fetch=mysql_fe tch_array($sql) ;
    if(isset($_GET['do']))
    {
    $Do=$_GET['do'];
    $sql12=mysql_qu ery("SELECT * FROM affiliate_produ ct WHERE productId='".$D o."'")or die(mysql_error ());
    $fetch=mysql_fe tch_array($sql1 2);
    echo '<script>window .location="$fet ch[dlink]"</script>';
    }
    else
    {
    echo "<strong>Produc t Not Found</strong> ";
    }
    include("foot.p hp"); ?>
    [/PHP]


    the database structure is as follows

    [PHP]CREATE TABLE `affiliate_prod uct` (
    `productId` int(10) NOT NULL auto_increment,
    `title` varchar(200) NOT NULL default '',
    `dlink` varchar(200) NOT NULL default '',
    `imgurl` varchar(200) NOT NULL default '',
    `price` varchar(200) NOT NULL default '',
    `description` text NOT NULL,
    `pr` varchar(100) NOT NULL default '',
    PRIMARY KEY (`productId`)
    ) AUTO_INCREMENT= 1 ;[/PHP]

    Also is there any way by which end user never comes to know the actual URL, i.e even during download progress the URL shown will be www.url.com/download.php?do=12

    Thanxs in advance,
    Best Regards,
    Ritesh Jain
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Line 4:[php]if(!isset($_COO KIE['userId']))
    header("Locatio n=login.php");[/php]
    Also modify line 13 accordingly.

    For Server, JavaScript code is just a string, and nothing more then that. Also keep in mind that JavaScript and PHP don't run together. PHP (hypertext preprocessor) runs on server while JS runs on client (after the server sends the HTML to the browser).

    Harpreet

    Comment

    • jainritesh
      New Member
      • Mar 2008
      • 4

      #3
      Hello Harpreet,
      I am able to confirm wheter the user is registered member and has logged in, my problem how to redirect user to the download file after confirming the same. the download link is stored in database.

      Best Regards,
      Ritesh Jain

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by jainritesh
        Hello Harpreet,
        I am able to confirm wheter the user is registered member and has logged in, my problem how to redirect user to the download file after confirming the same. the download link is stored in database.

        Best Regards,
        Ritesh Jain
        I told you in my above post to modify line 13 also...[php] header ("Location:".$f etch[dlink]);[/php]

        Comment

        Working...