adding https to an old site submission form?

Hi everyone / anyone, it’s been many years since i plucked around in PHP scripts so i am a bit out of the loop and could use some help.

I have an old directory script, the developers website no longer exists hence i can’t ask them anymore.

The script parses an URL form input, i believe with this string/s
[php]function ParseURL($url) {
$url = trim($url);

  //if (strpos($url, '.')<1) { return false;  }
  
  // check if empty 
  $len = strlen($url);
  if ($len<3) { return false;  }
  
  if (strcmp("http://", substr($url, 0, 7)) !== 0) {
      $url = "http://" . $url;
  }

  $url_stuff = parse_url($url);
  if (!isset($url_stuff["path"])) {  $url = $url . "/";  }

  return $url;
}[/php]

This is inside a PHP file folder called “php4_classes” and once more in a folder called “php5_classes”.

I believe i can just add the https://
somewhere within here
[php]if (strcmp(“http://”, substr($url, 0, 7)) !== 0) {
$url = “http://” . $url;
}[/php]
BUT HOW CORRECTLY??

In addition, with the same file, i find the http:// mentioned once more within a
function GetHTML"
as
[php] if (strpos($nueva,“http://”)=== FALSE) {
$nueva = “http://” . $urlc . $nueva;
}
[/php]and a bit further down in
“function GetAllHTML”
i find
[php]$header = "GET " . $url_stuff[‘path’] . “?” . $url_stuff[‘query’] ;
$header = $header . " HTTP/1.1\r\nHost: " . $url_stuff[‘host’] . “\r\n\r\n”; "
[/php]
The last one i probably do not need to change or add anything in terms of being able to also add https websites to the directory, but the second one above may need the same add-in of a https recognition??
Hope someone knows how this probably simple solution??

I would suggest a rewrite, if the original was meant for php4; that is so far out of date, it is worth complete abandon.

What would you like it to do?

Yes, i am aware that PHP is already at v. 7 by now :o

The problem is that i and the owner of the directory are also kind of version 4 :stuck_out_tongue:
(i mean older fellows) …

In my point of view that whole directory is outdated, but with all the work and time invested in it over the past 15 or more years and you are going on 80 and you are most likely not able to use the database of that particular script anywhere else the problem is that it is even less worth it to put in all the work for something completely new, so, the fix is the better of the options.

What it does you asked?
The classical website submission form input handling. Add and URL, description, keywords etc.
At present (as you can see at above script pieces) it can only accept URL’s that start with http://
Even manually added inside the directory scripts admin section, it will not accept the https, or i should correct, at present it does this: http:// (as this is automatically added when entering an URL) and than the https:// (in other words the URL now starts with http://https:// - completely senseless of course.
But now that i wrote this maybe, instead of trying to add a function that would accept http or https i should probably better REMOVE the auto-added http:// and thus the problem would be solved as well, right??

But again, how exactly would i do that without causing a confusion (errors) in PHP using the above mentioned script pieces??

Don’t know if it will work in php4 however

[php]<?php

$r = array(
example.com’,
http://example.com’,
http://www.example.com’,
https://example.com’,
https://www.example.com
);

foreach($r as $url){
//echo substr($url, 0, 7) . “\n”;
if (strrpos($url, “http”) !== 0) {
$new_url = “http://” . $url;
echo “Changed $url to $new_url\n”;
} else
echo “No change to $url\n”;
}[/php]

will run correctly on 4.4.9

Sponsor our Newsletter | Privacy Policy | Terms of Service