Jump to content

pull string from URL


Imaulle

Recommended Posts

Hello!

 

I'm trying to make a php script to help streamline a ton of website setups that I need to do. What I want for this function is to pull the 'username' from the url. The url will always look something like this:

 

http://75.0.0.0/~username/folder/setup.php

 

what is the easiest way to get just 'username' so that I can put it into a variable ?

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/193190-pull-string-from-url/
Share on other sites

crap, okay new problem! lol this should be really easy but I'm only really good at c++

 

line 9, the $DB_NAME isn't getting printed to the file. How do I get it to print the variable name and not try to print the contents? putting it in single and double quotes didn't work  :wtf:

 

$getURL = explode("/",$_SERVER['PHP_SELF']);
$username = substr($getURL[1], 1);

$addInfo="<?php
define ('DB_USER', '".$username."_stuff');
define ('DB_PASSWORD', 'pass');
define ('DB_HOST', 'localhost');
define ('DB_NAME', '".$username."_stuff');
'$DB_NAME' = '".$username."_stuff';";

$dbinfoFile = "dbinfo.php";
$contents = file_get_contents($dbinfoFile);
$contents = $addInfo.$contents;
$fp = fopen($dbinfoFile,"w");
fwrite($fp,$contents);
fclose($fp);

 

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.