开发者

php variables (website.com/?f="123") save to database & redirect

I have never coded php before and I really need this very simple script.

so let me explain what I need. user comes to开发者_如何转开发 my website via affiliate link so when they finished redirecting the url will look like this

http://website.com/lp/index.html?sub=1&customer_id=1039be6e23b4420c3e1063dc44a04d

now I have a download link on my website On download click check for duplicate ip address from database. if not duplicate capture sub="" & customer_id="" from the address bar. save to database with IP Address (this for tracking)

and redirect immediately to the download link

if the ip is not duplicated

 http://dl.website.com/download/downloadpop.aspx?id={Customer_id}

if it's duplicated

http://dl.website.com/download/downloadpop.aspx?id=beenbefore

Thank you so much!


You probably want header for the redirect:

http://php.net/manual/en/function.header.php

And mysql_connect, mysql_query, etc. for DB stuff:

http://php.net/manual/en/book.mysql.php

You can extract GET params from $_GET:

http://php.net/manual/en/reserved.variables.get.php

Note that any call to header() must take place before other output (see the example on the page linked.)


This is rather broad, and impossible to answer properly without knowing any details about your database structure, but here's how the basics of this would work:

<?php

$sub = $_GET['sub'];
$customer_id = $_GET['customer_id'];
$ip = $_SERVER['REMOTE_ADDR'];

$db = mysql_connect(...) or die(mysql_error());

$quoted_sub = mysql_real_escape_string($sub);
$quoted_customer_id = mysql_real_escape_string($customer_id);
$quoted_ip = mysql_real_escape_string($ip);

$sql = "SELECT count(*) AS cnt FROM yourtable WHERE ip_address = '$quoted_id'";
$result = msyql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if ($row['cnt'] == 0) {
    $enc = urlencode($customer_id);
    ... IP isn't in the database, so do the insert stuff ...
    header(" http://dl.website.com/download/downloadpop.aspx?id=$enc");
} else {
    header("Location: http://dl.website.com/download/downloadpop.aspx?id=beenbefore");
}

exit();


First off, you can access these variables via $_GET().

Next, you INSERT them into a database using PDO.

Finally, you can redirect someone with the appropriate header():

header('Location:http://dl.website.com/download/downloadpop.aspx?id=beenbefore');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜