Jump to content

Recommended Posts

Hi,

 

I have the code below:

<?
/*
* search.php
*
* Script for searching a datbase populated with keywords by the
* populate.php-script.
*/
print "<html><head><title>[squashy] Search! NOT MESSED UP.</title></head><body>\n";
if( $_POST['keyword'] )
{
    /* Connect to the database: */
    mysql_pconnect("www.freesqldatabase.com","sql01_44052","censored")
        or die("ERROR: Could not connect to database!");
    mysql_select_db("sql01_4405hahamo1");
    /* Get timestamp before executing the query: */
    $start_time = getmicrotime();
    /* Execute the query that performs the actual search in the DB: */
   $query = ' SELECT
   p.page_url AS url,
   COUNT(*) AS occurrences
   FROM
   page p,
   word w,
   occurrence o
   WHERE
   p.page_id = o.page_id AND
   w.word_id = o.word_id AND (false ';
$words = explode(' ', $_POST['keyword']);
foreach ($words as $word) {
    $query .= 'OR w.word_word = "' . $word . '" ';
}
$query .= ')
   GROUP BY
   p.page_id
   ORDER BY
   occurrences DESC
   LIMIT ' . $_POST['results'];
$result = mysql_query($query);

    /* Get timestamp when the query is finished: */
    $end_time = getmicrotime();
    /* Present the search-results: */
    print "<h2>[squashy] Search Results For '".$_POST['keyword']."':</h2>\n";
    for( $i = 1; $row = mysql_fetch_array($result) or die(mysql_error()); $i++ )
    {
        print "$i. <a href='".$row['url']."'>".$row['url']."</a>\n";
        print "(occurrences: ".$row['occurrences'].")<br><br>\n";
    }
    /* Present how long it took the execute the query: */
    print "This search took: ".(substr($end_time-$start_time,0,5))." seconds.";
}
else
{
    /* If no keyword is defined, present the search-page instead: */
    print "<form method='post'>[squashy Search] <input type='text' size='20' name='keyword'>\n";
    print "Results: <select name='results'><option value='5'>5</option>\n";
    print "<option value='10'>10</option><option value='15'>15</option>\n";
    print "<option value='20'>20</option></select>\n";
    print "<input type='submit' value='Search [squashy]'></form>\n";
}
print "</body></html>\n";
/* Simple function for retrieving the currenct timestamp in microseconds: */
function getmicrotime()
{
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}
?>

 

How do I:

 

a) Center the search box and title and add an image above it like in google, the code for the search box and title is (taken from the code above)

 

{
    /* If no keyword is defined, present the search-page instead: */
    print "<form method='post'>[squashy Search] <input type='text' size='20' name='keyword'>\n";
    print "Results: <select name='results'><option value='5'>5</option>\n";
    print "<option value='10'>10</option><option value='15'>15</option>\n";
    print "<option value='20'>20</option></select>\n";
    print "<input type='submit' value='Search [squashy]'></form>\n";
}

 

b) How do I protect the code so that people can't see the database name and password?

 

Thanks,

 

Will

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/214108-how-to-add-image-center-protect-php/
Share on other sites

to secure it you can use a file to define them, set permissions on that file to read only for your web user and put that outside of the web root

<?php 
define("DB_PASSWORD","yourdbpassword"); 
define("DB_USER","yourdbuser"); 
?> 

 

then in your connection script

require_once '/var/www/db.config.php'; 
mysql_pconnect("www.freesqldatabase.com",DB_USERNAME,DB_PASSWORD)

 

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.