Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2013, 06:38 PM   PM User | #1
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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..
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 06:52 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 06:54 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,504
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-14-2013, 07:08 PM   PM User | #4
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 07:18 PM   PM User | #5
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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!';
}

tempz is offline   Reply With Quote
Old 01-14-2013, 07:27 PM   PM User | #6
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 07:47 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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..
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 07:49 PM   PM User | #8
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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.
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 07:53 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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 :/
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 07:57 PM   PM User | #10
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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?
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 08:18 PM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 08:28 PM   PM User | #12
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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.
TestingPHP is offline   Reply With Quote
Old 01-14-2013, 10:02 PM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 10:29 PM   PM User | #14
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,504
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 PM.


Advertisement
Log in to turn off these ads.