Jump to content


Check out our Community Blogs

uniqueideaman

Member Since 12 Oct 2016
Offline Last Active Today, 04:59 AM
-----

Topics I've Started

How To Check Whether An Html Element Or Plain Text Exists On A Page Or Not

19 April 2017 - 05:41 PM

Pros,
 
 
Imagine you want to only provide your download link to those who tweet about you. Now, how would you code it ?
Let's make it simple for you to understand.
Let's say you want to write a php script that checks if a certain html element (eg. name=username) or plain text exists or not.
If it exists then to give you an alert "TRUE"; Else alert: FALSE.
 
In this example, you want the script to check this page:
 
And you want it to check if the following text (exact match) exists or not:
 "I'd like to put forward an Idea"
 
 How would you code it ? Can we see 2-3 examples ?
 I'd be grateful if you can show another example for a fuzzy match. Eg:
  * like to put forward *
  
 This is an interesting topic. Base the boolean around what exists or not on a page.
 Curious to see what the code would look like and php is capable of doing it in how many lines of code.
 
 
 Thanks

Recommend Me Some Tutorials

19 April 2017 - 03:49 PM

Friends, Mates, Buddies & Pals,
 
 
I don't want to google or youtube because there's a lot of bad tutorials rampaging the net.
And so, how-about you recommending me some text & video tutorials on:
 
CURL
Hashing
 
I really need to learn password hashing. Encrypting & decrypting.
And web scraping.
 
:thumbsup:
 
Where did you learn these subjects from ? What is your source ?
I can checkout your recommendations after I wake-up and so take your time searching for the right ones to recommend to me. No rush. ;)
And, most of all: THANKS!
 

 


What Is The Difference Between A Php Statement And A Php Expression ?

18 April 2017 - 04:37 AM

Programmer Folks!
 
I first started learning php in September 2015. In 2 wks I read the whole tizag tutorial after understanding it.
(Browse the chapters list on the leftside of the page).
 
I was still "raw" in experience when I suddenly read that php 7 was out and when some article mentioned there is a slight modification in the syntax of php 7, I got put-off from learning php 5 from any tutorial and deliberately tried forgetting what I learn so far from tizag (which doesn't even mention what version they're teaching, like most tutorials forget to mention that) and waited nearly 1.5yrs for a beginner level tutorial to come-out that would teach me php 7 from ground-up but no such tutorial has come-out even today as most php 7 tutorials don't teach you from the beginning of the language but only teach you what is different in php 7 compared to php 5. 
Anyway, since, programmers everywhere keep telling me it;s the same language and not to wait for php 7 tutorial to come-out that would teach from the beginning and since they have assured me the syntax is still the same in php 7 like it was in php 5 and earlier versions then I have no choice but to revise again after 1.5yrs of my long waiting break. 
This time, however, going slowly in the "re-learning" so to get a solid understanding of thto not overlook any aspect of it. Won't run this time. Saying all this, I do have a little experience in the language by watching youtube tutorials and fiddling with their codes modifying them according to my needs and asking for help in the forums. 
When I learnt from tizag, I can't remember them teaching anything about expressions or tokens (unless I've forgotten it over 1.5yrs) but going through tutorialspoint.com I came across it. Hence, the questions:
 
Q1a. In php, what is the difference between a statement and an expression ?
I know statements must end with a semi colon but what really is an expression and what really is a token ? I didnt really understand this explanation:
 
Guessing, a token is considered a data type (string, variable, integer, boolean, etc.) ?
 
Q1. Anything else I should know ?
 

How To Record Urls Loading on iFrame Into MySql Db ?

09 April 2017 - 04:59 PM

Programmer Experts,

 

I'm embarking on an interesting project to gain work experience in php. Just stuck on one thing and wondering if you can help.

You probably used Team Viewer. This is where I create a Team Viewer session and get a unique number and if I give you it then with that number you can login to my computer and see what is on my screen and you can remotely control my computer.

Creating something similar. Only difference is, you won't remotely control my computer nor access any parts of my computer but only see what I am viewing in an iframe.

So, it is like this ...

I register for a member account. I login to my member account. I add you as "friend". Now, you can view what I am viewing on an iframe.

My homepage (member account page after I login) will show me 2 iframes. Whatever, I browse on the 1st iframe is remotely viewed by my friends like you. And whatever page you (my friend) is viewing in your 1st iframe gets shown to me on my 2nd iframe.

So, my 1st iframe records what I'm viewing to show to you, my friend, on your 2nd iframe.

And my 2nd iframe shows what page you, my friend, are viewing on your 1st iframe inside your member account.

Simple concept, really. No rocket science.

So, technically, this is how it works ...

Whatever url I view in my 1st iframe (whatever url the iframe opens to and whatever links I click inside the iframe) gets recorded onto mysql like so ...

COLUMN

User| Latest_Viewing_Url

UI Man|1.com

 

Now, your member acc home page would show the webpage I am viewing in your 2nd iframe.

Your 2nd iframe pulls that (above mentioned mysql data) data and opens to the webpage mentioned on column (Latest_Viewing_Url) position: 0.

In this example, your 2nd iframe opens to: 1.com.

When I move-on to another page (eg. by clicking a link on 1.com) then that gets not INSERTED but UPDATED on "Latest_Viewing_Url" column position: 0.

And things work vice versa for both of us.

See, I told you it is an interesting project for a beginner like me. Everything is nearly finished. But a problem:

How do I get the iframe to record (onto "Latest_Viewing_Url" column; pos: 0, all the links I click inside the iframe (in this example the url I visit after clicking a link on 1.com) ?

I can code for there to be a "Visit" or "Go To Url" button so when I click it then the url in the "Url" html text box gets recorded onto the db. But that is only recording the urls that I view by clicking the "Go" button, Imagine, I clicked a link inside the iframe. Now, that link will have no connection with the "Go" button. hence, I'm in a puzzle how to record what links get clicked. If somehow, I can program the script to monitor the url field on the iframe every 5 secs for any changes so when it finds the url has changed then to record it on the db. But guess what ? I have no clue how to do that. Meaning, how to get the script to monitor what url is residing in the iframe url field. i know how to do this in Ubot Studio (.exe) bot but not php. And so, I need your brilliant help!

Care to show a few samples for all present and future newbies ? Newbies would appreciate your help for future to come!

A single line of code that notes down every url that loads in the iframe should do the trick!

What do you think ?

 

<html>
<head>
<title>
<?php 
$user ?> Home Page
</title>
</head>
<body>
<body background=".png">

<?php
session_start();
require "conn.php";

/*Check if user is logged-in or not by checking if session is set or not. 
If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

if(!isset($_SESSION["user"])) 
{
    header("location:login.php");
}
else 
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$sql);
    while($row = mysqli_fetch_assoc($result))
    {
        $db_id = $row["Id"];
        $db_username = $row["Username"];
        $db_forename = $row["Forename"];
        $db_surname = $row["Surname"];
        $db_email = $row["Email"];
        $db_bio = $row["Bio"];
        $db_status_to_friends = $row["Status_To_Friends"];
        $db_status_to_public = $row["Status_To_Public"];
        $db_latest_view = $row["Latest_View"];
        $db_upline_1 = $row["Upline_1"];
    
    
        //Welcome user by name.
        echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

        <?php
        //Display log-out link.
        echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
    
        <?php 
        //Display User's Latest View.
        echo "<br><b>Latest View:</b><br>";
        echo "$db_latest_view";?><br>
        <br>

        <?php 
        //Display User's Latest Viewed Url in iFrame.?>
        <iframe src='<?php echo $db_latest_view;?>'></iframe>

        <?php 
        //Display User Bio.
        echo "<br><b>Bio:</b><br>";
        echo "$db_bio";?><br>
        <br>

        <?php 
    }
}
?>

</body>
</html>


Php Sql Injection Secure Tags

09 April 2017 - 04:22 PM

 
New Friends! :)
 
The following is my member registration code as of latest.
 
ISSUE 1: 
I get this error:
 
Parse error: syntax error, unexpected '_' (T_STRING), expecting ',' or ')' in C:\xampp\htdocs\e_id\register_edited.php on line 10
 
What is wrong ? I copied the "'images/'_$FILES['avatar']['name']);" from a  youtube tutorial on how to create feature for your member site members to upload their images. It was working on my site but not now on my xammp.
 
 
ISSUE 2:
 
Is the following ok or have I got them wrong way round ? I mean the real_escape and the strtolower and the strip_tags. Eg.
 
$member_registration_username = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["member_registration_username"]))));
 
Any mistakes I made from line 9-22 ?
 
 
Question 3:
 
Looking at my html form, do you spot any errors apart from the <center> outdated tags ? (Will replace them and design with css instead. In the middle of it now).
 
 
Question 4:
Should there be 2 equal signs ? Eg. "== 0" (equal to) ? instead of just "=" ?
$member_registration_account_activation = 0;
 
 
FULL REG PAGE CODE:
 
 
<?php
require "conn.php";
require "site_details.php";
 
if  (isset($_POST['submit']))
{
if(!empty($_POST["member_registration_username"]) && !empty($_POST["member_registration_password"])&& !empty($_POST["member_registration_password_confirmation"])&& !empty($_POST["member_registration_email"])&& !empty($_POST["member_registration_email_confirmation"])&& !empty($_POST["member_registration_forename"])&& !empty($_POST["member_registration_surname"]))
{
$account_activation_link = "http://www.$site_domain.com/$site-name/activate_account.php?email=$member_registration_email&&member_registration_account_activation_code=$member_registration_account_activation_code";
$avatar_path = trim(strip_tags(mysqli_real_escape_string($conn,'images/'_$FILES['avatar']['name']);
$member_registration_account_activation = 0;
$member_registration_random_numbers = random_int(0, 9999999999);
   
        $member_registration_username = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["member_registration_username"]))));
$member_registration_password = trim(strip_tags(md5(mysqli_real_escape_string($conn,$_POST["member_registration_password"]))));
        $member_registration_password_confirmation = trim(strip_tags(md5(mysqli_real_escape_string($conn,($_POST["member_registration_password_confirmation"])))));
        $member_registration_forename = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_registration_forename"])));
        $member_registration_surname = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_registration_surname"])));
$member_registration_gender = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_registration_gender"])));
        $member_registration_email = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_registration_email"])));
        $member_registration_email_confirmation = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_registration_email_confirmation"]));
$member_registration_account_activation_code = trim(strip_tags(mysqli_real_escape_string($conn,"$member_registration_random_numbers")));
 
if (preg_match("!image!", $_FILES['avatar']['type'])) 
{
//copy image to images/ folder.
if(copy($_$FILES['avatar']['tmp_name'], $avatar_path)) 
{
$_SESSION['avatar']=$avatar_path;
}
else
{
$_SESSION['message']= "Image could not be uploaded!";
}
else
{
$_SESSION['message']= "Only gif, jpeg or png files allowed for your avatar!";
exit();
}
 
if($_POST["member_registration_email"] != $_POST["member_registration_email_confirmation"])
{
$_SESSION['message']= "Your email inputs do not match! Try inputting again and then re-submit.";
exit();
}
        
if($_POST["member_registration_password_confirmation"] != $_POST["member_registration_password_confirmation"])
{
$_SESSION['message']= "Your password inputs do not match! Try inputting again and then re-submit.";
exit();
}
 
//Check for Username match in users table.
$sql = "SELECT * FROM users WHERE Usernames ='".$member_registration_username."'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result)!=0)
{
$_SESSION['message']="That Username $member_registration_username is already registered!";
exit();
}
 
$sql = "SELECT * FROM users WHERE Emails ='".$member_registration_email."'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0)
{
$_SESSION['message']="That Email $member_registration_email is already registered!";
exit();
}
 
   $sql = "INSERT INTO users(Usernames,Passwords,Emails,Forenames,Surnames,Genders,Account_Activation_Codes,Account_Activations) VALUES('".$member_registration_username."','".$member_registration_password."','".$member_registration_email."','".$member_registration_forename."','".$member_registration_surname."','".$member_registration_account_activation_code."','".$member_registration_account_activation."')";
        if($sql)
   {
       $_SESSION['message']="Data insertion into table success!";
        }
   else    
   {
            $_SESSION['message']="Data insertion into table failure!";
   }
 
   $to = "$member_registration_email";
   $subject = "Your $site_name Account Activation!";
   $body = "$member_registration_forename $member_registration_surname,\n\n You need to click the following link to confirm your email address and activate your account.\n\n\
   $account_activation_link;
$from = "$site_admin_email";
   $headers = "from: $from";
 
   mail($to,$subject,$body,$headers);
   $_SESSION['message']="Check your email for further instructions!";
}
else
{
   $_SESSION['message']="You must fill-in all input fields!";
}
}
 
?>
<!DOCTYPE html>
<html>
<head>
<title><?php $site_name ?> Signup Page</title>
  <meta charset="utf-8">
</head>
<body>
<div class = "container">
<form method="post" action="">
<center><h2>Signup Form</h2></center>
<div class="form-group">
<center><label>Username:</label>
<input type="text" placeholder="Enter a unique Username" name="member_registration_username" required [A-Za-z0-9]></center>
</div>
<div class="form-group">
<center><label>Password:</label>
<input type="password" placeholder="Enter a new Password" name="member_registration_password" required [A-Za-z0-9]></center>
</div>
<div class="form-group">
<center><label>Repeat Password:</label>
<input type="password" placeholder="Repeat a new Password" name="member_registration_password_confirmation" required [A-Za-z0-9]></center>
</div>
<div class="form-group">
<center><label>First Name:</label>
<input type="text" placeholder="Enter your First Name" name="member_registration_forename" required [A-Za-z]></center>
</div>
<div class="form-group">
<center><label>Surname:</label>
<input type="text" placeholder="Enter your Surname" name="member_registration_surname" required [A-Za-z]></center>
</div>
<div class="form-group">
<center><label>Gender:</label>
<input type="radio" name="member_registration_gender" value="male" required>Male<input type="radio" name="member_registration_gender" value="female" required>Female</center>
</div>
<div class="form-group">
<center><label>Email:</label>
<input type="email" placeholder="Enter your Email" name="member_registration_email" required [A-Za-z0-9]></center>
</div>
<div class="form-group">
<center><label>Repeat Email:</label>
<input type="email" placeholder="Repeat your Email" name="member_registration_email_confirmation" required [A-Za-z0-9]></center>
</div>
<center><button type="submit" class="btn btn-default" name="submit">Register!</button></center>
<center><font color="red" size="3"><b>Already have an account ?</b><br><a href="login.php">Login here!</a></font></center>
</form>
</div>
</body>
</html>