php怎么直接获取链接的数据,php – 从数据库获取链接并重定向

我试着计算链接被点击的次数,然后重定向到具有该ID的联盟网站.我已经设法做了点击部分,每次点击链接时它在数据库中更新1但是有重定向部分的问题,我将id发送到track.php然后在那里检索id但我从那里重定向有问题.在数据库中我有affiliate_link并存储在那里的网址.任何帮助都会很棒.

在track.php上

require_once $_SERVER['DOCUMENT_ROOT'].'/market/core/init.php';

//update count click in database

if(isset($_GET['id'])){

$id = is_numeric($_GET['id']);

$db->query("UPDATE credit_card_offers SET count_click = count_click + 1 WHERE id = '$id'");

header('Location: How_to_call_Affiliate_link_here_form_database?');

}

?>

在index.php上.

See Deal

sql转储

-- phpMyAdmin SQL Dump

-- version 4.6.4

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Mar 25, 2017 at 03:54 PM

-- Server version: 5.7.14

-- PHP Version: 5.6.25

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8mb4 */;

--

-- Database: `dataz`

--

-- --------------------------------------------------------

--

-- Table structure for table `credit_card_offers`

--

CREATE TABLE `credit_card_offers` (

`id` int(11) NOT NULL,

`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`brand` int(11) NOT NULL,

`categories` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`description` text COLLATE utf8_unicode_ci NOT NULL,

`balance_transfers` text COLLATE utf8_unicode_ci NOT NULL,

`purchases` text COLLATE utf8_unicode_ci NOT NULL,

`representative_apr` text COLLATE utf8_unicode_ci NOT NULL,

`representative_example` text COLLATE utf8_unicode_ci NOT NULL,

`affiliate_link` text COLLATE utf8_unicode_ci NOT NULL,

`featured` tinyint(4) NOT NULL DEFAULT '0',

`count_click` int(255) NOT NULL DEFAULT '0',

`deleted` tinyint(4) NOT NULL DEFAULT '0'

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--

-- Dumping data for table `credit_card_offers`

--

INSERT INTO `credit_card_offers` (`id`, `title`, `brand`, `categories`, `image`, `description`, `balance_transfers`, `purchases`, `representative_apr`, `representative_example`, `affiliate_link`, `featured`, `count_click`, `deleted`) VALUES

(15, 'Barclaycard Platinum With Balance Transfer (25/25 Card)', 19, '19', '/market/images/products/5ac13b939568b60b71eb9fb1fa4d82df.png', 'A 2.5% fee is applied to balance transfers but a refund reduces this to 1.49% within 2 days (T&Cs apply). Transfer a balance within 60 days of opening an account to get the 0% deal; otherwise the rate will be 18.9% p.a. variable with no fee. ', '0% for 25 months with a 1.49% fee', '0% for 25 months', '18.9% APR', 'Representative Example: The standard interest rate on purchases is 18.9% p.a. (variable), so if you borrow £1,200 the Representative APR will be 18.9% APR (variable). ', 'https://www.barclaycard.co.uk/personal/platinum', 0, 0, 0);

--

-- Indexes for dumped tables

--

--

-- Indexes for table `credit_card_offers`

--

ALTER TABLE `credit_card_offers`

ADD PRIMARY KEY (`id`);

--

-- AUTO_INCREMENT for dumped tables

--

--

-- AUTO_INCREMENT for table `credit_card_offers`

--

ALTER TABLE `credit_card_offers`

MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

最佳答案 在track.php上,您将需要使用另一个查询来提取相关记录.另一种方法是在链接中包含URL,因为数据已在父页面上可访问.在index.php上:

See Deal

然后在track.php上你会得到它

$_GET['url']

然后你可以这样做:

if(!empty($_GET['url'])) {

header('Location: ' . $_GET['url']);

exit;

}

另请注意,is_numeric返回一个布尔值,因此$id赋值也可能不正确.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值