Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to do URL Encrypt with SmartPaginate?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
weblink
Smarty Rookie


Joined: 03 Apr 2010
Posts: 12

PostPosted: Sat Apr 03, 2010 6:49 pm    Post subject: How to do URL Encrypt with SmartPaginate? Reply with quote

Hello,

I'm new to smarty and I've got problem with pagination when pass the data from one page to another. I need to encrypt the data while passing that one.

Here is my PHP code for setUrl....

Code:
SmartyPaginate::setUrl("http://localhost/virtual/getReport.php?open_date=".opendate."&close_date=".closedate."&virtual_id=".virtual_id);


and the url displays the following

Code:

http://localhost/virtual/getReport.php?open_date=05-02-2001&close_date=01-01-2009&virtual_id=5482&next=15


In this above program code, i need to encrypt or encode the Url value of opendate, closedate and virtual_id. hope this is enough information ...

Is it possible to do with SmartyPaginate?

thanks

[/code]
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Sat Apr 03, 2010 9:09 pm    Post subject: Do it in php itself. Reply with quote

As open_date and close_date do not seem to be associated with your paginator, you should encrypt your values within the php file, while assigning them.

For example,
Code:
<?php
# Just encrypt your values
$opendate = encrypt_value($opendate);
$closedate = encrypt_value($closedate);

# Set the url
SmartyPaginate::setUrl("http://localhost/virtual/getReport.php?open_date={$opendate}&close_date={$closedate}&virtual_id={$virtual_id}");
?>


The URL you set will have encrypted values, irrespective of Smarty Paginate.
Back to top
View user's profile Send private message Visit poster's website
weblink
Smarty Rookie


Joined: 03 Apr 2010
Posts: 12

PostPosted: Sun Apr 04, 2010 1:56 pm    Post subject: Problem with Encrypted data with URL Reply with quote

Thank You for your reply bimal,

I tried with your solution with in php itself.

Code:
<?php
//tried only for encryption of virtual id
$virtual_id = id_encrypt( $_REQUEST['virtual_id']); 
echo "Encrypted id = ".$virtual_id;


//Set the url
SmartyPaginate::setUrl("http://localhost/virtual/getReport.php?open_date={$opendate}&close_date={$closedate}&virtual_id={$virtual_id}");
?>


The encrypted "virtual_id" only displayed in the URL and the page is not displayed upon that.

The page displayed the following
Code:

Encrypted id =127c5864e7f5e53b


When i clicked on the PageLink, the URL displayed as

Code:
http://localhost/virtual/getReport.php?open_date=05-02-2001&close_date=01-01-2009&virtual_id=127c5864e7f5e53b&next=3


Now, the corresponding data for that virutal_id is not displayed in that page. What changes i have to do in this?

THanks
Back to top
View user's profile Send private message
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Mon Apr 05, 2010 4:52 am    Post subject: Simple Reply with quote

Yeap... Let me know whether you have good knowledge in creating PLUGINS in smarty if so please take a test here

1) Write the encryption code is PHP and pass in the browser
2) Write the decryption code in Smarty and get the values.


If this ok for you. Else i will post some more details.

TY
Jo
Back to top
View user's profile Send private message Send e-mail
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Mon Apr 05, 2010 11:23 am    Post subject: Decryp! Reply with quote

Hmm, it won't display your contents according to your virtual ID because it is encrypted.

You should decrypt this piece first, so that your virtual_id becomes a valid thing for you to continue.

Do not encrypt your IDs with one way encryptions like MD5, because you may need to decrypt it to the original value. However, there are multiple solutions as well. For each encrypted value, you should keep a record of its original value as well, probably in the database. So, while decrypting, you can get back the real virual id.

Thanks
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Apr 05, 2010 1:37 pm    Post subject: Reply with quote

Pass those values through the PHP session on the server side, no need to encrypt them.
Back to top
View user's profile Send private message Visit poster's website
weblink
Smarty Rookie


Joined: 03 Apr 2010
Posts: 12

PostPosted: Mon Apr 05, 2010 5:30 pm    Post subject: Please give me an example Reply with quote

I don't have much knowledge about this topic, can anyone give the solution with example .

Thanks
Back to top
View user's profile Send private message
weblink
Smarty Rookie


Joined: 03 Apr 2010
Posts: 12

PostPosted: Wed Apr 14, 2010 6:37 pm    Post subject: Pagination problem with large amount of data Reply with quote

Hi all,

I'm using a query to retrieve the from table and stored the result in an array.
If the user clicks on the submit button, then the retrieved from table in between the open & close dates. The result of the data will be stored in an array variable..assume $data_array variable.

Code:
<?php
session_start(); 

$data_array = getData($opendate,$closedate);
SmartyPaginate::connect();
SmartyPaginate::setLimit(10);
$page_data = split_data($data_array );
SmartyPaginate::setUrl("http://localhost/virtual/getReport.php?open_date={$opendate}&close_date={$closedate}");


function split_data($data_array) {
      SmartyPaginate::setTotal(count($data_array));
                return array_slice($data_array,  SmartyPaginate::getCurrentIndex(),SmartyPaginate::getLimit());
    }

?>


assign to smarty object & display in smarty template. The Pagination is working here. The problem is, if the user selects the Submit button then the the getData function will be executed and the data will be retrieved from query and stored in array, then displayed in a first page. If the user clicks on page 2, then again the whole query will be executed from getData function then display the second page.

For every clicks in links, the entire query will be executed. The problem is, if i have 25 Lakhs of record, and retrieved only 1 lakhs records. The first page displayed when submit selected, it takes 1 minute for loading a page. Then the selection of page link 2, then the same 1 minute will take for loading a page. Is it possible to use the initial data which i retrieved early.

I stored in session variable and retrieved. Without using session variable, can any one give other solution

Thanks
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Wed Apr 14, 2010 9:41 pm    Post subject: Limit per-page details Reply with quote

When your data is too much, you should draw/select only the amount of data as your per-page's setting is, rather than pulling everything into a $data array.

In this case, say, your per-page (number of records per page) is 100, but your open/close date range contains 2000 data, then, you can have 20 pages: 1-...-20.

In whatever page you are, you should load only 100 records at once, for displaying your actual records in the page.

But for pagination, you should work differently - specially for identifying:
1. How many total records (and hence, page) are there in the page.
2. In which page number you are currently in.

By this, you should not draw 2000 records.

Other other easier way would be to use SQL_CALC_FOUND_ROWS: This saves a step in between. You should NOT use COUNT() in the sql to identify how many records are there under your conditions.

Here is an example:
SELECT SQL_CALC_FOUND_ROWS
data.column1,
data.column2
FROM data
WHERE
...
LIMIT $from_index, $per_page;

Then, immediately run: SELECT FOUND_ROWS() total; query to know how many records were there, when you did NOT use the LIMIT. This gives a number equivalent to your total number of records to paginate.

Please see the MySQL manual for SQL_CALC_FOUND_ROWS.
And, hopefully, it boosts up your operation speed several times.

Just remember, in whatever page number you are in, you are NOT going to pull records more than your $per_page configurations.

Thanks.
Back to top
View user's profile Send private message Visit poster's website
weblink
Smarty Rookie


Joined: 03 Apr 2010
Posts: 12

PostPosted: Sun Apr 18, 2010 4:27 pm    Post subject: Retrieve Records Quickly Reply with quote

Hello Bimal,

I tried that you suggested. Actually i am having 7 Lakhs records in my table, with my query i am taking 50,000 records from this 7 Lakhs records. I got this 50,000 records in 40 seconds and each page displaying 500 records. I tried my query added with "LIMIT 0,500", then it takes around 34 seconds to retrieve 500 records.

Any other way to reduce the time for executing the query?

Thanks
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Sun Apr 18, 2010 4:55 pm    Post subject: Indexing Reply with quote

Yes. There are ways to reduce the time used in SELECT query. You should better index your database, which can reduce an operation of around 10 minutes into few seconds Smile - That was my case.

Importantly, indices should be case-based - you must see how you have written your SELECT query. Wrong indices will not improve the time.

In your case, you may too have to include your open/close date parts in your index as well. But this will be out of Smarty's forum here. But a quick way to create an index is:
Code:
ALTER TABLE `my_table` ADD INDEX `my_index_name` (`colum1`, `column2`);

Also, please note that, order preference of the column names too matters. Here are more details at: MySQL's documentation.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Apr 18, 2010 4:55 pm    Post subject: Re: Retrieve Records Quickly Reply with quote

weblink wrote:
Hello Bimal,

I tried that you suggested. Actually i am having 7 Lakhs records in my table, with my query i am taking 50,000 records from this 7 Lakhs records. I got this 50,000 records in 40 seconds and each page displaying 500 records. I tried my query added with "LIMIT 0,500", then it takes around 34 seconds to retrieve 500 records.

Any other way to reduce the time for executing the query?

Thanks


index the keys used in the where clause.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP