Jump to content

mkosmosports

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Everything posted by mkosmosports

  1. :-\ Dang, Im embarrassed. Of course I can. Thanks pocobueno and thorpe. I think I had a brain freeze there or something. Is this the most server-resources friendly way of combining the two?
  2. Hi everyone, I must of missed something when I first started learning php, as I was sure I can display html in a .php file outside of the php tags. I dont seem to be able to though! I guess my other two options are echoing out the html from the .php file or setting up apache to parse html files for php as well and making the files .html. What seems like the most server-friendly option? Any advice is welcome. Thanks. mkosmosports
  3. Hey blueman, In this case it is intentional yes. The uri variable holds the part of the url after the domain, so the path/directory to the page name (including that page name as well). This is actually pretty confusing on my part as the uri IS the full url, but in this case the above is what this variable does. mkosmosports
  4. Yes that would certainly be causing problems blueman. Thanks. Ive got some more changes coming, and I believe I can now successfully send the post request (Thanks to that Zend article!), but Im still failing to redirect to that page at the same time just as a form post script would. (I know how to do it with cURL but I want to know and understand this way as well) So, this is test.php... //Sending the deal URL through a POST to test1.php function post_it($datastream, $url) { //Replace 'http://' with the empty string //Get the Host address substring //Get the URI of the desired Resource $_url = preg_replace("@^http://@i", "", $url); $host = substr($_url, 0, strpos($_url, "/")); $uri = strstr($_url, "/"); //Initialize the $reqbody variable //Traverse the $DataStream array //If $reqbody is not empty, append a ampersand sign '&' //Append the variable/value pair to the end of $reqbody $reqbody = ""; foreach($datastream as $key=>$val) { if (!empty($reqbody)) $reqbody.= "&"; $reqbody.= $key."=".urlencode($val); } //Construct the POST request to send to the desired server. $contentlength = strlen($reqbody); $reqheader = "POST $uri HTTP/1.0\r\n". "Host: $host\n". "User-Agent: PostIt\r\n". "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: $contentlength\r\n\r\n". "$reqbody\r\n"; //Connect to the server using fsockopen() //If there was a connect failure, return in error //Send the POST request to the server $socket = fsockopen($host, 80, $errno, $errstr); if (!$socket) { $result["errno"] = $errno; $result["errstr"] = $errstr; return $result; } fputs($socket, $reqheader); fclose($socket); return $result; } //Now to send the below array, using the post_it function above $_data["d1"] = "I want to send this data over"; $result = post_it($_data, "http://localhost/test1.php"); This seems to workNow how do I get it to redirect to "http://localhost/test1.php" like a normal form post request would do?? Thanks for any suggestions!
  5. Hey chronister, I dont want to use sessions as it will complicate things for me, considering my script, plus then I become dependent on cookies, which I dont want to be. I dont want to pass it in the URL as a GET because I dont want this data to be seen by users. Ive got the solution though, to use cURL, which is luckily available on my hosts server, but I think its available on most. <? $myURL="http://www.remoteSite.com/login.php"; $chttp = curl_init(); curl_setopt($chttp, CURLOPT_URL,"$myURL"); //URL to post the data to curl_setopt($chttp, CURLOPT_POST, 1); curl_setopt($chttp, CURLOPT_POSTFIELDS, "key1=value1&key2=value2"); //POST names (key1, key2) and their respective values curl_exec ($chttp); curl_close ($chttp); ?> Ive also found a way to do this without cURL, as seen in this link: http://www.zend.com/zend/spotlight/mimocsumissions.php Although I cant seem to get this one working.. mkosmosports
  6. Hey, page.php contains some $_POST array data that I want automatically passed on to page1.php, without the use of a form. So.......... On page.php I formed a post request in a variable like so: $host = "localhost"; $uri = "page1.php"; $data = $_POST['data1']; $contentlength = strlen($data); $reqheader = "POST $uri HTTP/1.1\r\n". "Host: $host\n". "User-Agent: PostIt\r\n". "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: $contentlength\r\n\r\n". "$data\r\n"; Now what do I do with this? I tried opening page1.php and writing the post request to it: $handle = fopen($url, "r"); fwrite($handle, $reqheader); But now what? At this point I want to go to page1.php and see the posted data there, just as I would with a form with an action of "page1.php". Any help is much appreciated! Thanks.
  7. Hey. Take for example this url: http://weblogtoolscollection.com/regex/regex.php I want to get "weblogtoolscollection.com" out. Im very unfamiliar with regex, but it seems like its the only option. Anyone want to help me out? Thanks
  8. Hey, Im looking for the best way to validate urls. I see a lot of different ways on the net, mainly using regex, or file, fopen, fsockopen functions. Both of these methods seem fine to me. Are there any disadvantages to them and what do you guys/gals prefer? Thanks.
  9. Hey, I think I explained myself very poorly Jesirose. Here my specific problem: Im trying to show soccer transfers on a per month basis. In the URL theres a year parameter, from which I retrieve all of the transfers for that given year from the db and put it into an md array divided by month. I then use AJAX, so when users choose different months, the page doesnt reload, it just the takes the transfers of the appropriate month from the md array. Ive been using sessions for this array to be accessible for this. But Im wondering if there any alternatives to this? I know I can run queries on a per month basis instead, or maybe even put the yearly transfers in a file, but what about some kind of globally accessible array which would be created on the fly on the server?
  10. Hey, I want to store an array on the server for use across multiple pages. I know and have been using sessions, but it just kills me to know that if the user turns cookies off, this is all gonna stop working unless I want that big session id in all urls. Also, the info in this array is by no means specific to each user, its the same for all of them. Is there any alternatives to this? Some way of storing an array which would be accessible by multiple pages? Thanks.
  11. Hey, On the topic of echoing HTML vs. completely separating html from php, is there any advantages to doing one over the other? For example: Is <?php echo("<div>Hello my name is $name</div>"); ?> better than <div>Hello my name is <?php echo($name); ?></div>? I always tend to use the first option but really only because I got into the habit of doing it. What do you guys use and why?
  12. You could use the file_put_contents function, so for example: $filename = "xxxx/123.php"; $filecontent = "Contents of file"; $createfile = file_put_contents($filename,$filecontents) or die("Cannot create file");
  13. Because that information is not specific to the user, its vital site data, and I dont want to get into the disadvantages of sessions, like for example when cookies are disabled.
  14. Hey, I have a situation where I need information from certain arrays to be available by multiple different pages. Up to now, I had passed put those arrays in sessions, which I dont think is a good idea. What can I do? What about globalizing the arrays? Will that work? Any suggestions welcome. Thanks.
  15. Hey, Now I know there are a lot of pages dedicated to this but I cant seem to find any concrete answers. I use sessions on my site. The information in some of these session arrays is vital for the site to work. I just recently found out if cookies are disabled that big ugly PHPSESSID url parameter gets inserted into all links, which is not only ugly but poses security risks because the session id can be viewed by everyone. A lot of people are advising to disable this altogether in php.ini, which I dont understand though, because how else can you use sessions if the users cookies are disabled?? So, I need to make sessions are accesible even if the user has cookies disabled, but I want to make sure that doesnt pose any security risks, and if possible I would like to clean up that url a little? Does anyone have any suggestions? Is this doable? Anything is appreciated. Thanks
  16. Thanks chigley. I was considering the echo, which is probably what I will end up doing. The server is shared so I cant modify php.ini, do you think its worth it to try to disable short tags in htaccess?
  17. .= will concatenate (join) the already existing string with whatever you specify it to equal...very useful... So for example, $text = "hello"; $text .= " ,my name is"; echo($text), will now be hello ,my name is...
  18. Hey, Ive just got on my newly acquired hosting account and am starting to discover and modify things. One thing I did is modify .htaccess to allow me to parse for php code inside html files. However, now, the xml declaration is being read as php: <?xml version="1.0" encoding="UTF-8"?> and returns a php error... How can I get around this? Thanks
  19. Hey, I have finished creating a solid medium-level security user login/validation script except it relies on cookies, and after reading up a little, I dont want to rely solely on them. So, Ive thought of the following idea of a login/validation without using cookies... When user logs in: 1. Username and password (hashed) fields are checked in a select query for their match. 2. If existent, the username is hashed and entered in another column called "loggedin_token" (or something like that) 3. A session variable saying user is logged in and containing loggedin_token is set. Now to validate: 1. Query selecting the username where loggedin_token in session variable is the same as loggedin_token in mysql row. 2. If query has a resulting row, user is valid, if not theyre not. The logged_in token will always be unique because the username is unique. Does this make sense? Thanks for your time..
  20. Right, if you destroy the session yes. But I never destoy it, I continually unset it, but I just want to know when it would change, or if it would ever unless destroyed of course. Strange, after restarting the browser it seems to reset everytime, although I swear last night this was not the case.... Another funny thing I just noticed. In Firefox, if you open new browser windows, it uses the initial session_id until you close all instances. However in IE 7, every new instance produces a different session_id...
  21. Maybe I should rephrase that to be a little more specific... Under what circumstance would the session_id() function return a different id? If the user closes the browser? Thanks.
  22. Hey, When do session id's change? Thanks.
  23. Unless someone thinks this wont work under a certain scenario. I think Ive figured it out (tested all scenarios I think) So, for any of you wanting to use regex (with preg_match function) to validate sign-in fields from: -being less than or more than a specific number of characters (below Im using 4-20) -containing any special characters (including blank spaces) except for hyphens or underscores. -if first validation level is ok, containing a list of banned words (against SQL injection, I should of put more banned words in there, but there must be a fine line of what the user CAN actually write) if (preg_match("/^[a-zA-Z0-9-_]{4,20}$/",$field)) { if (preg_match("/\bdelete\b|\binsert\b|\bdrop\b|\bselect\b/i",$field)) { echo("NO!"); } else echo("YES!"); } else { echo("NO!"); Of course the echo NO's or YES's would have to be replaced by the action you would want the script to take based on the result. mkosmosports
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.