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
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);

 

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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