andyd34 Posted March 9, 2011 Share Posted March 9, 2011 I am trying to come up with a backlink checker without a page refresh, i have come up with the code for the checking and is in form_requests.php $linkAction = $_POST['action']; $recip_url= $_POST['recip_url']; if($lnkAction == '1' && isset($recip_url)) { $this_url = 'http://www.my_url.co.uk'; $recip_url = $recip_url; $source = fopen($recip_url, 'r'); $contents = stream_get_contents($source); if(stristr($contents, $this_url)) { echo '0'; } else { echo '1'; } fclose($source); } I know this works fine Here is the code from the requesting page <!-- INCLUDE cont_header.html --> <script> $(document).ready(function(){ $("#copy").click(function(){ $.copy($("#backlink").html()); }); $("#close").click(function(){ $("#modal").fadeTo('slow', 0, function(){ $("#lightbox").fadeTo('slow', 0, function(){ $("#modal").remove(); $("#lightbox").remove(); }); }); }); $("#ChkLink").click(function(){ var linkUrl = $("#recip_url").val(); var lnkAction = $('#lnkAction').val(); if(linkUrl<1) { alert("the link check box is empty"); return false; } if(!linkUrl.match(/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_/\.]*(\?\S+)?)?)?/)) { alert("you entered an invalid url"); return false; } var dataString = '&lnkAction=' + lnkAction + '&recip_url=' + linkUrl; $("#checking").html('<img src="./styles/images/preloader_small.gif" width="25" height="25" /> checking backlink...'); //alert(dataString); $.ajax({ type: "POST", url: "./form_request.php", data: dataString, success: function(data) { if(data!='1') { $("#recip_url").val(''); $("#checking").html('backlink found'); } else { alert('not found'); } } }); return false; }); }); </script> <p style="color:#003"><strong>Please copy and paste the code below to your website then enter the page URL in the box below and select check. Alternatively you can hit the copy text button then just paste your clipboard contents to your page.</strong></p> <hr /> <p style="background-color:#CCC"> <table cellspacing="4"> <tr> <td valign="top">Title</td> <td valign="top" bgcolor="#FFFFFF">{BACK_T}</td> </tr> <tr> <td valign="top">Description</td> <td valign="top" bgcolor="#FFFFFF">{BACK_D}</td> </tr> <tr> <td valign="top">URL</td> <td valign="top" bgcolor="#FFFFFF">{BACK_U}</td> </tr> </table> <div id="backlink" style="width:500px; background-color:#DDFFFE; display:none"> {BACKLINK} </div> <p align="center"> <button id="copy">copy html text code</button> </p> <p align="center" id="checking"> <br /> <form id="checklinkfrm" name="checklinkfrm"> <input type="text" style="width:250px" id="recip_url" name="recip_url" /> <input type="hidden" style="width:250px" id="lnkAction" name="lnkAction" value="1" /> <input type="submit" name="ChkLink" id="ChkLink" value="check link" /> </form> </p> <p align="center"> <input type="button" name="close" id="close" value="{CLOSE}" class="button" /> </p> Outside jquery everything works fine but using jquery i get alerts if a invalid url is entered and if the field is blank but if everything is correct all i get is the preloader Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/ Share on other sites More sharing options...
joel24 Posted March 9, 2011 Share Posted March 9, 2011 why not just run the php backlink checker in the very start of your page, and if a backlink is found then do whatever is then needed (show page etc)... and if one is not found, then echo or include a different page which indicates no backlink was found. Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1184970 Share on other sites More sharing options...
andyd34 Posted March 10, 2011 Author Share Posted March 10, 2011 I have sorted it out now i miss typed the url, this is the first page of the linking process. The user will copy and paste the information to their site and provide the link. if the link is found if(data!='1') { // NOW CHANGED TO ==='1' $("#recip_url").val(''); $("#checking").html('backlink found'); } the next step is loaded into the div, this step includes their link details here is the working model http://www.halton-driving-school.co.uk/directory/ Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1185259 Share on other sites More sharing options...
Bartman Posted April 2, 2012 Share Posted April 2, 2012 Will this work on a submission form? I just want the form to check for a back link before allowing the submission to be added to the mysql. Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1333750 Share on other sites More sharing options...
joel24 Posted April 4, 2012 Share Posted April 4, 2012 yes, though it can be manipulated by a user... if you're that worried, store a hidden random value md5(date?) as a hidden form field, store it in the session and verify before inserting to database.... Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1334273 Share on other sites More sharing options...
Bartman Posted April 4, 2012 Share Posted April 4, 2012 Thank Joel24 for let me know I am in the right direction. Any idea how I would get it working with my form? <form id="websubmission" name="websubmission" method="post" action="index.php?action=submit"> <? if(!empty($_SESSION['websubmissionstatus'])){ echo $_SESSION['websubmissionstatus']."<br/>"; $_SESSION['websubmissionstatus']="";}?> <input name="title" type="text" id="title" style="font-family: Tahoma; border: 1px solid #184A7B; background-color: #FFFFFF" size="24" maxlength="75" value="Title"> <input name="url" type="text" id="url" style="font-family: Tahoma; border: 1px solid #184A7B; background-color: #FFFFFF" value="http://" size="50"> <select name="category" style="font-family: Arial; font-size: 10px; color: #000000; padding: 2px; border: 1px solid #666666; background-color: #FFFFFF"> <option value="0" selected>Select Type</option> <? echo submit_category_list();?> </select> <input name="Submit" type="submit" id="Submit" style="font-family: Arial; font-size: 10px; color: #000000; border: 1px solid #C0C0C0; background-color: #FFFFFF" value="Submit" /> </form> This part: <? if(!empty($_SESSION['websubmissionstatus'])){ echo $_SESSION['websubmissionstatus']."<br/>"; $_SESSION['websubmissionstatus']="";}?> shows the errors for when they do not add a proper Title, URL or don't choose a category. I would like the code in this post to work for my form so that it checks if the user has added a back link on their site already before they can submit my form. If they did not have a backlink the error would show up on the page where websubmission errors show or maybe a popup window that says No backlink found. Do you understand what I am trying to do? Can you point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1334310 Share on other sites More sharing options...
joel24 Posted April 14, 2012 Share Posted April 14, 2012 session_start(); $auth= md5(date('giadmy') . '5417'); $_SESSION['auth'] = $auth; // the html <form action='page2.php'> Field one... <input type='text' name='whatever' /> etc <input type='hidden' name='auth' value='<?php echo $auth; ?>' /> <input type='submit'> //page2 .php session_start(); if (!isset($_POST['auth'], $_SESSION['auth']) || $_POST['auth'] != $_SESSION['auth']): exit('the auths did not match...'); endif; //otherwise execute your code and insert to database etc Quote Link to comment https://forums.phpfreaks.com/topic/230086-backlink-check-with-php-and-jquery/#findComment-1337419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.