Which works... however I get the "Warning: Cannot modify headers..." error because I am echoing $referrer. Now before you say - take out the echo - I have tried. The script simply does not work if I take out the echo.
Which works... however I get the "Warning: Cannot modify headers..." error because I am echoing $referrer. Now before you say - take out the echo - I have tried. The script simply does not work if I take out the echo.
Any suggestions please?
Thanks
It means that you have already sent headers to the user's browser when you echo'ed the http referrer. You cannot use any output before sending a specific PHP header unless you buffer your output (which is more advanced than what you need to know at this stage).
Basically, just remove the echo statement and it should work fine. Have you checked your preg statement?
Thanks for the comments, I understood about 10% of what you said. It didn't work. For some reason removing the echo ends the script without redirecting and I get a browser error.
I tried both permutations of what you posted, with and without the echo.
I understand that I can't echo before sending headers... so what is the work around?
Thanks for the comments, I understood about 10% of what you said. It didn't work. For some reason removing the echo ends the script without redirecting and I get a browser error.
I tried both permutations of what you posted, with and without the echo.
I understand that I can't echo before sending headers... so what is the work around?
Whoops! Yeah, I forgot to delete the echo. Also, when I wrote my reply the forum here parsed your URL's as links and put in some [url] tags that are not doing you any favors. Lastly, I'll warn you that I am garbage with regex statements but I think any remaining problem is probably right there.
I think that there needs to be a carat "^" in there like so, and without the [url] tags:
Try that. If removing the [url][/url] tags from the code I first pasted doesn't work either then read on...
--------------
Anyway, like I said, I am garbage at making regex patterns. Try removing the "@" symbol in front of the preg_match and see if we are generating any errors. If so, paste them verbatim in a reply here.
Also, try running this code once and see what prints to screen:
Big whoops - we must have posted at the same time Rowsdower - trying that now!
Thanks folks.
Neither option is working.
Perhaps Im going about this the wrong way. Essentially I am trying to restrict access to a page - lets call it the "member special page" - to a certain link.
Here's what happens. As a member of "blankds" I login and then get access to a link which takes me to "blackisgreen". If I have logged into "blankds" and clicked the link I am allowed to see "member special page" on "blackisgreen".
If I have not come from the link on blankds I am redirected to the standard page on blackisgreen.
Essentially the if / else statement should work, but without echoing the $referrer value it simply doesn't. I have even tried .htaccess to turn on output buffering, tried php.ini files etc. those dont work to get rid of the header warning either.
Any suggestions of a better way to accomplish what I need are welcome.
Option 1: no error message - but redirects me to page_2.
Option 2: prints out Array() - but also stays on page_1 no matter where I redirect from.
Option 3: remove @ =
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
If you're getting a never-ending loop then this redirect script must be referring to itself or to another page with the redirect script, which then redirects to another page with the redirect script, etc.
Now when you printed out "Array()" (which is the retult of a blank array being printed with print_r) and didn't redirect that is the anticipated behavior. What this is telling us is that the preg_match is not finding a match - which means you have a problem with your regex (regular expression). If it had found a match, there would have been something in the array.
To make matters simple, just switch the preg_match() search to a strpos() search - you can find this function on php.net. It's simpler to use but less powerful. For your purposes here, however, it will be just fine.
The second redirect was redirecting to the same page that had the code - ie. endless loop. Remove it, place the "special" content on the page with that at the top of the code and we have a working model.