Solution for Baidu site search not supporting https (tested)

Solution for Baidu site search not supporting https (tested)

Recently, https has been enabled on the mobile phone. To get the green lock, the following problems need to be solved:

1. Pictures

2.js

3. CSS style

4. Form query also needs to use https

The first method: implemented through js

But recently, when I was working on a customer demand, I suddenly thought of a roundabout way to find a solution. Anyway, I tested that Baidu's site search can be used on the https website, and the method is particularly violent...

The idea is to make an input, a button, enter keywords in the input, and use js to control clicking the button to directly open the Baidu site search URL + keyword. Anyway, it works, I don’t know if it’s the right way to do it. . .

Above code:

<input type="text" name="q" id="bdcsMain" value="Baidu site search" onfocus="if (value =='Baidu site search'){value =''}" onblur="if (value ==''){value='Baidu site search'}" >
 <button class="search-submit" id="btnPost" type="submit" onclick="window.open('http://zhannei.baidu.com/cse/search?s=1849457021752692468&entry=1&q='+document.getElementById('bdcsMain').value)">Search</button>

Just copy the URL of your Baidu search results page and replace "http://zhannei.baidu.com/cse/search?s=1849457021752692468&entry=1&q=" in the above code.

The second method: through PHP jump

Search code is not js

<form action="http://so.jb51.net/cse/search" method="get" target="_blank" class="bdcs-search-form" id="bdcs-search-form">
		<input name="s" value="10520733385329581432" type="hidden">
        <input name="entry" value="1" type="hidden">
        <input name="ie" value="gbk" type="hidden">
        <input name="nsid" value="3" type="hidden">
        <input name="ie" value="gbk" type="hidden">
<input type="text" placeholder="Please enter the keywords you are interested in" value="" id="search_txt1" maxlength="18" class="search_txt" name="q">
<input class="search_btn" value="Search" type="submit">
</form>

After modification, change the action to the local PHP file

<div class="search">
<form action="/do/search.php" method="get" target="_blank" class="bdcs-search-form" id="bdcs-search-form">
		<input name="s" value="10520733385329581432" type="hidden">
        <input name="entry" value="1" type="hidden">
        <input name="ie" value="gbk" type="hidden">
        <input name="nsid" value="3" type="hidden">
        <input name="ie" value="gbk" type="hidden">
<input type="text" placeholder="Please enter the keywords you are interested in" value="" id="search_txt1" maxlength="18" class="search_txt" name="q">
<input class="search_btn" value="Search" type="submit">
</form>
</div>

search.php is as follows

<?php
error_reporting(E_ALL & ~E_NOTICE);
$s=is_numeric($_GET['s'])?$_GET['s']:0;
$entry=$_GET['entry']?intval($_GET['entry']):0;
$nsid=$_GET['nsid']?intval($_GET['nsid']):0;
$ie=$_GET['ie']?substr($_GET['ie'],0,3):0;
$q=$_GET['q']?urlencode($_GET['q']):'';
$url_str="http://so.jb51.net/cse/search?s=$s&entry=$entry&ie=$ie&nsid=$nsid&ie=$ie&q=$q";
header("Location: $url_str");
?>

That's it, you can modify it as needed. The second method is an original article from 123WORDPRESS.COM. We hope you will support us.

<<:  JavaScript common statements loop, judgment, string to number

>>:  How to implement DIV's blur function

Recommend

MySQL 4 common master-slave replication architectures

Table of contents One master and multiple slaves ...

MySQL infobright installation steps

Table of contents 1. Use the "rpm -ivh insta...

Detailed explanation of CSS line-height and height

Recently, when I was working on CSS interfaces, I...

Three common methods for HTML pages to automatically jump after 3 seconds

In practice, we often encounter a problem: how to...

Sample code for implementing a background gradient button using div+css3

As the demand for front-end pages continues to in...

MySQL lock control concurrency method

Table of contents Preface 1. Optimistic Locking A...

This article teaches you how to import CSS like JS modules

Table of contents Preface What are constructible ...

Detailed explanation of Vue's props configuration

<template> <div class="demo"&g...

js realizes two-way data binding (accessor monitoring)

This article example shares the specific code of ...

Details on using regular expressions in MySQL

Table of contents 1. Introduction 2. Prepare a pr...

Mysql5.6.36 script compilation, installation and initialization tutorial

Overview This article is a script for automatical...

Real-time refresh of long connection on Vue+WebSocket page

Recently, the Vue project needs to refresh the da...

How to use a field in one table to update a field in another table in MySQL

1. Modify 1 column update student s, city c set s...

MySQL quick recovery solution based on time point

The reason for writing such an article is that on...