Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP PDO Tutorial v2

Featured Replies

Hello,

Okay, so in this tutorial we will be creating a dynamic PHP Script, that changes database values when the correct user agent is requesting your server, and creating another PHP file for fetching that data from the database. No fancy design here, if you are after that - stop reading.

 

Part 1. What is User Agent?

User agent is a software application 'agent' that performs tasks behalf of a user. We can use user agent for our PHP script only allowing requests from a certain user agent. Useful in cases for example dynamic signatures and other tasks that we want to apply automation on.

 

Example of User Agent usage

$ua_name = "FacialSlave"; //The name of expected user agent
$ua = $_SERVER['HTTP_USER_AGENT'];

if(!preg_match('/'.$ua_name.'/', ua)) { //Returns false if incorrect HTTP_REQUEST
echo '<h1>Invalid user agent.</h1>';
} else if(isset($_GET['variable'])) { //If above returns true let's execute our statement defined somewhere.
$statement->execute();
}

Note! You need also to define the user agent from the other end of your application, in this we would be creating a dynamic script leaderboard, so you need to define the user agent from your Java files also, like this

private static final String USER_AGENT = "FacialSlave"; 

Part 1.5 The Java side for this app

The Java side not exactly what this guide is about, I'm just going to briefly talk this through.

//Variables
private static final String URL = "http://localhost/pdo_updateDatabase.php?";
private static final String USER_AGENT = "FacialSlave";

//Actual code
public static void httpAgent(String var_str, int var_int) {
String urlStr = URL + "variableOne=" + var_str + "&var_int=" + var_int;
StringBulder http = new StringBuilder();
URL url;
try {
url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("User-Agent", USER_AGENT);

BufferedReader brd = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String line;
while((line = brd.readLine()) != null) {
result.append(line);
}
brd.close();
} catch (Exception err) {

}
}

Part 2. SET Query for updating data in database

SET changes already existing data in database to new given values

require 'pdo_dbConnection.php';
//UA CHECK
...


Now if the user agent is correct, let's start executing our qery
else if(isset($_GET['variableOne'] && $_GET['var_int'])) {
//Query, where we set value of variableOne from Table where integerValue equals to given integer
$query = 'UPDATE Table SET variableOne = :variableOne WHERE integerValue = :var_int';
//Preparing the query above
$statement = $connection->prepare("$query");
//Executing statement as array, where we define placeholders for the query
$statement->execute(array(
':variableOne' => $_GET['variableOne],
':var_int' => $_GET['var_int']
));
echo 'Updated successfully.';
}

Part 2.5 Fetching data from our database

Fetching data can be done in multiple ways, this is just one example of it.

require 'pdo_dbConnection.php';

$query = 'SELECT * FROM Table'; //Query, * is a wildcard for selecting ALL fields from table.
//Using * is not recommended in production environment.
$statement = $connection->prepare($query); //And again, preparing the query for connection.
$statement->execute(); //Executing statement.

//Fetching data
foreach($statement as $row) {
echo '
<table style="width=250px">
<tr>
<th>My Script</th>
</tr>
<tr>
<td>Variable One: '.$row['variableOne'].'</td>
<td>Variable Two: '.$row['variableTwo'].'</td>
</tr>
</table>
';
}


I have NOT tested the code above, just wrote it. If you face any errors with my code, please let me know and I will take a look at it. Because I do make often alot of easy typos etc. 

  • Author

A tutorial that hasn't even been tested?

Why?

 

Because I know the code itself works. There might be typos or such things like that. It's not that an tutorial is supposed to be something where your kind can ctrl-ca and ctrl-v

  • Author

Please use a framework like Laravel or Symfony.

 

No hell no. Beautiful syntax isn't always the best..

  • 1 month later...

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.