How do I create a .php file?

kyrctyn

New Member
Messages
14
Reaction score
0
Points
0
I need to create a .php file to redirect a file of mine, but im a newbie to programming. Can someone help me with this? Thanks in advance ^^
 

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
The meta refresh method is not recommended for SEO.

The best methods use server-processed headers.

The following also informs the user-agent that the page has moved permanently.

PHP:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>

This method retains the majority of the page rank value your previous page had.

Hope it helps.
 

johncruz

Banned
Messages
10
Reaction score
0
Points
0
You can create .php file by using this code.


$ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle);
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
You can create .php file by using this code.


$ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle);

That not only has nothing to do with the question, it's bad PHP (die() is a bad habit) and an incomplete page to boot.
 

wwinter

Member
Messages
66
Reaction score
3
Points
8
Is there any way to include google analytics code into the page and has the browser parse it to recognize the codes? I doubt so, since it will be re-directed. Correct me.
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Not if you want an immediate redirect, no. (GA often takes many seconds to respond with a 200 OK.) You can do local PHP-based logging, though, to capture much of that data; and GA on the target page should give you relevant referer (original page request) info.
 

wwinter

Member
Messages
66
Reaction score
3
Points
8
Not if you want an immediate redirect, no. (GA often takes many seconds to respond with a 200 OK.) You can do local PHP-based logging, though, to capture much of that data; and GA on the target page should give you relevant referer (original page request) info.

Not if the target page is an affiliate page which you've no cpanel control. I do not understand what is local PHP-based logging. Can you elaborate?

I was thinking of using an intermediate page which contains GA and that page re-directs to the target page.

So, Start Page ---> GA (intermediate page) ---> Target Page

But do not know how to achieve it. Can help me?
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Doing local logging would involve looking at the $_SERVER variable values (HTTP_USER_AGENT, HTTP_REFERER, REMOTE_ADDR, etc.) and writing them to a database for later analysis.

Doing an intermediate page would mean either using the HTTP REFRESH header with a fixed delay that is long enough to make sure that GA has had time to run (so people could end up staring at your "you are about to be redirected" page for 30 seconds or a minute), or doing the redirect using JavaScript that wraps the Google Analytics code and waits for the return (or monitors the DOM for the change). Both are bad ideas; the server-side solution above is the only practical solution. There is a lot of logging code available on the net; I'm not going to write your application for you.
 

smartblogger

New Member
Messages
16
Reaction score
0
Points
0
Open a simple text editor. It is best to use something like Notepad or Wordpad. Microsoft Word and other higher level word processors add a lot of extra formatting that can get in the way of writing or saving code-oriented files.


Enter your PHP code. Remember, for the code to be read properly you must have "<?php" (no quotes) at the top of the document, and "?>" (no quotes) at the end. For example:

<?PHP
$GetFile = @fopen("/tmp/filetoread.txt","r");
?>


Save the file. Use the "Save As..." feature to save the file to your desktop as a .txt file.

Navigate to the file you just created.

Right-click the file and rename it. Change the extension from ".txt" to ".php". You have created a PHP file.
 

wwinter

Member
Messages
66
Reaction score
3
Points
8
Great info. Didn't know so much to learn about php. Indeed a great coding language for server-side.
 
Top