Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    URL Locking isn't working? Why? please help!

    PHP Code:
    <?
    require 'db.php';
    $query mysql_query("SELECT * FROM `customers`");
    while ( 
    $customers mysql_fetch_assoc($query) ) {
    {
    extract($customers);
    $hostname $_SERVER['SERVER_NAME'];
    }
    }
    if (
    $customers == $hostname){
    ?>

    <?
    if ( empty($_GET['i']) || empty($_GET['p']) || empty($_GET['t']) ) {
    echo 
    '<b>No input';
    }
    else {
    if (isset(
    $_GET['m'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "S") {
    $ch curl_init("http://serverip/request.php?method=S&i={$_GET['i']}&p={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "C") {
    $ch curl_init("http://serverip/request.php?method=C&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "A") {
    $ch curl_init("http://serverip/request.php?method=A&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (
    $ch == TRUE){
    echo 
    '<b>Request has been sent';
    }
    }
    }
    else{
    echo 
    '<b> Your Domain is not validated!';
    }
    ?>
    I get -> Your Domain is not validated!

    Before anyone asks, yes it's all added correctly in my database.

    It isn't reading the hostname from my mysql, even though it's extracting & querying, I don't know why please help!
    Last edited by TestingPHP; 01-14-2013 at 06:41 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    PHP Code:
    if ($customers == $hostname){ 
    Why would you expect that to be true? $customers is either an array or false, and $hostname is a string. Perhaps you mean to fetch on $customers['somefieldhere']? Using extract is unwise as well; if any of those fields happen to be 'customers', than the entire loop could become infinite. Avoid using extractions.

    You have a few redundant braces around as well. These won't actually harm the processing instructions, but does make readability more difficult when you don't have any indentation in the code.

    And I should note now, that as of 5.5 MySQL library is now officially deprecated (yay). You should convert to MySQLi or PDO instead.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,093
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Two things..

    What is this supposed to actually do? - You mention url locking and then in there you're using cURL but I don't see anything that refers to any sort of 'lock'.

    Secondly, your code formatting makes it hard to read. There is a link in my signature about coding styles - you might like to take a look. Why? Because when you're asking others to help you, it helps us if we can actually read your code, understand what part of the code relates to what if conditional etc. If not, it makes it rather difficult to follow the logic flow.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    PHP Code:
    if ($customers == $hostname){ 
    Why would you expect that to be true? $customers is either an array or false, and $hostname is a string. Perhaps you mean to fetch on $customers['somefieldhere']? Using extract is unwise as well; if any of those fields happen to be 'customers', than the entire loop could become infinite. Avoid using extractions.

    You have a few redundant braces around as well. These won't actually harm the processing instructions, but does make readability more difficult when you don't have any indentation in the code.

    And I should note now, that as of 5.5 MySQL library is now officially deprecated (yay). You should convert to MySQLi or PDO instead.
    How would I extract the data correctly and use the strings from the extracted data, to you know. Hard to explain you know what I'm trying to do though >_>.

    I will try PDO later on, firstly I need to get this working

  • #5
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    You had lots of errors in your code also.

    I fixed them with this code.

    PHP Code:
    if ( empty($_GET['i']) || empty($_GET['p']) || empty($_GET['t']) ) {
    echo 
    '<b>No input';
    }
    else {
    if (isset(
    $_GET['m'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "S") {
    $ch curl_init("http://serverip/request.php?method=S&i={$_GET['i']}&p={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "C") {
    $ch curl_init("http://serverip/request.php?method=C&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "A") {
    $ch curl_init("http://serverip/request.php?method=A&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    elseif(
    $ch == TRUE){ echo '<b>Request has been sent'; }
    else{
    echo 
    '<b> Your Domain is not validated!';
    }


  • #6
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tempz View Post
    You had lots of errors in your code also.

    I fixed them with this code.

    PHP Code:
    if ( empty($_GET['i']) || empty($_GET['p']) || empty($_GET['t']) ) {
    echo 
    '<b>No input';
    }
    else {
    if (isset(
    $_GET['m'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "S") {
    $ch curl_init("http://serverip/request.php?method=S&i={$_GET['i']}&p={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "C") {
    $ch curl_init("http://serverip/request.php?method=C&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "A") {
    $ch curl_init("http://serverip/request.php?method=A&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    elseif(
    $ch == TRUE){ echo '<b>Request has been sent'; }
    else{
    echo 
    '<b> Your Domain is not validated!';
    }

    None of that worked, besides that part I made was fine, it's just the url locking I need help with, if you could help me with that then that'll be great

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by TestingPHP View Post
    How would I extract the data correctly and use the strings from the extracted data, to you know. Hard to explain you know what I'm trying to do though >_>.

    I will try PDO later on, firstly I need to get this working
    Assign them manually. You know the field names, set the variables up to reflect them. extract is *almost* as dangerous as register_globals is.

    Quote Originally Posted by tempz View Post
    You had lots of errors in your code also.

    I fixed them with this code.

    PHP Code:
    if ( empty($_GET['i']) || empty($_GET['p']) || empty($_GET['t']) ) {
    echo 
    '<b>No input';
    }
    else {
    if (isset(
    $_GET['m'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "S") {
    $ch curl_init("http://serverip/request.php?method=S&i={$_GET['i']}&p={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "C") {
    $ch curl_init("http://serverip/request.php?method=C&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    if (isset(
    $_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']) && $_GET['method'] == "A") {
    $ch curl_init("http://serverip/request.php?method=A&i={$_GET['i']}&={$_GET['p']}&t={$_GET['t']}");
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
    $rtf curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
    $exec curl_exec($ch);
    }
    elseif(
    $ch == TRUE){ echo '<b>Request has been sent'; }
    else{
    echo 
    '<b> Your Domain is not validated!';
    }

    Not sure why you think that will fix anything. As is you can never issue an output for a request being sent since its blocked into an elseif compared only to method of "A". A better approach is to simply clean it up. I presume that the $_GET['m'] isn't actually valid as you have in the first if block; nowhere is $_GET['m'] ever used.
    PHP Code:

    if (isset($_GET['method'], $_GET['i'], $_GET['p'], $_GET['t']))
    {
        
    $aKeeping array_flip(array('method''i''p''t'));
        
    $sQryStr http_build_query($aQryarray_intersect_key($_GET$aKeeping);
        
        
    $sUrl 'http://serverip/request.php?' $sQrystr;
        if (
    false !== ($ch curl_init($sUrl)))
        {    
            
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
            if (
    curl_exec($ch))
            {
                
    // was successfully *sent*
            
    }
        }
        else
        {
            
    // could not establish a server connection
        
    }

    You can also use a check for the $method to verify it matches one of 'S', 'C' or 'A', I didn't bother in this one. Untested but works okay in my head.
    Last edited by Fou-Lu; 01-14-2013 at 07:49 PM.

  • #8
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Assign them manually. You know the field names, set the variables up to reflect them. extract is *almost* as dangerous as register_globals is.



    Not sure why you think that will fix anything. As is you can never issue an output for a request being sent since its blocked into an elseif compared only to method of "A". A better approach is to simply clean it up. I presume that the $_GET['m'] isn't actually valid as you have in the first if block; nowhere is $_GET['m'] ever used.
    PHP Code:

    if (isset($_G['method'], $_G['i'], $_G['p'], $_G['t']))
    {
        
    $aKeeping array_flip(array('method''i''p''t'));
        
    $sQryStr http_build_query($aQryarray_intersect_key($_GET$aKeeping);
        
        
    $sUrl 'http://serverip/request.php?' $sQrystr;
        if (
    false !== ($ch curl_init($sUrl)))
        {    
            
    $rtm curl_setopt($ch,CURLOPT_TIMEOUT,1);
            if (
    curl_exec($ch))
            {
                
    // was successfully *sent*
            
    }
        }
        else
        {
            
    // could not establish a server connection
        
    }

    You can also use a check for the $method to verify it matches one of 'S', 'C' or 'A', I didn't bother in this one. Untested but works okay in my head.
    No offense but could you please help me fix the hostname locking error.
    I know everything else works, I just need help fixing my project.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by TestingPHP View Post
    No offense but could you please help me fix the hostname locking error.
    I know everything else works, I just need help fixing my project.
    As Tango pointed out, you still haven't defined what you mean by "locking". Perhaps you are trying to send multiple requests and are attempting to open multiple curl sessions? You'll probably need to close your current one first (via curl_close). Otherwise, I'm not sure what you mean by locking either :/

  • #10
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    As Tango pointed out, you still haven't defined what you mean by "locking". Perhaps you are trying to send multiple requests and are attempting to open multiple curl sessions? You'll probably need to close your current one first (via curl_close). Otherwise, I'm not sure what you mean by locking either :/
    When I ment locking I mean Hostname locking as a whitelist the only domains/hostname i want to be able to send the request is hosts in the customers table. Did that clear up things?

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Nope, that doesn't clear it up. Is that related to my comparison check I put in the first reply? Also, $customers would result in false where you have it there since its located outside of the loop.

  • #12
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Nope, that doesn't clear it up. Is that related to my comparison check I put in the first reply? Also, $customers would result in false where you have it there since its located outside of the loop.
    Could you fix that for me? maybe it'll work. Keep it simple though.

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Not really, I'm not sure exactly what you are trying to do here. Are you trying to connect to a field set for each customer? I'm not sure why you are checking the $_SERVER's SERVER_NAME if that were the case though.

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,093
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by TestingPHP View Post
    When I ment locking I mean Hostname locking as a whitelist the only domains/hostname i want to be able to send the request is hosts in the customers table. Did that clear up things?
    Not in the slightest.

    Something about you have whitelist of domains are hosts in the table?

    Re-read what you've written - it's really not very clear.

    Perhaps you should start again by telling us step by step, what this project is and what it should do step by step
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •