Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

help with php, can u use a variable as a string?


K3174N 420's Avatar
Satan > God
0 0

hey, im trying to make a php page that opens a few differant urls untill i finfd the right 1, it is for a challange, but ill change the code to remove any 'spoilers'

heres what i got atm…

<?php

  echo "Hello World";
  $part1 = "http://www.someadress";
  $part2 = "00.sql";
  $part3 = "_";
  $days = "01";
  $hours = "1000";
  $url = $part1, $days, $part3, $hours, $part2;
  break;
  echo $url;
  break;
  //it just echos numbers

  while($days<=30)
  {
    while($hours<=2400)
   {
      $url = $part1+$days+"_"+$hours+$part2;

      $fp = @fopen($url, "r");
      if ($fp) 
      {
         echo($url);
         break;
         echo($fp);
         break;
      }
     $hours = $hours + 100;
   }
  $days++;
  $hours=1000;
}

?>```


whats wrong?

ghost's Avatar
0 0

K3174N 420 wrote: markupcode whats wrong?

  1. Don't use break unless you're breaking out of a switch case or something… no need to use it in normal coding.
  2. Use periods to concatenate strings, not commas. ($url = $part1, $days, $part3, $hours, $part2;)
  3. You can't fopen a URL… you'll have to use cURL to access URLs.

Other than those… your code looks fine.


K3174N 420's Avatar
Satan > God
0 0

seems to be half working now…

if i comment out the fopen() it will list every url i want checked… great…

but if i addd in that fopen(), the pages just loads n loads n loads all to no avail…


K3174N 420's Avatar
Satan > God
0 0

  echo "Hello World";


  $part1 = "***********************";
  $part2 = "*****************";
  $part3 = "*********";
  $days = "**";
  $part4 = "*";
  $hours = "****";
  $part5 = ".****";
  $url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
  echo $url . "<br />";


  while($days<=30)
  {
    while($hours<=2400)
   {
        $url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;

      ***$fp = fopen($url, "r");
      if ($fp) 
      {
         echo($url . "this one" . "<br />");
         echo($fp);
      }***
      
     $hours = $hours + 100;
   }
  $days++;
  $hours=1000;
}


?>```

ghost's Avatar
0 0

Re-read my post.


K3174N 420's Avatar
Satan > God
0 0

relooks hits self in face

great…. so now to ad to my newely aquired php knoledge, i gotta squeeze in sume curl, i hope w3 schools covers it ^^


spyware's Avatar
Banned
0 0

K3174N 420 wrote: relooks hits self in face

great…. so now to ad to my newely aquired php knoledge, i gotta squeeze in sume curl, i hope w3 schools covers it ^^

It doesn't. Suck it up, hit yours31f in the face one more time and go download cURL. Google cURL tutorials for help.


K3174N 420's Avatar
Satan > God
0 0

npe, spy is right, it doesnt, im quite surprised with all the shit they got, ah well, google it is, my good old friend google who i secretly hate ;)


ghost's Avatar
0 0

A lot of the old threads here address cURL issues… so, once you find a nice, cozy learning spot for cURL (via your favorite search engine), use those as reference for parameters that you'll need. Just hop on over to that Search link and type in "curl".


K3174N 420's Avatar
Satan > God
0 0

wait… this may be a very noobu question, but do i actually need to install this thing localy if im happy enuff doing all my tests from my website?

and even if i did install it localy, how would this affect my website using it?

im a lil stuck as to what to do next :(


ghost's Avatar
0 0

If you're using a web host, you don't need to install the extension. If you're running a web server locally (using Apache, lighttpd, or any of the other web server packages), then you'll need to install / enable the cURL extension in your php.ini. Most webhosts have this done by default, so no worries if you have one.


K3174N 420's Avatar
Satan > God
0 0

well on my site i can get html and php working, but i put in a tiny copy n paste snippet of basic curl code, and nothing worked >.>


ghost's Avatar
0 0

First, ensure that you're actually doing something with the returned data from the cURL script… cURL doesn't generate any output by default. For instance, grab the cURL response and echo it or save it to a file or something.

If you're doing that, check your web host's documentation or FAQs to ensure that the cURL extension is enabled; they should have this documented somewhere.


K3174N 420's Avatar
Satan > God
0 0

ok, i seem to have curl acctive….

http://keiran420.ueuo.com/

<?php

$ch = curl_init();
echo $ch;
curl_close ($ch);
?>```

displays >> Resource id #2

I HAVE LIFE!

ghost's Avatar
0 0

Good. After you fill out your cURL parameters and execute the cURL request, you'll be able to manipulate the response. Happy hunting. :)


K3174N 420's Avatar
Satan > God
0 0

thanks guys, more of an update than anything, but so far my code is

<?php
  $curl_handle=curl_init();
  echo "Hello World";


  $part1 = "http://www.hellboundhackers.org/";
  $part2 = "challenges/real2/";
  $part3 = "backup_2004-09-";
  $days = "01";
  $part4 = "_";
  $hours = "1000";
  $part5 = ".sql";
  $url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
  echo $url . "<br />";


  while($days<=30)
  {
    while($hours<=2400)
   {
        $url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;


curl_setopt($curl_handle, $url);
curl_exec($curl_handle);
  echo $curl_handle . "<br />";
  echo $url . "<br />";

      
     $hours = $hours + 100;
   }
  $days++;
  $hours=1000;
}
curl_close($curl_handle);

?>```

and this displays
```markuptest Hello Worldhttp://www.hellboundhackers.org/challenges/real2/backup_2004-09-01_1000.sql
Resource id #2

so, getting there, i just need to undurstand wth these curl commands do….


GTADarkDude's Avatar
Member
0 0

<?php $curl_handle=curl_init(); // (…) curl_setopt($curl_handle, $url); curl_exec($curl_handle); // (…) curl_close($curl_handle);

?>``` How about something like this: (only a small part of the code)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?&gt;```
Assuming you are using this code to solve a HBH challenge, you probably need to send your cookies, so the server recognises you as a member who&#39;s logged in. You can do this by adding the following line:
```markupcurl_setopt($ch, CURLOPT_COOKIE,&quot;PHPSESSID=***; fusion_user=***&quot;);```
Good luck! ;)

PS. I&#39;d do some more research on cURL if I were you. PHP.net does cover cURL: http://nl.php.net/manual/en/book.curl.php